Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Giving Random Values to an Array
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DifinityRJ




PostPosted: Sun Mar 16, 2008 4:28 pm   Post subject: Giving Random Values to an Array

I am having problems with the syntax in Visual basic to give an array that holds 10 values to assign it 10 random numbers.

In Turing you can do it like this

code:
var x :array 1..10 of int
for a:1..10
x(a):=Rand.Int(1,10)
end for


In visual basic...so far I've got

Dim xArray(9) as Integer

Thanks for any help, in advance.
Sponsor
Sponsor
Sponsor
sponsor
A.J




PostPosted: Sun Mar 16, 2008 4:30 pm   Post subject: Re: Giving Random Values to an Array

I'll advise you to check out the tutorials.
They're pretty helpful Wink
DifinityRJ




PostPosted: Sun Mar 16, 2008 4:37 pm   Post subject: Re: Giving Random Values to an Array

Yes I've checked them out.
nike52




PostPosted: Sun Mar 16, 2008 6:32 pm   Post subject: Re: Giving Random Values to an Array

stick for loop/while loop here with counter i, going from 0 to 8
xArray(i) = Int((HighestValue - LowestValue + 1) * Rnd) + LowestValue

stick randomize in the form_load to get diff random sequences

i like the bunnie, i have 2 fwuffy bunnies with me right now:D
CodeMonkey2000




PostPosted: Sun Mar 16, 2008 8:20 pm   Post subject: RE:Giving Random Values to an Array

Here is a useful function that is similar to turing's Rand.Int.
code:
Private Function randInt(ByVal x As Integer, ByVal Y As Integer)
   If x > Y Then
      Error (3)
   End If
   randInt = Int(Rnd * (Y - x + 1)) + x
End Function
unoho




PostPosted: Mon Sep 15, 2008 11:02 pm   Post subject: RE:Giving Random Values to an Array

hey man, im pretty new to arrays.. but i think it would be something like this??

Dim intX(1 to 10) as integer
dim intCount as integer

for intCount = 1 to 10
intX(intCount) = randint(1,10)
next intCount


im not relaly sure about the randint part because i haven't used it for a long time. lol
just try tht.
jbking




PostPosted: Fri Sep 19, 2008 2:37 pm   Post subject: RE:Giving Random Values to an Array

Dim xArray(9) as Integer defines a 9 element array as 0-8 are the valid indices for the array.

Try this instead:
Dim xArray(10)

JB
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: