![]() |
Tipp 0174
|
TextBox-Inhalt speichern und einlesen
|
 |
|
Autor/Einsender: Datum: |
|
Detlev Schubert 13.12.2001/10.05.2003 |
|
Entwicklungsumgebung: |
|
VB 6 |
|
|
Mit Hilfe dieses Tipps ist es möglich, sowohl eine eine einzeilige als auch eine MultiLine-TextBox in einer normalen Textdatei zu speichern, und diese Datei dann auch wieder einzulesen. Daten, die mit der Write #-Anweisung geschrieben worden sind, werden normalerweise, wie auch in diesem Beispiel, mit der Input #-Anweisung aus einer Datei gelesen.
|
|
|
Option Explicit
Private m_strFileName As String
Private Sub Form_Load()
Dim strAppPath As String
strAppPath = ApplicationPath
m_strFileName = strAppPath & "Beispiel.txt"
Text1.Text = "Dies ist ein Mustertext, der gespeichert und " & _
"auch wieder eingelesen werden kann." & vbCrLf & vbCrLf & _
"Euer VB-Fun.de-Team."
End Sub
Private Sub cmdOpen_Click()
Dim FN As Integer
Dim strText As String
On Error GoTo err_Log
FN = FreeFile()
Open m_strFileName For Input As #FN
strText = Input(LOF(FN), 1)
Close #FN
Text1.Text = Mid$(strText, 2, Len(strText) - 4)
Exit Sub
err_Log:
MsgBox "Die Datei " & m_strFileName & " wurde nicht gefunden !"
End Sub
Private Sub cmdSave_Click()
Dim FN As Integer
FN = FreeFile()
Open m_strFileName For Output As #FN
Write #FN, Text1.Text
Close #FN
End Sub
Private Function ApplicationPath() As String
Dim strPath As String
strPath = App.Path
If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
ApplicationPath = strPath
End Function
|
|
|
|
|
Windows-Version |
95 |
 |
|
98/SE |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
VB-Version |
VBA 5 |
 |
|
VBA 6 |
 |
|
VB 4/16 |
 |
|
VB 4/32 |
 |
|
VB 5 |
 |
|
VB 6 |
 |
|
|
|
Download (3,1 kB)
|
Downloads bisher: [ 2572 ]
|
|
|