|
-
Jun 27th, 2000, 12:15 AM
#1
Thread Starter
Hyperactive Member
Hi there,
For some reason my program's not working too well. There's 2 command buttons, a label and 2 forms. When the command button is pressed, 'I want' & number & 'sweets' appears in the label.
number is a random number from 1 to 9.
Then when the other button is pressed, form2 loads, and the number string should appear in a label on that form. But it doesn't. I've tried having number as a string, integer, etc, but still no luck.
Could you please take a look at my code? Thanks for any help.
Dim number As Integer
Private Sub Command1_Click()
Randomize
number = Int(Rnd * 9)
Label1 = "I want " & number & " sweets."
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Form_Load()
Label1 = number
End Sub
-
Jun 27th, 2000, 12:19 AM
#2
Hyperactive Member
you have your number as dim which is private
use
Code:
' in form1 in place of dim
Public number as Integer
' In form2
' Then to access on form2 say
label.Caption = form1.number
-
Jun 27th, 2000, 12:21 AM
#3
I do not quite understand what you want. Are you trying to make number be the caption of a label1 on Form2? If so, then this should work.
Code:
Private Sub Command1_Click()
Randomize
number = Int(Rnd * 9)
Label1 = "I want " & number & " sweets."
Form2.Label1 = number
End Sub
-
Jun 27th, 2000, 12:43 AM
#4
this sort of matches MSDN's code
Code:
Private Sub Command1_Click()
Randomize
number = Int((Rnd * 9) + 1) ' add the one since Rnd produces a random number higher than 0, but less than 1
Label1 = "I want " & number & " sweets."
Form2.Label1 = number
End Sub
-
Jun 27th, 2000, 01:16 AM
#5
Thread Starter
Hyperactive Member
learning all the time
Thanks everybody,
I think I'll use billrogers', though, because I actually have lots of integers in my program. I just sent a simplified version so it would be more simple to understand.
I'll just replace dim number as integer, with public number as integer, and so on,
thanks again!
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
|