Solved

Saving input text to a file

Posted on 2003-11-10
8
251 Views
Last Modified: 2010-05-01
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
0
Comment
Question by:aijohn
  • 4
  • 3
8 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9719045
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
 

Author Comment

by:aijohn
ID: 9719081
I need to save output and have the input for Text1 and Text2 for each of several nodes.
0
 
LVL 1

Accepted Solution

by:
JonothanTompson earned 125 total points
ID: 9719098
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
 

Author Comment

by:aijohn
ID: 9719435
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:aijohn
ID: 9719575
Above must be wrong as variable would be set when node was selected and
before any input.

sorry
0
 
LVL 1

Expert Comment

by:JonothanTompson
ID: 9719774
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
 

Author Comment

by:aijohn
ID: 9719886
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
 
LVL 1

Expert Comment

by:JonothanTompson
ID: 9720091
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now