×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

form Load (probably just a dumb mistake)

form Load (probably just a dumb mistake)

form Load (probably just a dumb mistake)

(OP)
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?

RE: form Load (probably just a dumb mistake)

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources