Save setting code with VB2010

Hello all

I had this code in VB6 that was working but if i do the same thing with Visual Studio 2010, it does not work:

SaveSetting("MyApp", "Settings", "TexttxtBaseDelabsolution", Form2.txtBaseDelabsolution)

Open in new window


It say NullRefrenceException was unhandled.


What could be the issue.

Thanks again for your help.
LVL 11
Wilder1626Asked:
Who is Participating?
 
GrahamSkanConnect With a Mentor RetiredCommented:
Oops, sorry. I didn't see your last comment.

I had put the code in Form1, and the textbox in Form2. Presumably you had the code in Form2. For some reason, you can no longer refer to the containing form by its name, but you must use the Me object.
0
 
jimswebCommented:
0
 
Wilder1626Author Commented:
I see that this is for VB Net

Is this the same for Visual Basic classic?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
GrahamSkanRetiredCommented:
Try specifying the text property of the text box.

SaveSetting("MyApp", "Settings", "TexttxtBaseDelabsolution", Form2.txtBaseDelabsolution.Text)
0
 
Wilder1626Author Commented:
Hello GrahamSkan

No sorry, even with the .Text, still the same issue.
0
 
Wilder1626Author Commented:
it is saying: System.NullRefrenceException (Variable object or variable of the bloc With not define)

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        SaveSetting("MyApp", "Settings", "TexttxtBaseDelabsolution", Form2.txtBaseDelabsolution.Text)
    End Sub

Open in new window

0
 
Wilder1626Author Commented:
I just found out the error:

This is the good syntax:
 SaveSetting("MyApp", "Settings", "TexttxtBaseDelabsolution", Me.txtBaseDelabsolution.Text)

Open in new window


Thanks for your help again.

Have a good day

0
 
GrahamSkanRetiredCommented:
I have tested that with VB2010 and it works for me. Are you sure that Form2.txtBaseDelabsolution exists?
0
 
Wilder1626Author Commented:
Thanks again for you help.

I will do this from now on.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.