Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
You can give one form a public method that reads a file, then call it from the other form.
Gamer extraordinaire. Programmer wannabe.
  • *Experts*
Posted
You mean when you start your app so it automatically opens a text file or you open your form from another one and want to pass in the text from the text file?
  • *Experts*
Posted (edited)

I guess you want to open it from another form then.

Edit the constructor of your form to accept a string variable that will hold the path of the file:

Public Sub New(ByVal path As String) accept a string variable
MyBase.New()
InitializeComponent()
Dim reader As New IO.Streamreader(path)
TextBox1 = reader.ReadToEnd 'read to something, like a textbox
End Sub

You didnt really answer my last question so Im not sure what you want :).

Edited by mutant
Posted

clarification

 

I have over a 1000 possible forms.

Info for check boxes for each is in a text file.

I want to load a text file ,execute , load another text file etc.

Each text file contains one line of text for each checkbox.

Also want to call text files by name from the form.

May not be possible.

Thanks.

  • *Experts*
Posted
So for example you have a form called "Form1" and you want to open a file that has the same name, read it, create a checkbox for every line?
Posted

more info

 

I have created a form that generates checkboxes on the "fly"

I wan tto call a text file that has captions for the checkboxes and corresponding text output. Each line of the text file has info for a checkbox.

I want an automatic way to select text files by names to fill in the info for the form.

 

Think of it as a 1000 questtion mutiple choice test.

Sorry this is so difficult to explain.

  • *Experts*
Posted (edited)

Oh :), I hope I understood your question right now.

 

So you want to create controls when the form loads then I assume you open that form from another one which asks to select a quiz. You would have to edit the constructor of the form that displays the quiz and pass in the path to the quiz.

Dim path As string 'a variable that will keep the path
Public Sub New(ByVal quizpath as string)
MyBase.New()
InitializeComponent()
path = quizpath
End Sub

And then in your constructor or form load this:

Dim reader As New IO.StreamReader(path) 'get the path of the quiz
Dim x as Integer = 0 'keep track of how many checkboxes there is
Do While reader.Read()
checkboxes(x) = New CheckBox
checkboxes(x).Caption = reader.ReadLine() 'read the line
checkboxes(x).Location = New Point(coordinates) 
Me.Controls.Add(checkboxes(x))
x +=1
Loop

[edit]

Forgot the x += 1 line :)

[/edit]

Edited by mutant
Posted

Just make sure you use a naming convension for your files. Doing so would allow you to easily create a generic function to open whatever file you wanted (using a loop, from the constructor, whatever).

 

Although.. why have 100s of files when you could just use a single XML file and group questions accordingly? Then you could just write simple searching algorithms to find what you're looking for, or better yet load the XML file into memory (maybe an array, or ArrayList if need be).

Gamer extraordinaire. Programmer wannabe.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...