AuthorMessage
b_w_johan
Regular
Posts: 56

hey, im looking for the most simple way to save a file.
i have this variable(like few 100 lines i guess).
so what i do now is storing this variable to
richtextbox1
then do savelist.savefile ("D:\myfile.xxx")
but the problem now is: its adding all kinds of chars (cause its saving as rtf format) how do i save it as plain textfile ?
prefer to use like this
myvar.savefile (filename)  but this .savefile is only working on rtb1 ..
hope someone can help me with this
greetings b_w_johan
Dark
n00b
Posts: 45

i was lookingaround and founded this :
Code:
Private fso As New FileSystemObject
Private strm As TextStream
Private strName As String
Private Sub Command1_Click()
    With c1
        .Filter = "All Files|*.*"
        .InitDir = App.Path
        .ShowSave
        Text1.Text = .FileName
    End With
End Sub
Private Sub Command2_Click()
    With c1
        .Filter = "All Files|*.*"
        .InitDir = App.Path
        .ShowOpen
        GetSettings .FileName
    End With
End Sub
Private Sub GetSettings(ByVal FileName As String)
    Set strm = fso.OpenTextFile(FileName, ForReading)
    With strm
        Option1.Value = .ReadLine
        Option2.Value = .ReadLine
        Option3.Value = .ReadLine
       
        Check1.Value = .ReadLine
        Check2.Value = .ReadLine
        Check3.Value = .ReadLine
        Check4.Value = .ReadLine
       
        Text2.Text = .ReadLine
       
        Text1.Text = FileName
       
        .Close
    End With
End Sub
Private Sub SaveSettings(ByVal FileName As String)
    Set strm = fso.CreateTextFile(FileName, True)
    With strm
        .WriteLine Option1.Value
        .WriteLine Option2.Value
        .WriteLine Option3.Value
       
        .WriteLine Check1.Value
        .WriteLine Check2.Value
        .WriteLine Check3.Value
        .WriteLine Check4.Value
       
        .WriteLine Text2.Text
       
        .Close
    End With
    MsgBox "The following settings were saved to " & FileName & " : " & vbCrLf & vbCrLf & _
        "Option1.Value = " & Option1.Value & vbCrLf & _
        "Option2.Value = " & Option2.Value & vbCrLf & _
        "Option3.Value = " & Option3.Value & vbCrLf & _
        "Check1.Value = " & Check1.Value & vbCrLf & _
        "Check2.Value = " & Check2.Value & vbCrLf & _
        "Check3.Value = " & Check3.Value & vbCrLf & _
        "Check4.Value = " & Check4.Value & vbCrLf & _
        "Text = " & Text2.Text, vbOKOnly + vbInformation, "Results"
End Sub
Private Sub Command3_Click()
    SaveSettings Text1.Text
End Sub
Private Sub Command4_Click()
    Unload Me
    End
End Sub
Private Sub Form_Load()
    Text1.Text = App.Path & "\Settings.BartNet"
End Sub

hope that this is what u need 
dzadzuks
Ametuar
Posts: 135

The way i would do it:
Code:

if you want to write a file:
dim FF as integer
ff=freefile
open app.path & "\filename.txt" for output as #ff
print #ff, "som text here"  'can be the textbox you want to save
close #ff
if you want to append the text to existing file:
dim FF as integer
ff=freefile
open app.path & "\filename.txt" for append as #ff
print #ff, "som text here"  'can be the textbox you want to save
close #ff
if you want to open the file for loading settings etc:
dim FF As integer
dim CurrentLine as string
ff = freefile
open app.path & "\filename.txt" for input as #ff
input #ff, CurrentLine: SomTextBox.text = CurrentLine 'input the 1st line in SomTextBox
input #ff, CurrentLine: SomTextBox2.text = CurrentLine 'input 2nd line in SomTextBox
'repeat it while you have loaded all needed lines
close #ff
-dzadzuks-

hope there wont be any typing mistakes, wrote it fast.