Results 1 to 2 of 2

Thread: visual basic 2017

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    1

    visual basic 2017

    not sure where to post this is ok I am tring to use select case with a random number but when i try, i get = in not defined for random or integer. this is the code for this



    dim r as new random
    r.next(1,5)
    select case r
    case 1
    do this
    case 2
    ect...

    end select


    thank you for the help in advance

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,348

    Re: visual basic 2017

    If you want to do a Select Case on a random number then you need to do it on a number, not the Random object that generated it. The Next method returns that number so you need to use that result. Your code should either be this:
    vb.net Code:
    1. Select Case r.Next(1, 5)
    or like this:
    vb.net Code:
    1. Dim n = r.Next(1, 5)
    2.  
    3. Select Case n
    For future reference, please use formatting tags when posting code (there are buttons for them on the editor toolbar) and, if possible, copy and paste code from the IDE rather than typing directly into the post. That way we get all the correct casing and indentation, which makes the code much easier to read.

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