Results 1 to 7 of 7

Thread: timer/counter help

  1. #1

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461

    Question timer/counter help!

    ok, i need a code that will add the number 1 every time the sub is called, so it will show 1,2,3,4,5,6,7 if it has been called 7 etc times. i want it to be in a timer so i know how many times a nother code has been called; i want the number to be showed in a caption( label)
    Last edited by Cmdr0Sunburn; Jun 6th, 2001 at 04:59 PM.
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  2. #2
    Lively Member
    Join Date
    Feb 2001
    Location
    Fort Lauderdale, FL
    Posts
    98
    Can you just set a variable for each sub and create a procedure that passes gets the sub name and adds 1 to it (or just add 1 right there in each procedure) and then display that variable in the text box...

    Sub cmdStart_Click
    iCmdStartClick = iCmdStartClick+1
    ...
    ...
    end sub


    What did you want the timer to do?

  3. #3

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461

    Post

    im a newbie at vb i dont know much
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  4. #4
    Matthew Gates
    Guest
    Somethin' like...


    VB Code:
    1. Static i As Integer
    2.  
    3. Private Sub MySub()
    4.     Timer1.Enabled = True
    5.     'rest of code
    6. End Sub
    7.  
    8. Private Sub Command1_Click()
    9.     Call MySub
    10. End Sub
    11.  
    12. Private Sub Command2_Click()
    13.    Msgbox "Times sub has been run:  " & i
    14. End Sub
    15.  
    16. Private Sub Timer1_Timer()
    17.     i = i + 1
    18.     Timer1.Enabled = False
    19. End Sub


    ..Although, you could do this without a Timer.

  5. #5
    Megatron
    Guest
    2 ways: USe a Static variable, or declare it at module level

    Example 1:
    VB Code:
    1. Sub MySub
    2.     Static i As Integer
    3.     i = i + 1
    4.     Label1 = i
    5. End Sub

    Example 2:
    VB Code:
    1. Private i As Integer   'In General section
    2.  
    3. Sub MySub
    4.    i = i + 1
    5.    Label1 = i
    6. End Sub

  6. #6
    Lively Member
    Join Date
    Feb 2001
    Location
    Fort Lauderdale, FL
    Posts
    98
    oh, sorry! you want it to show all the numbers.
    OK, how about this...

    Dim sTimes as string
    dim iNum as integer

    Sub cmdStart_Click
    setNum(getNum+1)
    sCmdStartClick = sCmdStartClick & getNum & ","
    ...
    ...
    end sub

    Sub SetNum(iInt as integer)
    iNum = iInt
    end sub

    Function getNum
    getNum = iNum
    end Function

  7. #7

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461
    i got it thx
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

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