dcsimg
Results 1 to 6 of 6

Thread: [RESOLVED] Why does this code unload my whole project?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2013
    Location
    Albania
    Posts
    101

    Resolved [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:
    Code:
    form2.show
    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.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Feb 2013
    Location
    Albania
    Posts
    101

    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.

  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,441

    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2013
    Location
    Albania
    Posts
    101

    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?

  5. #5
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    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

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2013
    Location
    Albania
    Posts
    101

    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
  •  



Featured


Click Here to Expand Forum to Full Width