[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).
Re: It works here... but not over there?
option strict on
VB Code:
Me.TextBox3.Text = (Rnd() * 10).ToString
Re: It works here... but not over there?
Quote:
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...
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...
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. :)
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
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. :cry: