6 Replies - 8860 Views - Last Post: 03 October 2007 - 02:11 PM Rate Topic: -----

#1 hironakamura   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 20-September 07

Password protect to open up 2nd form

Post icon  Posted 03 October 2007 - 10:43 AM

I've been trying all night to get a password protect for opening up a second form, i got it first try without anyhelp on vb6 but for some reason the code doesn't work on vb.net
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		If TextBox1.Text = "12345" Then
			Form2.Show()
		End If


	End Sub
End Class


it is underlining form2.show() and saying that Reference to a non-shared member requires an object reference.

i have both forms there a textbox and a button too exactly the way i had on vb6

Is This A Good Question/Topic? 0
  • +

Replies To: Password protect to open up 2nd form

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5485
  • View blog
  • Posts: 14,450
  • Joined: 18-April 07

Re: Password protect to open up 2nd form

Posted 03 October 2007 - 11:28 AM

Do you have an instance of form2 created before you call show? Try something along the lines of...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		If TextBox1.Text = "12345" Then
			Dim myform as new Form2
			myform.Show()
		End If
End Sub



Remember that everything in .NET is object based so you have create new instances of objects before you can use their methods.
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1660
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Password protect to open up 2nd form

Posted 03 October 2007 - 11:28 AM

Do it this way

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim f2 As New Form2
		If TextBox1.Text = "12345" Then
			f2.Show()
		End If
	End Sub



Hope this helps :)
Was This Post Helpful? 1
  • +
  • -

#4 hironakamura   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 20-September 07

Re: Password protect to open up 2nd form

Posted 03 October 2007 - 11:36 AM

ok thansk for the help
Was This Post Helpful? 0
  • +
  • -

#5 hironakamura   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 20-September 07

Re: Password protect to open up 2nd form

Posted 03 October 2007 - 01:22 PM

It worked perfect, but one more question, how can i get a message box up if the incorrect password is inputed
Was This Post Helpful? 0
  • +
  • -

#6 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Password protect to open up 2nd form

Posted 03 October 2007 - 01:27 PM

Well then you will need an Else portion to your IF statement. You might want to check out this link on how to use conditional statements in VB.NET.

Like this:
		If TextBox1.Text = "12345" Then
			f2.Show()
		Else
			MessageBox.Show("Your message here")
		End If

Was This Post Helpful? 0
  • +
  • -

#7 hironakamura   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 20-September 07

Re: Password protect to open up 2nd form

Posted 03 October 2007 - 02:11 PM

thaks again for the help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1