How do you open a form WITHIN another?

Discussion in 'Code Snippets and Tutorials' started by Smelly, Mar 11, 2007.

  1. Smelly

    Smelly Level IV

    Joined:
    Dec 1, 2006
    Messages:
    2,197
    Likes Received:
    8
    Location:
    England
    so the code;

    "Dim SecondForm As New form2

    SecondForm.Show()"

    Will open form2 in a new window.

    what statement do i use if i want to open it within the preexisting window of form1?
     
  2. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    If I got what you meant... I dunno how to do that!!! I'd say it's impossible!!! Did you try searching on Go_Ogle?
     
  3. Smelly

    Smelly Level IV

    Joined:
    Dec 1, 2006
    Messages:
    2,197
    Likes Received:
    8
    Location:
    England
    yeah ive been googling for about an hour now.

    maybe its not possible.

    what i mean, is like a web link, will open the next page where the page was before.

    I guess I could just use the close window function. which is probably easier :p


    another thing, how do you link a question box to open a form?

    i can get a button to do it, easy enough, but for example when it pops up with

    "yes" and "no", can i get the yes to link to another form? closing the form already open?

    hope that makes sense
     
  4. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    Yes, sure. Messageboxes return values depending on the button which is pushed. Values:
    OK = 1
    Cancel = 2
    Terminate = 3
    Retry = 4
    Skip(Ignore) = 5
    Yes = 6
    No = 7

    So, use this code:
    Code (Text):
    1. Dim intYesNo as Integer
    2. intYesNo = MsgBox("Do you want to open the next form?", vbYesNo)
    3. If intYesNo = 6 Then 'If Yes(6) button is pressed, it executes this code
    4. frmExample.Show
    5. Else
    6. End 'this will end the program, change it to whatever you want
    7. End If
     
  5. Smelly

    Smelly Level IV

    Joined:
    Dec 1, 2006
    Messages:
    2,197
    Likes Received:
    8
    Location:
    England
    awesome. that fitted in nicely. thanks

    and another thing,

    how do you compile to exe? :D
     
  6. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    File > Make File.exe
    (I dunno if it's make or create, I have the Italian version)
     
  7. Smelly

    Smelly Level IV

    Joined:
    Dec 1, 2006
    Messages:
    2,197
    Likes Received:
    8
    Location:
    England
    ok i have another problem

    Code (Text):
    1.  
    2.  
    3. Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
    4.         Dim submit As Integer
    5.         TextBox1.Text = submit
    6.         Dim wrong As New main
    7.         Dim correct As New Success
    8.         If submit < 94000 Or submit > 99000 Then
    9.             wrong.Show()
    10.         Else
    11.             correct.Show()
    12.         End If
    13.        
    14.    End Sub
    15.  
    now theoretically when you enter a value less than 94000, or greater than 99000 in the text box and click the picture it should go to "main" and when the value in the text box is between those two (e.g 96000) it should go to "success"

    now, i'm not sure how to get the "if something is less than a given value"
    because the less than sign (<) doesn't give the procedure i'm looking for.

    and ideas on what it may be?
     
  8. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    Is submit an integer or a string? If it is a string, use the
    Code (Text):
    1. Int(*here the string*)
    code. It converts a string to a numeric value.
     
  9. Smelly

    Smelly Level IV

    Joined:
    Dec 1, 2006
    Messages:
    2,197
    Likes Received:
    8
    Location:
    England
    doesnt

    Code (Text):
    1. Dim submit as integer
    doesnt that make sure "submit" is an integer?

    thats not the problem. its the case of directing the button to another form depending on what is entered into the box
     
  10. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    Then the code you posted should work. If you aren't sure if it works, just use a label to check the value of the submit variable. You will see if the code works properly.