|
-
Sep 21st, 2005, 06:21 AM
#1
Thread Starter
Fanatic Member
i want my code to become faster
hi, how to become my code faster?
this is my code:
VB Code:
Private Sub cmdFeed_Click()
Dim ln As Integer
For ln = 1 To Len(txtMobileNumber.Text)
Select Case Mid(txtMobileNumber.Text, ln, 1)
Case "0"
thex ("1F 00 10 D1 00 06 00 01 46 00 01 0A 03 97")
pause (100)
thex ("1F 00 10 D1 00 06 00 01 47 00 01 0C 04 97")
pause (100)
Case "1"
thex ("1F 00 10 D1 00 06 00 01 46 00 01 01 03 9C")
pause (100)
thex ("1F 00 10 D1 00 06 00 01 47 00 01 0C 04 97")
pause (100)
Case "2"
thex ("1F 00 10 D1 00 06 00 01 46 00 01 02 03 9F")
pause (100)
thex ("1F 00 10 D1 00 06 00 01 47 00 01 0C 04 97")
pause (100)
Case "3"
thex ("1F 00 10 D1 00 06 00 01 46 00 01 03 03 9E")
pause (100)
thex ("1F 00 10 D1 00 06 00 01 47 00 01 0C 04 97")
pause (100)
End Select
Next ln
End Sub
-
Sep 21st, 2005, 06:24 AM
#2
Lively Member
Re: i want my code to become faster
I could be missing something... but wouldn't taking out the pauses, or reducing them make it faster??
Don't listen to me. Ever. Surveillance.
-
Sep 21st, 2005, 06:27 AM
#3
Thread Starter
Fanatic Member
Re: i want my code to become faster
Surveillance, reducing with the pause? e.g pause(50) ?
btw, the use of this code is when u input in the txtMobileNumber e.g 012 then if u press cmdFeed it will dial on ur Mobile Phone 012
thanks..
-
Sep 21st, 2005, 06:29 AM
#4
Re: i want my code to become faster
-
Sep 21st, 2005, 06:29 AM
#5
Lively Member
Re: i want my code to become faster
Yes, like pause(50) or whatever... the only thing I have to ask is, are you sure that pause isn't there for a reason? Maybe to give the phone time to do its thing. But play around with it and see where you can optimize it at.
-
Sep 21st, 2005, 06:37 AM
#6
Thread Starter
Fanatic Member
Re: i want my code to become faster
this is the module..
VB Code:
Sub pause(pas As Single)
start = Timer
Do Until Timer >= start + pas / 1000
DoEvents
Loop
End Sub
i tried the pause(50) but there is an error my phone freeze..
-
Sep 21st, 2005, 06:46 AM
#7
Lively Member
Re: i want my code to become faster
Hmm, it looks like even with it at 100 it's only pausing for a 1/10th of a second. I don't see why it should freeze, unless it needs that full 1/10th of a second between inputs. Maybe try speeding it more gradually, until you hit the sweet spot, try (90), and if it doesn't freeze, move down to (80) or so, until you can't get it faster.
-
Sep 21st, 2005, 07:10 AM
#8
Re: i want my code to become faster
VB Code:
Declare Sub Sleep Lib "kernel32" ( _
ByVal dwMilliseconds As Long _
)
Private Sub cmdFeed_Click()
Dim ln As Long
Dim lTemp As Long
Dim sChar As String
For ln = 1 To Len(txtMobileNumber.Text)
lTemp = CLng(Mid$(txtMobileNumber.Text, ln, 1))
If (lTemp = 0) Then
sChar = "0A"
Else
sChar = "0" & CStr(lTemp)
End If
thex "1F 00 10 D1 00 06 00 01 46 00 01 " & sChar & " 03 97"
Sleep 100
thex "1F 00 10 D1 00 06 00 01 47 00 01 0C 04 97"
Sleep 100
Next ln
End Sub
As has been mentioned, the slowest part is really the pause. Unless you can improve that there is not much point optimising the rest of the code since the pause is the limiting factor.
-
Sep 21st, 2005, 08:09 PM
#9
Thread Starter
Fanatic Member
Re: i want my code to become faster
penagate,
hi, i got an error from the declare it says only Constants,Fixed Length strings,arrays,user-defined types and declare statements not allowed as public members of object modules
Thanks..
-
Sep 21st, 2005, 08:45 PM
#10
Re: i want my code to become faster
Indeed, you need to either chuck that part in a standard module or make it Private
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|