|
It is currently Wed Dec 03, 2008 2:02 am
|
View unanswered posts | View active topics
|
Page 1 of 1
|
[ 2 posts ] |
|
| Author |
Message |
|
alcoholic
|
Post subject: Text Files Posted: Sun Jul 13, 2008 7:58 pm |
|
Joined: Sun Jul 13, 2008 7:43 pm Posts: 1
|
|
Hi all,
I'm new to VB 2008 Express (I could help myself in VB6) but everything seems so complicated, so I would appreciate some help.
I want to read random lines from a file into an array (I can do that fine), but I want ALL the lines in random order, so I was thinking of generating my random number (1-300, for example), but when I get to 299, how long is it going to take to "trigger" 300 (or whatever number is left)???
So I was thinking that the best is to read line random(x) and then delete that line from the file, and then do a random(1-299) and so on. How would I write these lines into another file then (new file).
If anyone could give me some sample code I would appreciate it, and any links to text-file handling would also be welcome.
Thanx
|
|
| Top |
|
 |
|
mmkhetan
|
Post subject: Posted: Sun Aug 24, 2008 8:27 am |
|
Joined: Sun Aug 17, 2008 1:40 pm Posts: 4 Location: Hyderabad, INDIA
|
|
We are on VB6. We use following function to randomly assign numbers in a arry and then proceed as our requirement.Here M is a one dimensional array of no of entries you would like to have in your file. intially every entry is 0. as the randl\om nos are generated they are posted in respective cells, and if the gnerated no is already assigned then anohter no is generated and so on.
the procedure is quite fast and can populate 1000 nos within miliseconds, and 20000 nos also within a second.
Sub GENRATE(M%())
Randomize Timer
nk% = UBound(M, 1): MM% = 1
Do: l% = Int(Rnd(1) * nk) + 1
If M(l) = 0 Then M(l) = MM: MM = MM + 1
Loop While MM <= nk
End Sub
Once this array is with you, then you can incorpote it with your data lines and thereafter sort them on these numbers to radomize your data.
_________________ Windostat your own way of computing statistics
|
|
| Top |
|
 |
|
Page 1 of 1
|
[ 2 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 0 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums. Click here to Register
If you are a current member here on DEVPPL, please login below:
|
|
|