|
-
May 1st, 2007, 07:46 PM
#1
Thread Starter
Lively Member
[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!
-
May 1st, 2007, 09:31 PM
#2
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:
Private Sub Form_Load()
Dim intAge As Integer
intAge = 50
Select Case intAge
Case Is < 20
MsgBox "You're younger than 20"
Case Is >= 40
MsgBox "You're over the hill"
Case 42, 72, 56
MsgBox "You're either 42, 72, or 56 years old"
Case 100
MsgBox "wow"
End Select
End Sub
-
May 2nd, 2007, 12:50 AM
#3
Thread Starter
Lively Member
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
-
May 2nd, 2007, 01:05 AM
#4
Re: Name that thread
No if it is Greater than or equal to then it will say "You're Over the hill"
-
May 2nd, 2007, 01:43 AM
#5
Re: Name that thread
 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.
-
May 2nd, 2007, 06:26 AM
#6
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|