Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

form Load (probably just a dumb mistake)

Status
Not open for further replies.

fdg

Computer
Mar 23, 2003
1
US
In a program I am writing, I want a form to appear, when you click a button, that shows a different picture depending on what button you push. I currently have the code written:

(form 1)
Private Sub Form_Load()
Open "c:\mun.txt" For Output As #2
Write #2, "0"
Close #2
End Sub

(command button 1, form 1)
Private Sub Command1_Click()
Open "c:\mun.txt" For Output As #2
Write #2, "1"
Close #2
Used.Visible = False
Used2.Visible = True
End Sub

(command button 2, form 1)
Private Sub Command1_Click()
Open "c:\mun.txt" For Output As #2
Write #2, "2"
Close #2
Used.Visible = False
Used2.Visible = True
End Sub

(form 2)
Private Sub Form_Load()
Open "c:\mun.txt" For Input As #2
Input #2, string
Text1.Text = string
If Text1.Text = "1" Then Picture1.Visible = True
If Text1.Text = "2" Then Picture2.Visible = True
If Text1.Text = "3" Then Picture3.Visible = True
If Text1.Text = "4" Then Picture4.Visible = True
If Text1.Text = "5" Then Picture5.Visible = True
If Text1.Text = "6" Then Picture6.Visible = True
If Text1.Text = "7" Then Picture7.Visible = True
If Text1.Text = "8" Then Picture8.Visible = True
If Text1.Text = "9" Then Picture9.Visible = True
If Text1.Text = "10" Then Picture10.Visible = True
If Text1.Text = "11" Then Picture10.Visible = True
Close #2
End Sub

When I do a runtime debug, no matter what button I push on form1, the same picture cames up on form2. Can anyone help me? Can I use the Load sub for this function?
 
Replies continue below

Recommended for you

I've only given your code a quick glance, but if you are trying to change the picture after form 2 loads it will not work. The picture changing logic only appears in the form load event which will only happen once (unless you unload and reload the form). If this is the case you may want to move the picture changing code to its own subroutine such as
{somewhere in form 2 code}
public sub ChangePic(PictureNumber as integer)
select case PictureNumber
.
<add your code here for different pictures>
.

end sub

Now you can add code to form 1's command buttons such as...
[button for picture 1]
call form2.ChangePic 1

I hope this helps you, it should even eliminate the need for writing out a value to a text file just to pass a variable around.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top