how do i save multiple textboxes to one file for example a textfile
Printable View
how do i save multiple textboxes to one file for example a textfile
OK Lets say there a re 3 text boxes.
Option Explicit
Dim str(2) As String 'array holds 3 strings 0, 1, 2
Private Sub cmdSave_Click()
str(0) = Text1
str(1) = Text2
str(2) = Text3
Open App.Path & "\words.txt" For Output As #1
'Then save the strings to the file:
Write #1, str(0), str(1), str(2)
Close #1
End Sub
OK I wrote the app in full,
does someone else have an idea that actually works??
It works. Let me see your code. You will not get answers with that attitude. If you look at the text file your data will be there. If you need to retrieve the data you will need to add the code for that.
As I have said numerous times, This will get you on the right path. I am not here to do your work for you.
i can't start retrieving data if the saving piece doesn't even work
Post your code
OK I wrote the code in it's entirety for you. Look above, I didn't want to do it, but you seemed stumped.
Lee
Now, if you want to retrieve the data change the code as follows:
Clear the textboxes:
txt1 = ""
txt2 = ""
txt3 = ""
Open app.path & "\words.txt" For Input As #1
Input #1, str(0), str(1), str(2)
Then set them to the textboxes
txt1 = str(0)
txt2 = str(1)
txt3 = str(2)
close #1
Does that make sense?
it works now thnx allot sorry i was a bit bold in the beginning
use a commondialog in this piece of code showopen and showsave would be nice for the user to determine where to save and wich file to open
Add the control to the form(s)
Let's say it's called cdl1
cdl1.showopen (will show the Open screen)
cdl1.ShowSave (will show the save screen)
Look up Common Dialog Box in the Help file it's quite descriptive
when i save a file there is no file created now what?
Question:
Do you Know about the different ways to Open
a file, ie... Append, Read, Write, and so on?
I would not worry about a Common Dialog Box, and how to
pass strings & values to and from it, until I had the code to
do the actual reading and writeing accomplished.
MyFileNum = freefile 'Look Up FreeFile
Open "C:\temp.text" for OutPut as #MyFileNum 'Look Up Open, Output
Print #MyFileNum, "This is the First Line"
Print #MyFileNum, "This is the Second Line"
Close #MyFileNum
MyFileNum = freefile
open "c:\temp.text" for input as #MyFileNum
While Not EOF(MyFileNum)
Line Input #MyFileNum, X$ 'Look up Line Input
msgbox X$
wend
close #MyFileNum
msgbox "All Done"
-The above is for illustration purpose
-Hop this Helps
-Lou
i know append and so on and thnx for that last piece of code but now i still don't have my question answered there is no file created but here's my code could someone please tell me the changes i have to make
Private Sub mnusave_Click(Index As Integer)
str(0) = txtZoon.Text
str(1) = txtDochter.Text
str(2) = txtVader1.Text
CMDialog1.ShowSave
CMDialog1.FileName = txtringnummer.Text
If CMDialog1.CancelError Then End Sub
Open App.Path & "\words.txt" For Output As #1
'Then save the strings to the file:
Write #1, str(0), str(1), str(2)
Close #1
End Sub
Private Sub mnuOpen_Click(Index As Integer)
'Clear the textboxes:
txtZoon.Text = ""
txtDochter.Text = ""
txtVader1.Text = ""
CMDialog1.ShowOpen
Open App.Path & "\words.txt" For Input As #1
Input #1, str(0), str(1), str(2)
'Then set them to the textboxes
If CMDialog1.CancelError Then End Sub
txtZoon.Text = str(0)
txtDochter.Text = str(1)
txtVader1.Text = str(2)
Close #1
I don't get why your using the common dialog to show the open box, the code you have has nothing to do with the common dialog, your opening something regardless of what you pick in the common-dialog box. if you want to link it to the common dialog you should use code like
with commondialog1
.filter "text files|*.txt"
.showopen
end with
'im sorta new so you have to put your own code in here
'that would split up the text file into your different parts
'probably use the Len command, and assign each different
'part to each text-box
[/end vb code]
sorry if that wasn't what you wanted i tried at least... now can i gutter the thread since i took my time to post in it??
can anyone help me i need to save multiple text boxes to 1 file and i want to use an dialogbox or something else so the user can decide where to save the file my code is posted above but in that state their is no file created this is going for a week now will someone please come up with some answers??????
here is a sample i made that does what you want... i think
the design is very crude, but i just made it in like 10 mins just to see if i could do it
Same here.
CommonDialog Open SaveAs, TextBoxes, Everything.
Except Comments.
Ask if its Hazy.
-Lou
Skitchen8,
Great Variable name, the value you assign to text4.text!
Pretty Funny!
-Just got Posted, See Ya
-Lou
yea... i waz mad at my bro and hes like 3 so thats all i can call him so i used it as the variable name, did you get it to work all right, and do what you wanted??
OK I have been gone, I see you are still stuck on this.
This is a BRIEF explantion on the Common Dialog Box.
(Although I don't see why you need to use it)
Use the save as dialog.
Put a CommonDialog control on the form and use the following code:
code:--------------------------------------------------------------------------------
Private Sub button_Click()
Dim iFileNum As Integer
Dim sFileName As String
With CommonDialog1
.CancelError = True
.DefExt = "txt"
.Filter = "Text files|*.txt|All files|*.*"
'the above properties can be set during design time
.Flags = cdlOFNPathMustExist + cldOFNHideReadOnly + cdlOFNOverwritePrompt
On Error Resume Next
.ShowSave
If Err = cdlCancel Then
'the user click on the cancel button so bail out
Exit Sub
End If
sFileName = .Filename
End With
iFileNum = FreeFile
Open sFileName For Output As iFileNum
Print #iFileNum, form.textbox.Text
Close iFileNum
basic.Text = form.textbox.Text
End Sub
Now, before you go and plug this code into your module, it will not work. I did not use your naming conventions. You will need to set the Filters and Flags yourself. I don't see why you need this, because your application saves to a specific file. Unless you want to save multiple files (in which a database may be in order). Read up on the Flags and Filters for the common dialog box. As your code stands now it will open and read the file, it will erase and re write the file, then pull it's data into the GUI.
I think that we did just fine doing our codes, so stop bein a little butthole!! LOL
finally it works thnx allot you guys if i could ever do something in return just ask
It was no problem, im happy that you posted this, because i basically taught myself how to do that only because i had to so thank you
don't tell that to parksie... he'lll want you to bend over and pick up the soap :D
NoProb,
I think we all like to help when we can.
-Lou
Who ya callin a butthole?
lol
I get a syntax error at the End Sub. Any Ideas?Quote:
Originally posted by Robke
If CMDialog1.CancelError Then End Sub
[My Code:]
Private Sub mnuOpen_Click(Index As Integer)
CommonDialog1.ShowOpen
If CommonDialog1.CancelError Then End Sub
Open openpath For Input As #1
stext = Input(LOF(1), 1)
Close #1
RichTextBox1.Text = stext
End Sub
[End My Code.]
Any ideas?
End Sub should be used at the bottom of a procedure only.
Exit Sub can be used everywhere else to conditionally
break out of a sub.
-Lou
Thanks a lot.