10 Replies - 1660 Views - Last Post: 22 February 2011 - 01:06 PM Rate Topic: -----

#1 myhaksown   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 07-January 09

Trying to pull up another form

Posted 22 February 2011 - 11:03 AM

I am trying to call up different forms based on a basic login screen (thats fine) the part that is not working is that when I put in any information it should pull up one of 2 screens but neither will come up. Any help below is my code so far. (using professional 2010)
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login.Click
        If TextBox1.Text = "test" And TextBox2.Text = "test" Then
            Show(form2)
        Else
            Show(Form3)
        End If
    End Sub
End Class


thats my login button and I have 3 forms the one this is on the one that pops up when incorrect information is put in and the one that pops up with the correct information only.

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to pull up another form

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15329
  • View blog
  • Posts: 61,444
  • Joined: 12-June 08

Re: Trying to pull up another form

Posted 22 February 2011 - 11:25 AM

How are you declaring your objects form2 and Form3?

You should have code that looks like this:

dim form2 as new <name of your form 2 class>
dim form3 as new <name of your form 3 class>

form2.show
...
form3.show

Was This Post Helpful? 1
  • +
  • -

#3 myhaksown   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 07-January 09

Re: Trying to pull up another form

Posted 22 February 2011 - 11:35 AM

View Postmodi123_1, on 22 February 2011 - 11:25 AM, said:

How are you declaring your objects form2 and Form3?

You should have code that looks like this:

dim form2 as new <name of your form 2 class>
dim form3 as new <name of your form 3 class>

form2.show
...
form3.show


I haven't done anything like that. I used to use 2008 Express but I got 2010 pro for free and I don't recall ever having to declare any of my forms in 2008.
Was This Post Helpful? 0
  • +
  • -

#4 bedrockhorror   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 56
  • Joined: 22-October 09

Re: Trying to pull up another form

Posted 22 February 2011 - 11:35 AM

try this, and see if it helps.

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login.Click
2	        If TextBox1.Text = "test" And TextBox2.Text = "test" Then
3	           form2.show
4	        Else
5	           form3.show
6	        End If
7	    End Sub
8	End Class



This post has been edited by bedrockhorror: 22 February 2011 - 11:36 AM

Was This Post Helpful? 1
  • +
  • -

#5 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15329
  • View blog
  • Posts: 61,444
  • Joined: 12-June 08

Re: Trying to pull up another form

Posted 22 February 2011 - 11:43 AM

Odd... well maybe I am down and out with the object orientated mindset but for me if you have objects you explicitly declare them, initialize them, and then use their methods. If you need information from that state of the object or want to pass information to the object it helps having them declared.

bedrockhorror option works as well.
Was This Post Helpful? 0
  • +
  • -

#6 myhaksown   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 07-January 09

Re: Trying to pull up another form

Posted 22 February 2011 - 11:52 AM

bedrockhorror your method works on 2008 however when trying it in 2010 I get

Quote

Error 2 Reference to a non-shared member requires an object reference.

modi123_1 I think you are right with the you need to initialize them but the problem is how do I initialize them? would this happen to be the way to do that?
Dim Form2 As Windows.Forms.IWin32Window


Just tryed that and it gives me an error still any other ideas?

This post has been edited by myhaksown: 22 February 2011 - 11:54 AM

Was This Post Helpful? 0
  • +
  • -

#7 myhaksown   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 07-January 09

Re: Trying to pull up another form

Posted 22 February 2011 - 12:00 PM

I also found that I can do this-
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent(form2)

        ' Add any initialization after the InitializeComponent() call.

    End Sub
    Private Sub InitializeComponent(ByVal Form2 As Windows.Forms.IWin32Window)
        Throw New NotImplementedException
    End Sub


however where it says not implemented exception it wont load any farther. and at the top at Public Sub New () the () give me a warning

Quote

Warning 1 'Public Sub New()' in designer-generated type 'Project1.Form1' should call InitializeComponent method.

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15329
  • View blog
  • Posts: 61,444
  • Joined: 12-June 08

Re: Trying to pull up another form

Posted 22 February 2011 - 12:05 PM

Yeah, don't screw with the InitializeComponent.

Stop thrashing around and think about for a minute.

In your project what are you form names? The name of the classes for form2 and form3?

How do you declare any other object?

dim <variable name> = new <class name>
Was This Post Helpful? 0
  • +
  • -

#9 myhaksown   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 07-January 09

Re: Trying to pull up another form

Posted 22 February 2011 - 12:35 PM

forms so far-
loginform (form1)
form2 (form2)
error0 (form3)

Dim Error0 As Windows.Forms.IWin32Window


that looks almost exactly like what you said to use however by what you say would I use-
dim Error0 = new form3
also I messed around with it a bit and got an error that says I must set its visibility to false before I can show it. How do I do that? I cant do hide(form2) because I get errors, and I cant find it on the properties menu.

This post has been edited by myhaksown: 22 February 2011 - 12:35 PM

Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15329
  • View blog
  • Posts: 61,444
  • Joined: 12-June 08

Re: Trying to pull up another form

Posted 22 February 2011 - 12:48 PM

No.. you are not reading this right:
dim <variable name> = new <class name>

What are your class names? I am guessing: loginform, form2, error0. Right?

If you are to use the format: dim <variable name> = new <class name>

it would look something like this:
dim <variable name1> = new loginform
dim <variable name2> = new form2
dim <variable name3> = new error0



Since you are still flailing around I'll tell you now - you would supply your own variable name between the <...> for each of those.

Then to show them use the show method.

<variable name1>.show
....

Was This Post Helpful? 1
  • +
  • -

#11 myhaksown   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 07-January 09

Re: Trying to pull up another form

Posted 22 February 2011 - 01:06 PM

I have never used anything like that with vb and it has been some time sense I last used it. But thanks for the help now I know what to do and how to show things now. Thank You!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1