Results 1 to 10 of 10

Thread: If condition...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    If condition...

    Dear Friends,

    How can I modify the following code as it is not working: The command button name is: cmdANS

    VB Code:
    1. Public Sub Timer7_Mod()
    2.  
    3. If cmdANS_Click Then
    4. Timer7.Enabled = True
    5. Timer7.Interval = 200
    6. Call cmdNext_Click
    7. Timer7.Enabled = False
    8. End if
    9.  
    10. End Sub

    Margaret

  2. #2
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Re: If condition...

    what is it supposed to do?

  3. #3
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: If condition...

    VB Code:
    1. If cmdANS_Click Then
    cmdANS_Click is cmdANS' Click-event.
    You can't call it as if it were a variable or function.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: If condition...

    Quote Originally Posted by robbedaya
    what is it supposed to do?
    Hi,

    When I press cmdAns button....

    Timer7.Enabled = True >>>> Timer7 should start working
    Timer7.Interval = 200 >>>> This is the time
    Call cmdNext_Click >>>>> when time finishes it should click cmdNext button automatically

    Timer7.Enabled = False >>> Lastly it should stop working.

  5. #5
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: If condition...

    Why don't you use a flag to indicate that the button was pressed. Declare a global boolean value and set it to true at the end of the procedure. Then query the boolean value to determine if it is true or not. Like this...

    VB Code:
    1. Dim bFlag       As Boolean
    2.  
    3. Private Sub CmdANS_Click()
    4.     ' Statements Here
    5.     ' Statements Here
    6.     ' Statements Here
    7.     ' Statements Here
    8.     ' Statements Here
    9.     ' Statements Here
    10.     ' Statements Here
    11.     bFlag = True
    12. End Sub
    13.  
    14. Public Sub Timer1_Mod()
    15.     If bFlag Then
    16.         Timer7.Enabled = True
    17.         Timer7.Interval = 200
    18.         Call cmdNext_Click
    19.         Timer7.Enabled = False
    20.     End If
    21. End Sub

    Hope this helps,

    Jenova

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: If condition...

    Why the following code is not working? Any help please.

    VB Code:
    1. Private Sub Timer7_Timer()
    2. Static i As Long
    3. i = i + 1
    4. If i = 500 Then
    5. Timer7.Enabled = False
    6. i = 0
    7. End If
    8. End Sub

    Margaret

  7. #7
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Re: If condition...

    what error does the code give? what doesn't work?

  8. #8
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: If condition...

    Make sure Timer is getting enabled with an interval of more than 0 from somewhere...

  9. #9
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Re: If condition...

    Quote Originally Posted by moinkhan
    Make sure Timer is getting enabled with an interval of more than 0 from somewhere...
    i tested the code, and the code works like a charm. So check the things Moinkhan said.
    timer.enabled = true
    timer.interval must be bigger than 0. (1000 = 1 second)

  10. #10
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: If condition...

    Quote Originally Posted by jeroen79
    cmdANS_Click is cmdANS' Click-event.
    You can't call it as if it were a variable or function.
    Not quite true...you can call it to fire the sub by typing "cmdANS_click" in your code...but no, you can't use it in a true/false statement or to hold a value...A better way to do that would be an option button
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

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