Results 1 to 10 of 10

Thread: i want my code to become faster

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    i want my code to become faster

    hi, how to become my code faster?

    this is my code:

    VB Code:
    1. Private Sub cmdFeed_Click()
    2. Dim ln As Integer
    3. For ln = 1 To Len(txtMobileNumber.Text)
    4. Select Case Mid(txtMobileNumber.Text, ln, 1)
    5. Case "0"
    6. thex ("1F 00 10 D1 00 06 00 01 46 00 01 0A 03 97")
    7. pause (100)
    8. thex ("1F 00 10 D1 00 06 00 01 47 00 01 0C 04 97")
    9. pause (100)
    10. Case "1"
    11. thex ("1F 00 10 D1 00 06 00 01 46 00 01 01 03 9C")
    12. pause (100)
    13. thex ("1F 00 10 D1 00 06 00 01 47 00 01 0C 04 97")
    14. pause (100)
    15. Case "2"
    16. thex ("1F 00 10 D1 00 06 00 01 46 00 01 02 03 9F")
    17. pause (100)
    18. thex ("1F 00 10 D1 00 06 00 01 47 00 01 0C 04 97")
    19. pause (100)
    20. Case "3"
    21. thex ("1F 00 10 D1 00 06 00 01 46 00 01 03 03 9E")
    22. pause (100)
    23. thex ("1F 00 10 D1 00 06 00 01 47 00 01 0C 04 97")
    24. pause (100)
    25. End Select
    26. Next ln
    27. End Sub

  2. #2
    Lively Member
    Join Date
    Aug 2005
    Location
    Missouri
    Posts
    69

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    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..

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: i want my code to become faster

    Moved.

  5. #5
    Lively Member
    Join Date
    Aug 2005
    Location
    Missouri
    Posts
    69

    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.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    Re: i want my code to become faster

    this is the module..

    VB Code:
    1. Sub pause(pas As Single)
    2. start = Timer
    3. Do Until Timer >= start + pas / 1000
    4. DoEvents
    5. Loop
    6. End Sub

    i tried the pause(50) but there is an error my phone freeze..

  7. #7
    Lively Member
    Join Date
    Aug 2005
    Location
    Missouri
    Posts
    69

    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.

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: i want my code to become faster

    VB Code:
    1. Declare Sub Sleep Lib "kernel32" ( _
    2.     ByVal dwMilliseconds As Long _
    3. )
    4.  
    5. Private Sub cmdFeed_Click()
    6. Dim ln      As Long
    7. Dim lTemp   As Long
    8. Dim sChar   As String
    9.  
    10.     For ln = 1 To Len(txtMobileNumber.Text)
    11.         lTemp = CLng(Mid$(txtMobileNumber.Text, ln, 1))
    12.         If (lTemp = 0) Then
    13.             sChar = "0A"
    14.           Else
    15.             sChar = "0" & CStr(lTemp)
    16.         End If
    17.  
    18.         thex "1F 00 10 D1 00 06 00 01 46 00 01 " & sChar & " 03 97"
    19.         Sleep 100
    20.  
    21.         thex "1F 00 10 D1 00 06 00 01 47 00 01 0C 04 97"
    22.         Sleep 100
    23.     Next ln
    24. 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.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    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..

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width