1-demensional array string cannot be converted to integer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spud379
    New Member
    • Mar 2007
    • 11

    1-demensional array string cannot be converted to integer

    i am doing an assignment in vb.net. i have to select at random from and array what i have is

    dim country(29) as string
    dim random as new random

    txtcountry.text = random.next(cou ntry)

    I keep getting that this error
    1-demensional array string cannot be converted to integer

    can anyone help?

    thanks
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    #2
    Originally posted by spud379
    i am doing an assignment in vb.net. i have to select at random from and array what i have is

    dim country(29) as string
    dim random as new random

    txtcountry.text = random.next(cou ntry)

    I keep getting that this error
    1-demensional array string cannot be converted to integer

    can anyone help?

    thanks
    Dim randomNo as Int

    ...

    randomNo = toInt(random)

    txtcountry.text = randomNo(countr y)

    ?? would that work?

    Comment

    • spud379
      New Member
      • Mar 2007
      • 11

      #3
      No it didn't work but thanks anyway

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        When you create a random number between 0 and 28 you can then use it as an array index to select a random string. The index is the part in brackets so you need to put the random number in the brackets.
        country(random number here)

        Comment

        • spud379
          New Member
          • Mar 2007
          • 11

          #5
          I did it and this is how, if u want to know.

          Private choice As Integer
          Private random As New Random

          choice = random.Next(0, 29)
          txtcountry.Text = country(choice)

          Comment

          Working...