hi all pros,

below is my vb6.0 code. the click command is to save my text and picture. there is no problem for my text.
but, i have a problem after saving the picture. the picture can be saved but it is not availabe for preview.
is there any fix for this ?

Private Sub Command2_Click()
Dim namefile
namefile = Text2 + Text3
Open App.Path & ("/" + namefile + ".txt") For Output As #1
Print #1, Label5.Caption + Text3.Text & vbNewLine; Label6.Caption + Text4.Text & vbNewLine; Label7.Caption + Text5.Text & vbNewLine; Label8.Caption + Text6.Text & vbNewLine; Label9.Caption + Text7.Text & vbNewLine; Label10.Caption + Text8.Text & vbNewLine; Label11.Caption + Text9.Text & vbNewLine; Label12.Caption + Text10.Text & vbNewLine; Label13.Caption + Text11.Text & vbNewLine; Label14.Caption + Text12.Text & vbNewLine; Label15.Caption + Text13.Text & vbNewLine;
Close #1

Dim namefile2
namefile = Text2 + Text3
Open App.Path & ("/" + namefile + ".bmp") For Output As #2
Print #2, Picture1; PictureBox
Close #2
End Sub

please assist! thakns alot!

Dani AI

Generated

Opening a file For Output and using Print writes plain text, not the binary bytes a bitmap viewer expects. That is why a .bmp created with Print cannot be previewed. In VB6 you should persist the PictureBox’s image using SavePicture, which writes a valid image file.

Two practical tips often missed in this scenario:

  • Choose the right source: use .Picture to save the image you loaded, or .Image to include anything you drew at runtime. If you draw at runtime, set Picture1.AutoRedraw = True before drawing so .Image contains the final pixels.
  • Build the path safely and concatenate strings with &, not +. Also, use a backslash on Windows and make sure you do not duplicate or omit it.

Example:

' Option Explicit at the top of the module helps catch typos.
Dim base As String, fname As String
base = App.Path
If Right$(base, 1) <> "\" Then base = base & "\"
fname = base & Text2.Text & Text3.Text & ".bmp"

' Save the loaded picture only:
SavePicture Picture1.Picture, fname

' If you drew on Picture1 and want drawings included:
' Picture1.AutoRedraw = True   ' set this before drawing
' SavePicture Picture1.Image, fname

If you need JPEG/PNG output, VB6 cannot write those formats natively; save as BMP or use a library/codec that supports encoding to other formats.

Recommended Answers

All 5 Replies

below is my vb6.0 code. the click command is to save my text and picture. there is no problem for my text. but, i have a problem after saving the picture. the picture can be saved but it is not availabe for preview. is there any fix for this ?

To save picture in PictureBox you should use SavePicture() function :

Dim namefile2
namefile = App.Path & ("/" & Text1 + Text2) & ".bmp"
SavePicture Picture1.Image, namefile
commented: :D +1
commented: - +1
commented: agree +13

variable namefile2 is assigned the nextline namefile

Jx_Man u rocks to the max!!! now i can save my picture from the picture box!!!

thanks everyone that help me !!

You're welcome :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.