Saving Multiple Textboxes as One File?

I'm working on a program takes an address and then there is an array of 99 textboxes. I would like to be able to save the file as my own filetype and be able to open it back up to have the address and the textboxes already filled out. I am searching for a way to do that, but all I end up with is a lame CD control example that just saves txtBox1.text and the opens the file into txtBox1.text. Would I have to create an ini file? I woud like it to have an extention just for my program, so if you double click the file, my program opens.
GreggoryAsked:
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.

Stephen MandersonSoftware EngineerCommented:
Are the array of text boxes saved to one text box ?
0
Stephen MandersonSoftware EngineerCommented:
What you could do is save the all of the text in the array to one text box and save the text box to a file.

==== Join the Text Boxes =====
Dim i as integer
Dim str as String

str = ""
For i = 0 to 99
    str = str & Text(i).text & ", "
Next

str = Left(str, Len(str)-2)
TextJoined.text = str
0
Stephen MandersonSoftware EngineerCommented:
And to save the text box to a file. Add a rich text box to the form named textjoined

==== Save to a file =====
 path = "Data\"
 extention = ".ccd"
 FileName = "NameOfYourFile"

     TextJoined.SaveFile path & FileName & extention 'save the file

====Open the File =====
 path = "Data\" 'set the path
 extention = ".ccd"
 FileName = "NameOFYourFile"

      TextJoined.LoadFile path & FileName & extention    
0
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.

Stephen MandersonSoftware EngineerCommented:
And you can change the extension to suit yourself. Hope this helps.

Manderson
0
Stephen MandersonSoftware EngineerCommented:
And make sure you have a folder named Data in the directory you are running the program. Or change the Path to suit.
0
GreggoryAuthor Commented:
When I open the file, is each text box going to be filled out or after I join them, are they now 1 big box?
0
Stephen MandersonSoftware EngineerCommented:
Yes, they will be turned into one large Textbox. And stored Into the file.
0
Stephen MandersonSoftware EngineerCommented:
You can of corse alter that code to save each file as the number in its array. say,

Dim i as integer
Dim str as String
 path = "Data\"
 extention = ".ccd"
 FileName = "NameOfYourFile"


For i = 0 to 99
    Text(i).SaveFile path & FileName & extention 'save the file
Next

========== Load The data ==========

For i = 0 to 99
    Text(i).LoadFile path & FileName & extention 'Load the file
Next
0
Stephen MandersonSoftware EngineerCommented:
O what sorry, that will give the same name for each text box.

Dim i as integer
Dim str as String
 path = "Data\"
 extention = ".ccd"
 FileName = (i)


For i = 0 to 99
    Text(i).SaveFile path & FileName & extention 'save the file
Next

========== Load The data ==========
Dim i as integer
Dim str as String
 path = "Data\"
 extention = ".ccd"
 FileName = (i)

For i = 0 to 99
    Text(i).LoadFile path & FileName & extention 'Load the file
Next
0
Stephen MandersonSoftware EngineerCommented:
The only what to get them to .savefile is if they are Rich Text Boxes. hope this is ok for you ?
0
GreggoryAuthor Commented:
Does that save all 99 textboxes in one file, or each textbox to it's own file?
0
Stephen MandersonSoftware EngineerCommented:
The first way joins them all and saves as one file. The second way i showed will save a file for each text box.
0
GreggoryAuthor Commented:
Is there a way to create one file that will load all the info back into the right boxes?
0
Stephen MandersonSoftware EngineerCommented:
I dont think there is a way of doing it personaly, I may be wrong.
0
ShauliCommented:
'assuming all textboxes are in one array from 0 to 98 (I called the textbox array Text1, modify to your needs) then:

' here is how to call the subs. Locate these lines where you want to execute, save to file, and read from file respectively.
Private Sub Command1_Click()
'to save to file
Call Save_TextBoxes("your path & file name")   '<<<<<<<modify

'to read from file
Call Read_TotxtBoxes("your path & file name")   '<<<<<<<modify
End Sub

'sub to save to file
Public Sub Save_TextBoxes(ByVal sbPathFilename As String)
Dim tbLoop As Integer

'open file
Open sbPathFilename For Output As #1
    'loop the txtboxes
    For tbLoop = 0 To Text1.Count - 1
        Print #1, tbLoop & Chr(167) & Text1(tbLoop).Text
    Next tbLoop
Close #1
End Sub

'sub to read to text boxes:
Public Sub Read_TotxtBoxes(ByVal sbPathFilename As String)
Dim mySplit() As String, txtLoop As Integer, myLine As String
On Error GoTo errHandling
'open file
Open sbPathFilename For Input As #1
    'loop to read to txtboxes
    Do Until EOF(1)
        Line Input #1, myLine
            mySplit = Split(myLine, Chr(167), -1)
                If UBound(mySplit) > 0 Then
                    Text1(txtLoop).Text = mySplit(1)
                    txtLoop = txtLoop + 1
                End If
    Loop
Close #1
Exit Sub

errHandling:
If Err.Number = 340 Then
    MsgBox "More Lines Than TextBoxes"
    Err.Clear
    Close #1
Else
    MsgBox "An error has occured"
    Err.Clear
End If
End Sub

S
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
GreggoryAuthor Commented:
PERFECT! Thanks
0
ShauliCommented:
You are welcome. :)
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.