# Object reference error or something... :S

## Recommended Posts

I am programming in VB.NET 2005 and I have a form, frmLogin with a progress bar, pbLogin. I also have a module. I have made a subroutine called OnConnected in the module which is called when the user clicks the Login button on frmLogin. Public Sub OnConnected() frmLogin.pbLogin.Value = 100 frmLogin.lblProgress.Text = "Login successful!" frmLogin.Hide() End Sub() The problem is it errors on the first line, saying "Object reference not set to an instance of an object." Why is this? How come I can't access the form from the module?

##### Share on other sites
I've barely touched VB.Net myself, but what you're doing looks like something you can only do in VB6 and earlier. If I remember correctly (doubtful), in VB.Net frmLogin does not refer to an actual form, but to the class of the form. To refer to the form which is actually showing, you have to have an instance of frmLogin to manipulate. Unfortunately as I said I don't know much of VB.Net so I can't offer you any better suggestions than that, but hopefully that will get you started.

##### Share on other sites
I'm not very familiar with VB.NET, but after glancing at some documentation, it looks like you should be able to still use the Me keyword more or less just like you did in VB6.
Public Sub OnConnected()  Me.pbLogin.Value = 100  Me.lblProgress.Text = "Login successful!"  Me.Hide()End Sub

##### Share on other sites
Me should indeed work, but not if the OnConnected() sub is in a module separate from the form code - I think?

##### Share on other sites
Quote:
 Original post by ApochPiQMe should indeed work, but not if the OnConnected() sub is in a module separate from the form code - I think?
It would indeed help if I read the question more thoroughly. *smacks head and apologizes*

##### Share on other sites
Yeh it does. Thanks. Now all I need to figure out is how to create an instance? Anyone know?

##### Share on other sites
Hi :)

well i dont know if this post is late .. but i will share the information that i have regarding this issue.. now lets refer to the code you wrote

Public Sub OnConnected()
End Sub()

my guess would be that it would crash on the frmLogin.Hide() with
"Object reference not set to an instance of an object"

how to solve it...

2 ways

first way:

Public Sub OnConnected()
End Sub()

second way:
Public Sub OnConnected(frmIn as Form)
frmIn.Hide()
End Sub()

Please Note that i didnt test this code coz i really dont have alot of time i need to go back to work :).
please inform me of any errors or mistakes take care .

##### Share on other sites
Greetings,
the first one should be
Public Sub OnConnected()    Dim LoginForm as New frmLogin    LoginForm.pbLogin.Value = 100    LoginForm.lblProgress.Text = "Login successful!"    LoginForm.Hide()End Sub()

or
Public Sub OnConnected()    Dim LoginForm as frmLogin    Loginform = New frmLogin()    LoginForm.pbLogin.Value = 100    LoginForm.lblProgress.Text = "Login successful!"    LoginForm.Hide()End Sub()

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628365
• Total Posts
2982273

• 10
• 9
• 13
• 24
• 11