Saving input text to a file

I have a form with treeview1 , text1, and text 2.  When a node is clicked on the tree, text is shown in text1 that gives suggestions for input to text2. The idea is to design MyReportGenerator which will lead the user through writing a report by adding input to text2 for each subject.  I would like to save this input in file.mrg so that the user can quit, save interim work, and then start again and load file.mrg that would have all the saved prior work.

How do I create file.mrg from the text2 inputs associated with each node and save this file and then use it to input text to text2 for each node on the next use.

aijohn
aijohnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinnyd79Commented:
Private Sub Command1_Click()
Dim ff As Integer
ff = FreeFile
' opening for output will create the file or overwrite it
Open App.Path & "\file.mrg" For Output As #ff
Print #ff, Text1.Text
Print #ff, Text2.Text
Close #ff
End Sub

Private Sub Command2_Click()
Dim ff As Integer, Ln As String
ff = FreeFile
Open App.Path & "\file.mrg" For Input As #ff
Line Input #ff, Ln
Text1.Text = Ln
Line Input #ff, Ln
Text2.Text = Ln
Close #ff
End Sub
0
aijohnAuthor Commented:
I need to save output and have the input for Text1 and Text2 for each of several nodes.
0
JonothanTompsonCommented:
Well if the nodes of the treeview are going to be the same each time it is loaded ( not necesarily the text but howmany and what position they are in the tree) then you can just have the file.mrg set out like this
Say you have 4 different things to be inputed ( Time, Date, User, Description ) so once inputed they are put into different variabled

*** This is basically what you want i think
Dim iTime as String
Dim iDate as String
Dim iUser as String
Dim iDescrip as String
'These are then inputed so that they all have info

Private Sub SaveInfo()
Dim Whole as String
Whole = iTime & vbTab & iDate & vbTab & iUser & vbTab & iDescrip      'This colates all the info and makes the tabs make it so it can be spilt when loading
Open App.Path & "\file.mrg" For Output As #1
    Print #1, Whole
Close #1
End Sub

Private Sub LoadInfo()
Dim Whole as String
Dim Info() as String
Open App.Path & "\file.mrg" For Input As #2
While Not EOF(1)
 Line Input #1, Whole
Wend
Close #2
Info = Split(Whole, vbTab)
iTime = Info(0)
iDate = Info(1)
iUser = Info(2)
iDescrip = Info(3)
End Sub


Jonothan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

aijohnAuthor Commented:
Do I do something like this to keep track of the different inputs?

If TreeView1.SelectedItem.Text = "Report time" Then
     iTime=Text1.txt

If TreeView1.SelectedItem.Text = "Report the date" Then
     iDate=Text1.txt





       
0
aijohnAuthor Commented:
Above must be wrong as variable would be set when node was selected and
before any input.

sorry
0
JonothanTompsonCommented:
Sorry i dont understand your last post exactly,
yes the variables would be put at the top of your code so that they are instalized when your program is run
then you just have to set the variables
*** like so
If TreeView1.SelectedItem.Text = "Report the date" Then
    iDate=Text1.txt
End If



Jonothan
0
aijohnAuthor Commented:
How are the variables set when new text is entered in the textbox? Sorry, I am not making this clear.  I can see that your answer will insert text from the variable in the text box but I also want to save any new or edited input.
0
JonothanTompsonCommented:
One way to set them is

Dim Doing as String     ' Jus make sure that when the user clicks on a different node that Doing is changed

Private Sub txtInput_Change()
If Doing = "Date" Then
     iDate = txtInput.Text
Else If Doing = "Time" Then
     iTime = txtInput.Text
Else If Doing = "User" Then
     iUser = txtInput.Text
Else If Doing = "Descrip" Then
     iDescrip = txtInput.Text
End If
End Sub


Or the other way is to have it so that the user has to hit a command button and then that uses the same procedure as txtInput_Change but on press of the command button.



Jonothan
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.