Android Question Question about strings

tufanv

Expert
Licensed User
Longtime User
Hello
i have an int named numberofcars that randomly selects a number between 1 and 20 with the code numberofcars = rnd(1,20)
and i have 20 strings declared like car1,car2,car3 ..... car20 as String

Now the quesiton is for example numerofcars is 17 (choosen randomly) i want to assign a value to car1 to car17 (the value is not important , I just want to know how to assign a value to the cars that comes from the numberofcars int. Shortly : I have to assign car1,car2... car17 a value but not assign anything to car18 car19 and car20 )

The question is mixed a little bit hope u can udnerstand TY
 

klaus

Expert
Licensed User
Longtime User
You should use an array of strings.
Dim car(20) As String
Then you can access each car with car(0), car(1), car(2) etc.
I suggest you to begin with index 0 instead of 1.
Be aware that the function numberofcars = Rnd(1,20) generates numbers between 1 and 19 !
From the help: Returns a random integer between Min (inclusive) and Max (exclusive).
 
Upvote 0
Top