|
-
Jul 15th, 2005, 10:13 AM
#1
Thread Starter
Junior Member
[RESOLVED] It works here... but not over there?
I bet at least some of you know the following code string well:
VB Code:
RndLabel.Text = (Int(Rnd() * 10))
Well, this works in one of my programs doing the exact same thing - setting a label's code to a random number between zero and nine. However, in a different program, the following:
Is underlined. The mouseover 'explanation' tells me "Operator '*' is not defined for types 'System.Windows.Forms.Label' and 'Integer'".
Direct excerpt from my program:
VB Code:
If Roomnmberrnd.Text = "102" Then
Rnd.Text = (Int([U]Rnd() * 20[/U]))
End If
Why does it tell me this? 
Edit: In my program, the 'Rnd.Text' does not have 'Rnd' underlined because that is the name of the label I'm working with (yes, Rnd).
-
Jul 15th, 2005, 10:21 AM
#2
Re: It works here... but not over there?
option strict on
VB Code:
Me.TextBox3.Text = (Rnd() * 10).ToString
"The dark side clouds everything. Impossible to see the future is."
-
Jul 15th, 2005, 10:27 AM
#3
Thread Starter
Junior Member
Re: It works here... but not over there?
 Originally Posted by Asgorath
option strict on
VB Code:
Me.TextBox3.Text = (Rnd() * 10).ToString
Ok, so suppose this is what I want to do...
VB Code:
If Roomnmberrnd.Text = "102" Then
Me.RndLabel.Text = (Rnd() * 20).ToString
If RndLabel.Text = 1 Then
'Blah, Blah, Blah, etc...
End If
End If
Plus, I just added that same string into my code and it gives me the same problem...
-
Jul 15th, 2005, 10:31 AM
#4
Thread Starter
Junior Member
Re: It works here... but not over there?
This is what it looked like when it worked:
VB Code:
'After a button was clicked, this was the action:
Encounternumber.Text = (Int(Rnd() * 10))
'Separate button...
If PartyLevelInput.Text = "1" Then
If Encounternumber.Text = "1" Then
'Blah blah, very long stuff
End If
End If
That worked - it generated completely random bits of information based on the number generated by (Int(Rnd() * 10) from the first button. However, now that I'm doing it in a different program...
Last edited by KidVBkiD; Jul 15th, 2005 at 10:35 AM.
-
Jul 15th, 2005, 10:37 AM
#5
Thread Starter
Junior Member
Re: It works here... but not over there?
- WHOA -
I just changed the name of the label (from "rnd" to "rndlbl") and it works?!
OK, keep that in mind. Thanks asgorath.
-
Jul 15th, 2005, 10:39 AM
#6
Thread Starter
Junior Member
Re: [RESOLVED] It works here... but not over there?
The code now reads, lol:
VB Code:
Rndlbl.Text = (Int(Rnd() * 20).ToString)
That generates an integer between 0 and 19, which is what I want. Thanks again, i'll use that in the future
-
Jul 15th, 2005, 10:46 AM
#7
Re: [RESOLVED] It works here... but not over there?
If you have a control or some other variable called "Rnd" then you need to qualify the method named "Rnd" so the compiler doesn't confuse the two, i.e. VBMath.Rnd() or Microsoft.VisualBasic.VBMath.Rnd(). Better you don't call anything else "Rnd" I think. It's not a very descriptive name anyway. You could also use the System.Random class instead.
Edit:
Just missed out.
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
|