Solved

Saving input text to a file

Posted on 2003-11-10
8
246 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 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

16 Experts available now in Live!

Get 1:1 Help Now