Results 1 to 7 of 7

Thread: [RESOLVED] It works here... but not over there?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    18

    Resolved [RESOLVED] It works here... but not over there?

    I bet at least some of you know the following code string well:

    VB Code:
    1. 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:

    VB Code:
    1. Rnd() * 10

    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:
    1. If Roomnmberrnd.Text = "102" Then
    2.             Rnd.Text = (Int([U]Rnd() * 20[/U]))
    3.         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).

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: It works here... but not over there?

    option strict on
    VB Code:
    1. Me.TextBox3.Text = (Rnd() * 10).ToString
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    18

    Re: It works here... but not over there?

    Quote Originally Posted by Asgorath
    option strict on
    VB Code:
    1. Me.TextBox3.Text = (Rnd() * 10).ToString
    Ok, so suppose this is what I want to do...

    VB Code:
    1. If Roomnmberrnd.Text = "102" Then
    2. Me.RndLabel.Text = (Rnd() * 20).ToString
    3. If RndLabel.Text = 1 Then
    4. 'Blah, Blah, Blah, etc...
    5. End If
    6. End If

    Plus, I just added that same string into my code and it gives me the same problem...

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    18

    Re: It works here... but not over there?

    This is what it looked like when it worked:

    VB Code:
    1. 'After a button was clicked, this was the action:
    2. Encounternumber.Text = (Int(Rnd() * 10))
    3.  
    4. 'Separate button...
    5.  
    6.         If PartyLevelInput.Text = "1" Then
    7.             If Encounternumber.Text = "1" Then
    8.                 'Blah blah, very long stuff
    9.             End If
    10.         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.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    18

    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.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    18

    Re: [RESOLVED] It works here... but not over there?

    The code now reads, lol:

    VB Code:
    1. 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

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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
  •  



Click Here to Expand Forum to Full Width