satriano17
Gebruiker
- Lid geworden
- 30 sep 2012
- Berichten
- 331
Code:
Sta me toe om een klein programma te tonen
met Save-Load. Ik heb 4 tekst velden en 2 afbeeldingen.
Bij saven krijgen de twee afb zelfde naam van de file.
Ik begrijp niet waarom het soms lijkt te werken, maar
andere keren worden teksten en afbeeldingen tussen de files verkeerd geloadt.
Toch is het een simpel routine. Ik begrijp niet waar de fout zit (als er een fout is)
Waar zit mijn fout, volgens u?
dank u
Private Sub load_Click()
Dim Slash As String
Dim tekst As String, kFile As String
CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
' MkDir App.Path & "\DiagnoseArchief\" '
CommonDialog1.Filter = "Tekst|*.txt"
If Right(App.Path, 1) <> "\" Then Slash = "\"
CommonDialog1.InitDir = App.Path & Slash & "DiagnoseArchief"
CommonDialog1.FileName = App.Path & Slash & "DiagnoseArchief" & "\*.txt"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1
'tekst = ""
tekst2 = ""
tekst8 = ""
tekst9 = ""
tekst10 = ""
Image1.Picture = LoadPicture()
Image2.Picture = LoadPicture()
Do Until EOF(1)
'Line Input #1, kFile
'tekst = tekst & kFile & vbCrLf
Line Input #1, kFile
tekst2 = tekst2 & kFile & vbCrLf
Line Input #1, kFile
tekst8 = tekst8 & kFile & vbCrLf
Line Input #1, kFile
tekst9 = tekst9 & kFile & vbCrLf
Line Input #1, kFile
tekst10 = tekst10 & kFile & vbCrLf
Loop
'Text1.Text = tekst
Text2.Text = tekst2
Text8.Text = tekst8
Text9.Text = tekst9
Text10.Text = tekst10
Close #1
'CommonDialog1.FileName = Replace(CommonDialog1.FileName, ".txt", ".bmp")
'Image1.Picture = LoadPicture(CommonDialog1.FileName & ".bmp")
'CommonDialog1.FileName = Replace(CommonDialog1.FileName, ".txt", "2.bmp")
'Image2.Picture = LoadPicture(CommonDialog1.FileName & ".bmp")
Image1.Picture = LoadPicture(Replace(CommonDialog1.FileName, ".txt", ".bmp"))
Image2.Picture = LoadPicture(Replace(CommonDialog1.FileName, ".txt", "2.bmp"))
End Sub
'save file .txt
Private Sub save_Click()
Dim Slash As String
MkDir App.Path & "\DiagnoseArchief" ' om een folder te maken de eerste keer
On Error Resume Next
CommonDialog1.Filter = "Tekst|*.txt"
If Right(App.Path, 1) <> "\" Then Slash = "\"
CommonDialog1.InitDir = App.Path & Slash & "DiagnoseArchief"
CommonDialog1.FileName = App.Path & Slash & "DiagnoseArchief" & "\*.txt"
CommonDialog1.ShowSave
Open CommonDialog1.FileName For Output As #1
'Print #1, Text1.Text
Print #1, Text2.Text
Print #1, Text8.Text
Print #1, Text9.Text
Print #1, Text10.Text
Close #1
SavePicture Image1.Picture, Replace(CommonDialog1.FileName, ".txt", ".bmp")
SavePicture Image2.Picture, Replace(CommonDialog1.FileName, ".txt", "2.bmp")
End Sub
' om de eerste afb te laden
Private Sub Command1_Click()
CommonDialog1.InitDir = "c:\"
CommonDialog1.FileName = ""
CommonDialog1.Filter = "Graphics|*.bmp;*.jpg;*.jpeg"
CommonDialog1.ShowOpen
Image1.Picture = LoadPicture(CommonDialog1.FileName)
End Sub
' en om de tweede te laden
Private Sub Command2_Click()
CommonDialog1.InitDir = "c:\"
CommonDialog1.FileName = ""
CommonDialog1.Filter = "Graphics|*.bmp;*.jpg;*.jpeg"
CommonDialog1.ShowOpen
Image2.Picture = LoadPicture(CommonDialog1.FileName)
End Sub
Laatst bewerkt: