Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Line
I have decided to take a break from Card Sharks (though somebody may be doing an improvement on the game as of lately), and I am now working on Super Password.
I would like to find out some information:
If I were to randomly select a text file from a range of text file numbers within a folder, how would I randomly choose the text file number? Like say, if I were to choose between textfile0 to textfile20, or something.
Also, if the program were to choose randomly from a series of lines (the lines start with red words - lines 3 to 9, in this case), and the CPU player must give one of the words and if the contestant or CPU player gives one of the words elsewhere on the line and it matches the first word on the second line (as shown in purple text), how do I code it?
If I am unclear in what I am saying, please let me know. Here is a segment of the text file:
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
Both goals can be achieved with the RND function
1. For the numbers: Rnd*20+1
I know 20 is an example, you can add all the files to a FileListbox and use Rnd*File1.ListCount. Then you'd simply select File1.List(result). This can be very useful if you don't know the number of files ahead of time or it is possible that there can be gaps in the file names.
2. Lines. Assuming your file is carriage-return delimited, read the entire file into a string and split it on carriage returns. You will now have the number of file lines. Again use random: Rnd*NrLines to select a line in your array returned by Split.
Insomnia is just a byproduct of, "It can't be done"
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
I found it, I clicked the button, and nothing happens. What do I do from there?
EDIT: I just went to form view mode, and I discovered a drop down menu with scroll bar. I am not supposed to artificially select the file, btw. As far as I can see, it displays all the files in the main folder and not the text folder. How do I display all the text files (and only those in the text folder) in the file list box?
Last edited by JonSea31; Jan 4th, 2010 at 06:23 PM.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
^ I put it into Form_Load, and all the text folders are shown in the FileListBox. Thanks!
Now, on to retrieving the puzzle text file. How do I randomly select the puzzle to be used for, say, Round One?
Like, say, if I were to randomly choose a puzzle file by number in this sub:
Code:
Public Sub GetR1Puzzle()
???
End Sub
And if I were to randomly select a line from the range of lines 3 to 9, and displaying the first word on the line in a label (for example, PWClue) in these subs (which are "shells" currently):
Code:
Public Sub FirstClue1()
End Sub
Code:
Public Sub SecondClue1()
End Sub
Code:
Public Sub ThirdClue1()
End Sub
Code:
Public Sub FourthClue1()
End Sub
I should only have to use each line from that range of lines 3 to 9 only once per Clue1 sub. Any suggestions?
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
I believe I may have the random selecting of the text file numbers down pat, but I am having problems with randomly selecting a line from a range of 7 lines (the line numbers, in this case, would be 3 to 9). Plus from that line, I would like to display in the SetCluePW area the first word on that particular line randomly selected
Here is the code I have thus far:
Code:
Public Sub FirstClue1()
Dim i As Integer, j As Integer, X As Integer, tmpint As Integer
PlaySound App.Path & "\sounds\wordsound.wav", ByVal 0&, SND_ASYNC Or SND_FILENAME
i = Rnd * 7 + 1
For j = 3 To 9
j = i
Line Input #1, tmpstr
tmp = Split(tmpstr, ",")
PWClue1(j) = tmp(0): Guess1(j) = tmp(1)
Next j
' Randomize
For i = 3 To 9
X = Int(Rnd() * 7) + 1
tmpstr = PWClue1(i)
tmpint = Guess1(i)
PWClue1(i) = PWClue1(X)
Guess1(i) = Guess1(X)
PWClue1(X) = tmpstr
Guess1(X) = tmpint
Next
CurrentPW = CurrentPW + 1
If CurrentPW > 8 Then CurrentPW = 1
SetCluePW PWClue1(CurrentPW)
End Sub
When I did a test run on the form, I got a pop-up message saying "Run-time Error '52': Bad file name or number." When I clicked the "Debug" button on the pop-up, it displayed where the error prevails (the line in bold red text). Where did I go wrong?
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
Actually, the file would be open - as per the following code:
Code:
Public Sub GetR1Puzzle()
Dim i As Integer, Index As Integer
i = Rnd * File1.ListCount
PWpuzzle(Index) = PWpuzzle(rand(Index))
Open App.Path & "\puzzles\puzzle" & Trim(Val(Index)) & ".txt" For Input As 1
Close
FirstClue1
End Sub
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
Do a check to see if it is open, add a line before the line input to see :-P
"bad file name or number" does suggest the file isn't open or you're using the wrong info. Only thing that jumps out at me is "For Input As 1" which might have to be "For Input As #1"
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
I did a test run of the form, and with this update:
Code:
Public Sub FirstClue1()
Dim Index As Integer
PlaySound App.Path & "\sounds\wordsound.wav", ByVal 0&, SND_ASYNC Or SND_FILENAME
SetCluePW PWpuzzle(rand(Index))
End Sub
I only displayed the numeric digit "0" in the SetCluePW area. I was doing this as a test run to see if something would display, but how can I get the first word from any line number between 3 and 9 to display.
Just to clarify:
PWpuzzle = the Text File Number (which should randomly choose the file number within the range of 0 to 9). It only displays the number "0" to start and nothing else. This means the text file is not being picked at random. Help may be required on that one.
PWClue1 = in the first post of this thread, a portion of the text file was posted, and the first word on each of lines #3 to #9 (the first line from the top being line #0) is displayed in red. That word should be displayed in the SetCluePW box. Again, help may be required on that one.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
I have 211 files (0 to 210 inclusive) total in my folder, and I have manipulated the code to see what happens, and I get the following error message (as bolded in red):
Code:
Public Sub GetR1Puzzle()
Dim i As Integer, j As Integer, X As Integer, Index As Integer
For i = 0 To 210
i = Rnd * File1.ListCount
PWpuzzle(i) = PWpuzzle(rand(i)) <== Subscript Out of Range Error Message Prevails
Open App.Path & "\puzzles\puzzle" & Trim(Val(i)) & ".txt" For Input As 1
Close
Next
FirstClue1
End Sub
If there is a better way to code this randomizing of text file numbers, please let me know.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
subscript out of range means it's trying to use a value higher than the array will allow, so the ubound() of PWpuzzle will be lower than whatever i is when it reaches there...try looking at what i is when it crashes :-P
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
I removed the "rand" from the code, and I ran the code, and I still show the number "0" in the SetCluePW area (remember, this is for testing purposes only).
Here is the updated code:
Code:
Public Sub GetR1Puzzle()
Dim i As Integer
i = Rnd * File1.ListCount
For i = 0 To 210
PWpuzzle(i) = PWpuzzle(i)
Open App.Path & "\puzzles\puzzle" & (Trim(Val(i))) & ".txt" For Input As 1
Close
Next
FirstClue1
End Sub
If i is supposed to determine the file number to be selected at random, why do I get a zero as a result? How do I get the file number within range (from 0 to 210)?
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
I am guessing here, but set file1 as visible rather than hiding it...the fact that it is hidden might be making a difference to your results...and in both cases check the listcount's value. Add a few debug.print in there so you can see what the values are for each part and soon you'll know where the problem is occuring...this is the best way to debug a program :-P
Looking at your code, you should ALWAYS get number 210 because of the way it's laid out...and AFAIK the code doesn't really even do anything...but you did say it was just for testing :-)
Also you are using i both in the for/next and in the rnd statement...could that be it?
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
Best thing to do is to upload it here...unless there's a reason why you don't want it public?
If so, sure...upload it somewhere and send me the link in PM and I'll take a look and see if I can work out what it's doing and what it's doing wrong :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
Jon, rand is not a function, rnd is. Take your time and review your code to see if you have other typos. Use option explicit and start your project with Ctrl+F5.
Also, adding a Close right after you open your file is simply closing the file.
Insomnia is just a byproduct of, "It can't be done"
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
Okay, first definite bug is in firstclue1()
Code:
Public Sub FirstClue1()
Dim i As Integer
PlaySound App.Path & "\sounds\wordsound.wav", ByVal 0&, SND_ASYNC Or SND_FILENAME
SetCluePW PWpuzzle(i)
End Sub
You've DIMmed the variable i so it'll be 0 at this point, then you've set the clue to i, meaning it will ALWAYS be 0 as you mentioned. Now, if we go back to the previous part (copied from above in this post) you'll need to sort out something to deal with choosing a random number...
Code:
Dim i As Integer
i = Rnd * File1.ListCount
For i = 0 To 210
PWpuzzle(i) = PWpuzzle(i)
Open App.Path & "\puzzles\puzzle" & (Trim(Val(i))) & ".txt" For Input As 1
Close
Next
FirstClue1
My suggestion here is to use Public pw as single in a module, that way pw will be globally available, then use this code:
Code:
pw = int(Rnd(1)* File1.ListCount)
FirstClue1
(I've always done my randomisation that way, it's a throwback to QBasic, I think :-))
That should choose a random number between 0 and the upper bound of the filelistbox then give the first clue
Edit: Thought there was a bug with pwpuzzle() but turned out the passwords hadn't been set up to load yet :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
On second thoughts, instead of making pw global, you could pass it as an argument
Code:
Public Sub FirstClue1(i as single)
PlaySound App.Path & "\sounds\wordsound.wav", ByVal 0&, SND_ASYNC Or SND_FILENAME
SetCluePW PWpuzzle(i)
End Sub
That way you wouldn't even need the module and to set anything public...it's all up to you though, and you know you'd then have to change FirstClue1 to FirstClue1 pw in the other bit of code :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
Originally Posted by JonSea31
It still does not choose the text file as random.
Depends on where you're looking. If you look at the big 0 on-screen you're looking in the wrong place to check for the file it chooses...the variable pw changes each time. To test this, put debug.print pw below the line where pw is generated as a random number and each time you run it the number it generates should be different (if you use randomize like I mentioned above :-))
The part of the code that puts that 0 on-screen is taking the value from the PWpuzzle variable and each one is "0"
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
I watched the show and I'm more confused than I was before...so I think I'll just try to work out what you need done for the loading of the questions and you can work on it from there :-P
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
Anyway, I've made a few changes and it now loads a random text file and chooses a random line to work from and displays the first word in that line on-screen...From what I barely understand of the game it's similar to a game called Blankety Blank which used to be on over here in the UK (probably around the same time :-)), basically word association, so you're given a word and you have to guess the words associated with it...it's now up to you to work on the data input aspect of it :-P
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
All that would get me on the right track would be to use an individual puzzle file for 4 to 6 rounds max. Since there are normally 4 rounds (1st being a $100 puzzle, 2nd being $200, 3rd being $300, and 4th and subsequent rounds being $400 each), and 5 passwords per puzzle (4 clues maximum for each), it would possibly get me on the right track if even just the code for the retrieving puzzle file and the first password of the round (with 4 clues max) be done so far.
Just to refresh:
mister,mister,mr,mr., <== Answer to puzzle
coffee,coffee, <== First Password
none,none,none,none, <== Forms of the password (if needed)
folgers,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,
sanka,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,
caffeine,coke,coffee,coke,insomnia,coffee,coffee,coffee,coffee,coffee,coffee,
cappuccino,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,
beans,kidneys,kidneys,jelly,vegetable,coffee,coffee,coffee,coffee,coffee,coffee,
espresso,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,
java,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee, ^^Red words are the clues given, and the player must key in the attempt to identify the password, and if the player gives the word shown on the second row (coffee, in this case), that player can have a chance at solving the puzzle.
BTW, I can code the images and display the password later on.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
Ah, I think I understand a bit better...the text after the red is actually for the CPU answers...then perhaps I need to redo the code I just sent you :-)
Edit: I do, but now looking at those text files you're loading from I'm lost again because they're more than 10 lines long so I'm not sure exactly how that will work within the scope of what I am trying to do :-P The code I have chooses a word from random but differently to how I think you needed it, so it is almost there. I'm also not sure where you want each clue to go at the moment.
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
This means there are a total of 46 lines in each text file (#1 should be #0, and #46 should be #45). The answer to the puzzle on the first line, followed by 5 groups of 9 lines (as numbered). I hope this makes things a bit simpler.
And if a player was prompted to identify the password, how would I include the contents on Line #1 in the code to allow for a player to guess the password correctly?
Last edited by JonSea31; Jan 5th, 2010 at 07:27 PM.
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
Reviving this thread for a good reason...
I am resuming the work on Super Password as of lately, and I will inform some of you that during the first round, the contestant would have to identify the password as displayed on the second line in the following code:
mister,mister,mr,mr., <== Answer to puzzle
coffee,coffee, <== First Password
none,none,none,none, <== Forms of the password (if needed)
folgers,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,
sanka,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,
caffeine,coke,coffee,coke,insomnia,coffee,coffee,coffee,coffee,coffee,coffee,
cappuccino,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,
beans,kidneys,kidneys,jelly,vegetable,coffee,coffee,coffee,coffee,coffee,coffee,
espresso,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,
java,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,coffee,
During Round One, the computer player would give the clues (as shown in red text above), and in order to win the right to solve a puzzle, your guess has to match any of the two words that are in the blue text. There are two words on the second line in case there are two words that sound alike but are spelled differently.
Now, I am on to Round Two, and the gameplay is supposed to be reversed. Instead of the CPU giving the clues, the password (in this case, the first word on the second row) would be displayed on the screen (a caption in a text label would read "The password is... COFFEE." in this case), and the human player would have to key in a clue. If the clue matches one of the 7 words in red text, the program should try to locate one of the 10 words (as displayed in purple text) and randomly select one of those 10 words on that line.
Say, if the human player keyed in the Text box "beans" - that would mean the program would randomly select any of the words in purple text on that particular line. In this case, if one of the 10 words randomly selected was to be "coffee", this means that randomly selected word matched the password (as displayed in blue text), and the player has the right to solve the puzzle.
I am attaching the code I have so far (btw, one other user, who hasn't posted since April, gave me a head start on this project). If anyone can scan the code and see what can be done about the "reverse gameplay" for Round 2, that would be great.
Oh, and btw, Round 3 should have the same Round 1 gameplay (as already done in the code), and Round 4 gameplay should be the same gameplay as Round 2. In other words, odd-numbered rounds should be similar to Round 1 gameplay whereas even-numbered rounds should use reverse gameplay as I described in this post.
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
I realized where I may have went wrong.
I am taking a stab at coding the game, but I was hoping to randomly select the first word from a range of lines (in this case, lines 4 to 10).
Here is some of the code I am providing:
Code:
Private Sub GetPWPuzzle()
Dim x As Integer, tmpstr As String, tmpstr1 As String, tmpstr2 As String, tmpstr3 As String, tmpstr4 As String, tmpstr5 As String, tmpstr6 As String, tmpstr7 As String, tmpstr8 As String, tmpstr9 As String, tmpstr10 As String, tmpstr11 As String, i As Integer
Open (App.Path & "\puzzles\puzzle" & (Rnd() * 3) & ".txt") For Input As 1
If PW = 1 Then
For i = 4 To 10
Line Input #1, tmpstr
tmp = Split(tmpstr, ",")
PWClue1(i) = tmpstr(0): CelebGuess1(i) = tmpstr(1): CelebGuess2(i) = tmp(2): CelebGuess3(i) = tmp(3): CelebGuess4(i) = tmp(4): CelebGuess5(i) = tmp(5): CelebGuess6(i) = tmp(6): CelebGuess7(i) = tmp(7): CelebGuess8(i) = tmp(8): CelebGuess9(i) = tmp(9): CelebGuess10(i) = tmp(10)
Next i
ElseIf PW = 2 Then
For i = 13 To 19
Line Input #1, tmpstr
tmp = Split(tmpstr, "|")
PWClue2(i) = tmp(0): CelebGuess1(i) = tmp(1): CelebGuess2(i) = tmp(2): CelebGuess3(i) = tmp(3): CelebGuess4(i) = tmp(4): CelebGuess5(i) = tmp(5): CelebGuess6(i) = tmp(6): CelebGuess7(i) = tmp(7): CelebGuess8(i) = tmp(8): CelebGuess9(i) = tmp(9): CelebGuess10(i) = tmp(10)
Next i
ElseIf PW = 3 Then
For i = 22 To 28
Line Input #1, tmpstr
tmp = Split(tmpstr, "|")
PWClue3(i) = tmp(0): CelebGuess1(i) = tmp(1): CelebGuess2(i) = tmp(2): CelebGuess3(i) = tmp(3): CelebGuess4(i) = tmp(4): CelebGuess5(i) = tmp(5): CelebGuess6(i) = tmp(6): CelebGuess7(i) = tmp(7): CelebGuess8(i) = tmp(8): CelebGuess9(i) = tmp(9): CelebGuess10(i) = tmp(10)
Next i
ElseIf PW = 4 Then
For i = 31 To 37
Line Input #1, tmpstr
tmp = Split(tmpstr, "|")
PWClue4(i) = tmp(0): CelebGuess1(i) = tmp(1): CelebGuess2(i) = tmp(2): CelebGuess3(i) = tmp(3): CelebGuess4(i) = tmp(4): CelebGuess5(i) = tmp(5): CelebGuess6(i) = tmp(6): CelebGuess7(i) = tmp(7): CelebGuess8(i) = tmp(8): CelebGuess9(i) = tmp(9): CelebGuess10(i) = tmp(10)
Next i
ElseIf PW = 5 Then
For i = 40 To 46
Line Input #1, tmpstr
tmp = Split(tmpstr, "|")
PWClue5(i) = tmp(0): CelebGuess1(i) = tmp(1): CelebGuess2(i) = tmp(2): CelebGuess3(i) = tmp(3): CelebGuess4(i) = tmp(4): CelebGuess5(i) = tmp(5): CelebGuess6(i) = tmp(6): CelebGuess7(i) = tmp(7): CelebGuess8(i) = tmp(8): CelebGuess9(i) = tmp(9): CelebGuess10(i) = tmp(10)
Next i
End If
Close
' Randomize
'new
If PW = 1 Then
For i = 4 To 10
x = Int(Rnd() * 7) + 1
tmpstr1 = PWClue1(i)
tmpstr2 = CelebGuess1(i)
tmpstr3 = CelebGuess2(i)
tmpstr4 = CelebGuess3(i)
tmpstr5 = CelebGuess4(i)
tmpstr6 = CelebGuess5(i)
tmpstr7 = CelebGuess6(i)
tmpstr8 = CelebGuess7(i)
tmpstr9 = CelebGuess8(i)
tmpstr10 = CelebGuess9(i)
tmpstr11 = CelebGuess10(i)
PWClue1(i) = PWClue1(x)
CelebGuess1(i) = CelebGuess1(x)
CelebGuess2(i) = CelebGuess2(x)
CelebGuess3(i) = CelebGuess3(x)
CelebGuess4(i) = CelebGuess4(x)
CelebGuess5(i) = CelebGuess5(x)
CelebGuess6(i) = CelebGuess6(x)
CelebGuess7(i) = CelebGuess7(x)
CelebGuess8(i) = CelebGuess8(x)
CelebGuess9(i) = CelebGuess9(x)
CelebGuess10(i) = CelebGuess10(x)
PWClue1(x) = tmpstr1
CelebGuess1(x) = tmpstr2
CelebGuess2(x) = tmpstr3
CelebGuess3(x) = tmpstr4
CelebGuess4(x) = tmpstr5
CelebGuess5(x) = tmpstr6
CelebGuess6(x) = tmpstr7
CelebGuess7(x) = tmpstr8
CelebGuess8(x) = tmpstr9
CelebGuess9(x) = tmpstr10
CelebGuess10(x) = tmpstr11
Next
CurrentPW = CurrentPW + 1
If CurrentPW < 4 And CurrentPW > 10 Then CurrentPW = 1
I did a test run, and I get an error message saying "Subscript out of range." I mean, I put the PWClue1(4 to 10) in the declarations section, and I still get the error message. What would I have to do to fix it?
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
After the first if condition onwards, your for loop counter uses values which are higher than 10(10 is the upperbound of your array). So, you have to either increase the size of the array or rewrite the code...
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
Re: Randomly Selecting Text File Number, Selecting Line, and Retrieving Part of a Lin
Thanks for the help, folks. I think I will try a hands-on approach with regards to selecting from a set range by studying a VB Manual I got from my friend last year, and I will see what I can do to learn this approach when my Card Sharks game is completed.