Page 1 of 1

ขึ้นโค้ด Error Argument not optinal ต้องแก้อย่างไรครับ ขอบคุณครับ

Posted: Mon Sep 18, 2017 8:56 am
by nisit2559

Code: Select all

Private Declare PtrSafe Function timeGetTime Lib "winmm.dll" (ByVal hKey As LongPtr, ByVal lpSubKey As String, phkResult As LongPtr) As Long
Public lngStartTime As Long   'time in msec

Public Sub StartTimer()
    lngStartTime = timeGetTime()
End Sub

Public Function EndTimer() As Double
    EndTimer = timeGetTime() - lngStartTime
End Function
Public Sub delay(msdelay As Long)
   ' creates delay in ms
   Dim temp As Double
   StartTimer
   Do Until EndTimer > (msdelay)
   Loop
End Sub

Re: ขึ้นโค้ด Error Argument not optinal ต้องแก้อย่างไรครับ ขอบคุณครับ

Posted: Mon Sep 18, 2017 6:05 pm
by snasui
:D ฟังก์ชั่น timeGetTime มี 3 Arguments คือ hKey, lpSubKey และ phkResult หากจะเรียกใช้ต้องส่งตัวแปรไปด้วย 3 ตัวจึงจะทำงานได้ ยกเว้นจะกำหนดตัว Arguments ทั้งหมดเป็น Optional

Function EndTimer ที่เขียนมา มีการเรียกใช้ timeGetTime() แต่ไม่ได้ส่ง Arguments ไปด้วย (Arguments อยู่ภายในวงเล็บ) โปรแกรมจึงฟ้องดังที่เห็นครับ