Solved

Saving input text to a file

Posted on 2003-11-10
8
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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
 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month5 days, 7 hours left to enroll

627 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