|
-
Mar 22nd, 2013, 06:01 AM
#1
Thread Starter
Lively Member
[RESOLVED] Why does this code unload my whole project?
There are two forms. The first one(form1) has a command button. When you click it, it calls the second form(form2) using this code:
In form2 there are two picture boxes. The first one(pic1) is visible, the second(pic2) is not. When the mouse hovers pic1:
Code:
Private Sub pic1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
SetCursor LoadCursor(0, IDC_HAND)
End Sub
Code:
Private Sub pic1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
pic1.Visible = True
pic2.Visible = False
unload me
End Sub
Code:
Private Sub pic1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
pic1.Visible = False
pic2.Visible = True
End Sub
This will give the feeling of a hover effect, using two pictures.
But when I test it, the whole project unloads.
Why does this happen? How can it be solve? Thanks.
-
Mar 22nd, 2013, 06:29 AM
#2
Thread Starter
Lively Member
Re: Why does this code unload my whole project?
EDIT:
I also added a textbox to form1 and in the pic1_MouseUp event I added: form1.txt1.text = "hello"
This doesn't work either.
But when I add: msgbox "hi" , it works.
So confused right now!
I also tried some other lines of codes that affect form1 such as form1.refresh and apparently none of them worked. Seems like the problem stays within form1.
Last edited by kevinKZzaka; Mar 22nd, 2013 at 06:36 AM.
-
Mar 22nd, 2013, 07:03 AM
#3
Re: Why does this code unload my whole project?
Try putting in error handling and see if that catches something. Here is an example:
Code:
Private Sub Command_Click()
On Error GoTo ErrorHandler
'logic here
ErrorHandler:
MsgBox "Error Occured: " & Err.Description
End Sub
-
Mar 22nd, 2013, 07:11 AM
#4
Thread Starter
Lively Member
Re: Why does this code unload my whole project?
I think I found the problem. I am working with multiple instances of the same form, using: Dim newFrm as new form1
and when the app runs, it runs a new copy of form1, so newFrm.
And when I use the code in the other form: unload form1 , it doesn't work because form1 has never been loaded, but I actually want to unload a certain instance of form1, for example I would use: unload newFrm, but this will close all forms that are copies of form1. I want to unload only the specific copy of form1, where form2 has been called from. Can you help me with this?
-
Mar 22nd, 2013, 08:04 AM
#5
Banned
Re: Why does this code unload my whole project?
remove
Private Sub pic1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
pic1.Visible = True
pic2.Visible = False
unload me
End Sub
remove unload me lol
-
Mar 22nd, 2013, 06:31 PM
#6
Thread Starter
Lively Member
Re: Why does this code unload my whole project?
I fixed the problem. Thanks everybody for your suggestions and help.
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
|