Sign in to follow this  
Kryptus

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by ApochPiQ
Me 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 this post


Link to post
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()
frmLogin.pbLogin.Value = 100
frmLogin.lblProgress.Text = "Login successful!"
frmLogin.Hide()
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()
Dim LoginForm as frmLogin
LoginForm.pbLogin.Value = 100
LoginForm.lblProgress.Text = "Login successful!"
LoginForm.Hide()
End Sub()

second way:
Public Sub OnConnected(frmIn as Form)
frmIn.pbLogin.Value = 100
frmIn.lblProgress.Text = "Login successful!"
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 this post


Link to post
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()

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this