|
-
Dec 9th, 2013, 06:15 PM
#1
Thread Starter
New Member
Setting up StreamReader to use 3 different text files
I need advice setting up StreamReader.
This is for a game. 3 radio buttons are supposed to control access to 3 text files (difficulty level).
I can get it to work for one. I declare (Dim) a new StreamReader and then open the file.
But if I try to Dim inside an "If, Them" statement to make a choice based on the radio buttons, I get an error because 'SR System' is 'Friend.
Could anyone suggest a basic organization for this set-up?
I have a loop for loading the text from the file into an array and choosing a random word. I just want to be able to specify any one of the three text files to run in the loop (one variable).
Thanks!
-
Dec 10th, 2013, 05:30 PM
#2
Member
Re: Setting up StreamReader to use 3 different text files
Can you post some of your code?
Thanks,
Paul
Please mark your threads Resolved if your thread has been answered..And don't forget to rate the post if the answer has helped you.
-
Dec 10th, 2013, 09:34 PM
#3
Re: Setting up StreamReader to use 3 different text files
LEt's say you have two cars... a VW and a Subaru... Let's say you're sitting in the VW, when you go to make a call on your cell... only, you left your cell in the Subaru... it can't be in the Subaru and let you make a call from the VW at the same time.
Same thing here... when you dim a variable inside the If statement, it's only good inside that block (the Subaru)... you can't use variables declared in the If statement outside of the block (while sitting in the VW)... the scope of any variable is defined by the block in which it is defined... be it class, module, sub, loop, conditional, what ever....
-tg
-
Dec 10th, 2013, 09:39 PM
#4
Re: Setting up StreamReader to use 3 different text files
As tg suggests, you can't declare the variable inside the If block because then it doesn't exist outside the If block. The alternative is outside the If block. You have two choices:
1. Declare the StreamReader variable first but do not create a StreamReader object. Use an If...ElseIf statement to determine which RadioButton is checked and then create a StreamReader object inside each block using the appropriate file name and assign them to the variable. You can then use the StreamReader after the End If line.
2. Declare a String variable first and assign the appropriate file name to it inside the If...ElseIf statement. After the End If line, declare and create the StreamReader and pass it the String containing the file name.
-
Dec 11th, 2013, 09:55 PM
#5
Thread Starter
New Member
-
Dec 11th, 2013, 09:59 PM
#6
Re: Setting up StreamReader to use 3 different text files
You should debug your code. Don't just read the code; watch it in action. Place a breakpoint at the top of a section of code using F9 and then, when execution breaks, you can step through the code line by line to see exactly where it goes and you can evaluate all your variables and whatever else you like at each step. That way you don;t have to guess what's happening; you can see it happen.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|