|
-
Mar 7th, 2010, 07:34 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] VB6 - Paintpicture...
Hello. Since a few week, I have been trying to make a small software using Visual Basic 6.0. I got stucked in one process that is EDIT DETAILS. This is the name of the form which is used to store information about the user. Everything is set except a picture. Picture path last selected is save in the file config.dat. And when the form is loaded, with the path I want to load the picture in the picturebox. At the same time I'm using paintpicture to stretch the image to fit the picturebox. But the problem occurs doing so. I've two picturebox one hidden. First picture is loaded in second picturebox that is hidden and it as the source, is transferred to main visible picturebox. When I browse the picture it shows well but when I load next time, no picture is seen. below is the coding. If you could find the bug and help me debug it, I would be grateful. Please add more necessary codes if needed.
Code:
Private Sub Apply_Click()
Open "msconfig.dat" For Output As #1
Write #1, picPath
If FName.ForeColor = &H80000002 Then
Write #1, ""
Else
Write #1, FName
End If
If LName.ForeColor = &H80000002 Then
Write #1, ""
Else
Write #1, LName
End If
Write #1, Month.ListIndex
Write #1, Day.ListIndex
If year.ForeColor = &H80000002 Then
Write #1, ""
Else
Write #1, year
End If
Write #1, Occupation.ListIndex
Write #1, Country.ListIndex
If Email.ForeColor = &H80000002 Then
Write #1, ""
Else
Write #1, Email
End If
If URL.ForeColor = &H80000002 Then
Write #1, ""
Else
Write #1, URL
End If
Close #1
Apply.Enabled = False ' Disables apply
End Sub
Private Sub cmdbrowse_Click()
On Error GoTo fixbug
OpenD.CancelError = True
OpenD.Filter = "Image Files (JPG,JPEG,BMP,GIF,PNG)|*.jpg;*.jpeg;*.bmp;*.gif;*.png"
OpenD.InitDir = App.Path
OpenD.ShowOpen
picPath.Text = OpenD.FileName
frmDetails.SetFocus
PictureBox.Picture = LoadPicture()
Picture1.Picture = LoadPicture(OpenD.FileName)
PictureBox.PaintPicture Picture1.Picture, 0, 0, 1440, 1440
Exit Sub
fixbug:
End Sub
Private Sub Cancel_Click()
Form2.Show
Unload Me
End Sub
<BR><BR>
Private Sub Email_GotFocus()
If Not Email.ForeColor = &H80000001 Then
Email.Text = ""
Email.ForeColor = &H80000001
Else
Email.SelStart = 0
Email.SelLength = Len(Email)
End If
End Sub
COLOR="Blue"]Private Sub[/COLOR] Email_LostFocus()
If Email = "" Then
Email.Text = "Email Address"
Email.ForeColor = &H80000002
End If
End Sub
Private Sub FName_GotFocus()
If Not FName.ForeColor = &H80000001 Then
FName.Text = ""
FName.ForeColor = &H80000001
Else
FName.SelStart = 0
FName.SelLength = Len(FName)
End If
End Sub
Private Sub FName_LostFocus()
If FName = "" Then
FName.Text = "First Name"
FName.ForeColor = &H80000002
End If
End Sub
Private Sub Form_Load()
Form2.Hide 'Hides the main form and open frmEdit.
On Error GoTo fixErr
Open "msconfig.dat" For Input As #1
Static path1 As String
Input #1, path1
Static name1 As String
Input #1, name1
Static name2 As String
Input #1, name2
Static month1 As Integer
Input #1, month1
Static day1 As Integer
Input #1, day1
Static year1 As String
Input #1, year1
Static occupation1 As Integer
Input #1, occupation1
Static country1 As Integer
Input #1, country1
Static email1 As String
Input #1, email1
Static WebURL As String
Input #1, WebURL
Close #1
Timer1.Enabled = True
If path1 = "" Then
picPath.Text = ""
PictureBox.Picture = LoadPicture(App.Path & "\noimg.jpg")
Else
picPath.Text = path1
PictureBox.Picture = LoadPicture()
Picture1.Picture = LoadPicture(path1)
End If
If name1 = "" Then
FName.ForeColor = &H80000002
FName.Text = "First Name"
Else
FName.ForeColor = &H80000001
FName.Text = name1
End If
If name2 = "" Then
LName.ForeColor = &H80000002
LName.Text = "Last Name"
Else
LName.ForeColor = &H80000001
LName.Text = name2
End If
Month.ListIndex = month1
Day.ListIndex = day1
If year1 = 0 Then
year.ForeColor = &H80000002
year.Text = "Year"
Else
year.ForeColor = &H80000001
year.Text = Val(year1)
End If
Occupation.ListIndex = occupation1
Country.ListIndex = country1
If email1 = "" Then
Email.ForeColor = &H80000002
Email.Text = "E-mail"
Else
Email.ForeColor = &H80000001
Email.Text = email1
End If
If WebURL = "" Then
URL.ForeColor = &H80000002
URL.Text = "Uniform Resource Locator (URL)"
Else
URL.ForeColor = &H80000001
URL.Text = WebURL
End If
Exit Sub
fixErr:
End Sub
Private Sub Form_Unload(Cancel As Integer)
Form2.Show
End Sub
Private Sub LName_GotFocus()
If Not LName.ForeColor = &H80000001 Then
LName.Text = ""
LName.ForeColor = &H80000001
Else
LName.SelStart = 0
LName.SelLength = Len(LName)
End If
End Sub
Private Sub LName_LostFocus()
If LName = "" Then
LName.Text = "Last Name"
LName.ForeColor = &H80000002
End If
End Sub
Private Sub Text1_Change()
Text1.text = ""
PictureBox.SetFocus
End Sub
Private Sub Text1_GotFocus()
Call cmdbrowse_Click
End Sub
Private Sub OK_Click()
If Apply.Enabled = True Then
Call Apply_Click
Form2.Show
Unload Me
ElseIf Apply.Enabled = False Then
Form2.Show
Unload Me
End If
End Sub
Private Sub Timer1_Timer()
Label8.Caption = "1"
End Sub
Private Sub picPath_GotFocus()
Call cmdbrowse_Click
End Sub
Last edited by rajbdilip; Mar 7th, 2010 at 08:13 AM.
-
Mar 7th, 2010, 07:43 AM
#2
Re: VB6 - Paintpicture...
Hey,
Given that this question is specifically related to VB6, I have asked a moderator to move this thread to the appropriate forum.
Gary
-
Mar 7th, 2010, 08:27 AM
#3
Re: VB6 - Paintpicture...
Thread moved from the 'VB.Net' (VB2002 and later) forum to the 'VB6 and Earlier' forum
(thanks for letting us know Gary )
-
Mar 7th, 2010, 11:53 AM
#4
Re: VB6 - Paintpicture...
I see 2 potential issues.
1. You should always provide the full path to your config file. Not providing a path tells vb to use the current path on your drive and it may not be the path where the config file is at. In those cases, you are reading/writing the file to potentially different paths. Without specifing the fully path, you have no control where the file will be read/written.
2. When you load the picture in Form_Load, I don't see that you are using PaintPicture in the Form_Load event. If you do load the image into Picture1, PictureBox isn't painting the image. Also, you should set PictureBox's AutoRedraw to True, otherwise, when you do paint the picture in form_load, it will be erased when the form is refreshed/made visible the first time.
-
Mar 9th, 2010, 09:01 AM
#5
Thread Starter
Hyperactive Member
Re: VB6 - Paintpicture...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|