|
-
Jul 12th, 2000, 04:37 PM
#1
Thread Starter
Lively Member
Hi,
How can I get this working!?
I have three integers. I want the highest one to appear in textbox1 when the user clicks command1. I keep getting a 'If missing' error. I'm sure I don't have to use the If statement? Is there some way of looping? I'd appreciate if you could show me what's wrong with my code.
Thanks!
'Three labels, a command button and textbox
Dim rfirst As Integer
Dim rsecond As Integer
Dim rthird As Integer
Private Sub Form_Load()
Randomize
rfirst = Int(Rnd * 20)
Label1.Caption = rfirst
rsecond = Int(Rnd * 20)
Label2.Caption = rsecond
rthird = Int(Rnd * 20)
Label3.Caption = rthird
End Sub
Private Sub Command1_Click()
If rfirst > rsecond Then
If rfirst > rthird Then
Text1 = rfirst
End If
If rsecond > rfirst Then
If rsecond > rthird Then
Text1 = rsecond
End If
If rthird > rfirst Then
If rthird > rsecond Then
Text1 = rthird
End If
End Sub
-
Jul 12th, 2000, 04:45 PM
#2
You were missing some End If's, but it should work now.
Code:
Private Sub Command1_Click()
If rfirst > rsecond Then
If rfirst > rthird Then
Text1 = rfirst
End If
End If
If rsecond > rfirst Then
If rsecond > rthird Then
Text1 = rsecond
End If
End If
If rthird > rfirst Then
If rthird > rsecond Then
Text1 = rthird
End If
End If
End Sub
-
Jul 12th, 2000, 04:46 PM
#3
Hyperactive Member
Your problem is you open two if statements for each check, and only close one.
Code:
Dim rfirst As Integer
Dim rsecond As Integer
Dim rthird As Integer
Private Sub Form_Load()
Randomize
rfirst = Int(Rnd * 20)
Label1.Caption = rfirst
rsecond = Int(Rnd * 20)
Label2.Caption = rsecond
rthird = Int(Rnd * 20)
Label3.Caption = rthird
End Sub
Private Sub Command1_Click()
If rfirst > rsecond And rfirst > rthird Then
Text1 = rfirst
End If
If rsecond > rfirst And rsecond > rthird Then
Text1 = rsecond
End If
If rthird > rfirst And rthird > rsecond Then
Text1 = rthird
End If
End Sub
-
Jul 12th, 2000, 04:48 PM
#4
Hyperactive Member
Here ya go:
Code:
Private Sub Command1_Click()
If rfirst > rsecond Then
If rfirst > rthird Then
Text1 = rfirst
End Ff
End If
If rsecond > rfirst Then
If rsecond > rthird Then
Text1 = rsecond
End If
End If
If rthird > rfirst Then
If rthird > rsecond Then
Text1 = rthird
End If
End If
End Sub
That should do it, but I haven't had a chance to try it out yet. You were missing three End If statements there.
Let me know if you have any problems
-
Jul 12th, 2000, 04:49 PM
#5
Originally posted by christophe
Code:
Private Sub Command1_Click()
If rfirst > rsecond Then
If rfirst > rthird Then
Text1 = rfirst
End If
If rsecond > rfirst Then
If rsecond > rthird Then
Text1 = rsecond
End If
If rthird > rfirst Then
If rthird > rsecond Then
Text1 = rthird
End If
End Sub
Total lack of End Ifs there try,
Code:
Private Sub Command1_Click()
if rfirst > rsecond Then
If rfirst > rthird Then
Text1 = rfirst
Exit Sub
End If
End If
'
if rsecond > rfirst Then
If rsecond > rthird Then
Text1 = rsecond
Exit Sub
End If
End If
'
If rthird > rfirst Then
if rthird > rsecond then Text1 = rthird
Endif
Now l hope you don't intend to keep the default names like Text1 and Command1, re-name them to something more meaningful.
P.S Sorry had to modify the code, the Exit Sub statements should of course only be executed if the condition is true.
Hope this helps,
John, this is not really a helpful posting....honest
[Edited by Jethro on 07-12-2000 at 06:27 PM]
-
Jul 12th, 2000, 04:50 PM
#6
Hyperactive Member
DANG! I almost managed to answer one
-
Jul 12th, 2000, 05:04 PM
#7
You were missing some End If's, but it should work now.
Code:
Private Sub Command1_Click()
If rfirst > rsecond Then
If rfirst > rthird Then
Text1 = rfirst
End If
End If
If rsecond > rfirst Then
If rsecond > rthird Then
Text1 = rsecond
End If
End If
If rthird > rfirst Then
If rthird > rsecond Then
Text1 = rthird
End If
End If
End Sub
-
Jul 12th, 2000, 05:30 PM
#8
Zap l don't believe it you got me again with that Click thing
Please no one else click on Zaps thread....it will destroy your day......aaaarrrrrrrgggggghhhhhhhhhh!!!!!!!!
-
Jul 12th, 2000, 05:38 PM
#9
Hyperactive Member
An outside the box route:
Code:
Private Sub Form_Load()
Dim res As Integer
res = Rnd * 20
' init "highest" random value
Label1.Tag = res
' first random value
Label1.Caption = res
res = Rnd * 20
' second random value
Label2.Caption = res
If res > Label1.Tag Then Label1.Tag = res
res = Rnd * 20
' third random value
Label3.Caption = res
' tag holds highest value of three random
If res > Label1.Tag Then Label1.Tag = res
End Sub
Private Sub Command1_Click()
Text1 = Label1.Tag
End Sub
Try to use as few resources and CPU cycles as necessary. 
[Edited by Mongo on 07-12-2000 at 06:53 PM]
-
Jul 12th, 2000, 09:06 PM
#10
Damn you Mongo
And there l was thinking l had the best solution including the Exit Sub additions.
Actually l was waiting on some one to figure out the Select Case solution.
oh well
Code:
Select Case rfirst
Case > rsecond and > rthird: Text1 = rfirst
Case < rsecond and rsecond > rthird : Text1 = rsecond
Case < rthird and rthird > rsecond : Test1 = rthird
End Select
Ok tested it out with Universe and it works, don't have vb on this PC so don't know if this will work, actually will dick around with it tonite and have a look.
-
Jul 12th, 2000, 09:52 PM
#11
Hyperactive Member
Re: Damn you Mongo
*ROTFLMAO* I'll wear that red badge of courage proudly, Jethro! Maybe I had too many days with the 101st... you know, do more with less, night stalking, etc... (I assume there's some truth to your combat programming, ergo the milspeak). Condor 06, scouts out. Out Front! 
[Edited by Mongo on 07-12-2000 at 10:55 PM]
-
Jul 13th, 2000, 12:24 AM
#12
Hyperactive Member
Jethro:
hehe...
I don't really see the problem, all I did was say click here.
I don't see a problem with saying click here, it's just like saying don't click here or click here or you'll regret it
because it's your choice whether or not you want to click here, or maybe over here or even right here. It's not my fault if you click here.
In conclusion CLICK HERE!!!!!!!!!!
-
Jul 13th, 2000, 04:42 AM
#13
Hyperactive Member
Thank you all for your many ideas. I'll look at them all now, and try them out.
That damn If statement - I'm always getting it wrong.
-
Jul 13th, 2000, 06:07 PM
#14
You guys
Mongo
Naw the combat programming has nothing to do with the military, is to do with our website once l can get the guys to agree to put the friggin thing up. Word of warning, never have an artist on your team of web developers, they just add months to the process.
Zap
Not being caught by that one again, though l noticed in email some one was.hehehehehehehe
Ian
Glad to help...don't tell John the Admin....mongo's looks to be about the best solution...damn.
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
|