Een image opslaan in filetext met hetzelfde naam van de file.

Status
Niet open voor verdere reacties.

satriano17

Gebruiker
Lid geworden
30 sep 2012
Berichten
331
VB6
dag ik heb een klein probleem.
Ik heb een textfile met 2 textboxen + 1 image
Mijn doel:
De file opslaan met naam.
De image opslaan met hetzelfde naam van de file in de default map (DiagnoseArchief)

Is bijna alles gelukt. De file wordt opgeslaan. De image ook.
Enige probleem , de image wordt wel opgeslaan in de default map maar krijgt geen (file) naam. Wordt opgeslaan zonder naam.
Ik denk aan constructiefout

Hier mijn code
Code:
' file load
Private Sub Command1_Click()
On Error Resume Next ' load
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 = ""
  Do Until EOF(1)
    Line Input #1, kFile
    tekst = tekst & kFile & vbCrLf
    
   Line Input #1, kFile
    tekst = testo2 & kFile & vbCrLf
  Loop
  Text1.Text = tekst
  Text2.Text = tekst2
  
  Close #1
  Image1.Picture = LoadPicture(App.Path & "\DiagnoseArchief\" & CommonDialog1.FileName & ".bmp")
End Sub

'save file .txt

Private Sub Command2_Click()
  CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
  On Error Resume Next ' save
Dim Slash As String
'On Error Resume Next
 MkDir App.Path & "\DiagnoseArchief" ' qui ho aggiunto
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
  Close #1
  SavePicture Image1.Picture, (App.Path & "\DiagnoseArchief\" & CommonDialog1.FileName & ".bmp")
  
End Sub
'Hier laad ik een afb in de image
Private Sub Command3_Click()
CommonDialog1.InitDir = "c:\"
CommonDialog1.FileName = ""
CommonDialog1.Filter = "Graphics|*.bmp;*.jpg;*.jpeg"
CommonDialog1.ShowOpen
Image1.Picture = LoadPicture(CommonDialog1.FileName)
End Sub
error zit natuurlijk in
Code:
SavePicture Image1.Picture, (App.Path & "\DiagnoseArchief\" & CommonDialog1.FileName & ".bmp")
 
Laatst bewerkt:
Plaats je project.
Haal tevens dat onzinnige On Error Resume Next eruit.
 
Laatst bewerkt:
ik krijg niet te uploaden de zip bestand
Ik ga nog eens proberen

maar altijd 'mislukt'
 
Laatst bewerkt:
Haal eerst die On Error Resume Next regels eruit.
Dan zie je vanzelf waar het fout gaat.

Wat ik al zei, onzinnig en zit je alleen maar in de weg.
 
de fout zit, raar, il Mkdir?

heb je de bestand gezien?
 
Laatst bewerkt:
Onder andere inderdaad.
Los dat eerst op en dan verder.
 
Ik heb beetje aangepast.

Nu wordt alles goed opgeslaan maar steeds image zonder naam
 

Bijlagen

  • Prova save load 1 immag.zip
    2,3 KB · Weergaven: 21
Laatst bewerkt:
Ik moet nu naar een avondschool. Sorry Edmoor.

Dan zie ik verder.
De enige probleem was en is dat de image wordt opgeslagen zonder naam.
Als een oplossing hebt, zal ik straks kijken. Anders zal ik nog zoeken.
dank u
 
Er zit nog steeds een On Error Resume Next regel in.
Die moeten gewoon weg, allemaal.

De enige probleem was en is dat de image wordt opgeslagen zonder naam.

En dat komt dus omdat je vanwege die On Error Resume Next niet ziet wat er niet goed is.
 
Laatst bewerkt:
Bijna opgelost !!!
Nu wordt de image wel in de juiste map opgeslagen met gelijk file name als de file !

Ik heb nog een (klein) probleem:
De image wordt wel opgeslagen, maar....met extensie txt in plaats van BMP
Code:
Private Sub Command1_Click()
Dim Slash As String
  Dim tekst As String, kFile As String
  CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
  ' MkDir App.Path & "\DiagnoseArchief\" ' qui ho aggiunto
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 = ""
  Do Until EOF(1)
    Line Input #1, kFile
    tekst = tekst & kFile & vbCrLf
    
   Line Input #1, kFile
    tekst2 = tekst2 & kFile & vbCrLf
  Loop
  Text1.Text = tekst
  Text2.Text = tekst2
  
  Close #1
  Image1.Picture = LoadPicture(CommonDialog1.FileName & ".bmp")
  
End Sub
Private Sub Command2_Click()
  CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
  On Error Resume Next ' save
Dim Slash As String
'On Error Resume Next
 MkDir App.Path & "\DiagnosiArchivio" ' qui ho aggiunto
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
  Close #1
  SavePicture Image1.Picture, CommonDialog1.FileName & ".bmp"
  
End Sub
 
Laatst bewerkt:
Dan kan je er in debug mode doorheen gaan om te kijken waar die naam toegewezen wordt.
 
ook zonder debug mode weet ik dat door commondialog wordt toegewezen. Toch raar als ik aangegeven heb dat .BMP moet worden.

Code:
SavePicture Image1.Picture, CommonDialog1.FileName & ".bmp"
ik heb aan Replace gedacht, maar waar?
 
Laatst bewerkt:
Als het tonen van extensies uit staat zal je naam.txt zien terwijl het in werkelijkheid naam.txt.bmp is.
 
Ik weet dat de probleem hier is.
Code:
SavePicture Image1.Picture, CommonDialog1.FileName & ".bmp"
 
Ja, en CommonDialog1.FileName staat dus die .txt achter waar je zelf weer .bmp achter plakt.

Maak er eens dit van:
Code:
SavePicture Image1.Picture, Replace(CommonDialog1.Filename, ".txt", ".bmp")
 
Laatst bewerkt:
Met save geen probleem meer. Met load wel want die zoekt nog steeds naar test.txt.bmp
Ook met load moet ik Replace gebruiken?
 
Als je de .txt in plaats van de .txt kiest moet dat daar uiteraard ook gebeuren.
 
Nattuurlijk gaat niet zo
Code:
image1.picture=LoadPicture , Replace(CommonDialog1.FileName, ".txt", ".bmp")

Ongelooflijk vandaag
Ik krijg di 'txt' niet weg
 
Laatst bewerkt:
Maar heb je dan al gekeken wat er op dat moment in CommonDialog1.FileName staat?
Bijvoorbeeld zo:
Code:
MsgBox CommonDialog1.FileName
image1.picture=LoadPicture , Replace(CommonDialog1.FileName, ".txt", ".bmp")
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan