Results 1 to 6 of 6

Thread: [RESOLVED] Name that thread

  1. #1

    Thread Starter
    Lively Member cgarlick's Avatar
    Join Date
    Apr 2007
    Location
    Virginia
    Posts
    92

    Resolved [RESOLVED] Name that thread

    Ok so I am new to programing, so let me explain what I want to code and if someone could give me a point in the right direction I can go from there.

    I want to code something like a yes/No chart..

    EX:

    If condition1=1 goto 2
    elseif condition=2 go 3
    else condition=3 go to 100

    Shuold I use a if/and/or or is there a better way to do this?

    Cheers!

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Name that thread

    First of all, I'd recommend against using GoTo in any of your code. There's almost always a better solution than using GoTo.

    2nd, you're not being specific enough. If you want to execute code based off of a certain condition, then use If/Then or Select/Case statements.

    If there's just 2 or 3 conditions then If/Then is fine, if there's more then Select/Case will be better and less time consuming. ie:
    vb Code:
    1. Private Sub Form_Load()
    2.     Dim intAge As Integer
    3.    
    4.     intAge = 50
    5.    
    6.     Select Case intAge
    7.         Case Is < 20
    8.             MsgBox "You're younger than 20"
    9.         Case Is >= 40
    10.             MsgBox "You're over the hill"
    11.         Case 42, 72, 56
    12.             MsgBox "You're either 42, 72, or 56 years old"
    13.         Case 100
    14.             MsgBox "wow"
    15.     End Select
    16. End Sub

  3. #3

    Thread Starter
    Lively Member cgarlick's Avatar
    Join Date
    Apr 2007
    Location
    Virginia
    Posts
    92

    Re: Name that thread

    Thanks for the reply, quick question though..

    Wouldn't this code end Line 9 if intAge > 40?
    Very good example of what I am looking for, just whondering if you threw it together and did not see that or if I am missing something.

    Thanks again!

    1. Private Sub Form_Load()
    2. Dim intAge As Integer
    3.
    4. intAge = 50
    5.
    6. Select Case intAge
    7. Case Is < 20
    8. MsgBox "You're younger than 20"
    9. Case Is >= 40
    10. MsgBox "You're over the hill"
    11. Case 42, 72, 56
    12. MsgBox "You're either 42, 72, or 56 years old"
    13. Case 100
    14. MsgBox "wow"
    15. End Select

  4. #4
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Name that thread

    No if it is Greater than or equal to then it will say "You're Over the hill"

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Name that thread

    Quote Originally Posted by cgarlick
    Thanks for the reply, quick question though..

    Wouldn't this code end Line 9 if intAge > 40?
    Very good example of what I am looking for, just whondering if you threw it together and did not see that or if I am missing something.

    Thanks again!

    1. Private Sub Form_Load()
    2. Dim intAge As Integer
    3.
    4. intAge = 50
    5.
    6. Select Case intAge
    7. Case Is < 20
    8. MsgBox "You're younger than 20"
    9. Case Is >= 40
    10. MsgBox "You're over the hill"
    11. Case 42, 72, 56
    12. MsgBox "You're either 42, 72, or 56 years old"
    13. Case 100
    14. MsgBox "wow"
    15. End Select
    I did just throw it together real quick.

    If intAge = 42 it will still say 'Over the hill' because Case 42, 72, 56 comes AFTER Case >= 40. So Case >= 40 will execute first.

  6. #6

    Thread Starter
    Lively Member cgarlick's Avatar
    Join Date
    Apr 2007
    Location
    Virginia
    Posts
    92

    Re: Name that thread

    Ok, I think the only reason I noticed is because I compiled it to see what it would do.

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