Hello!

I'm declaring a line at the top of my code window.

Dim sTemp as String = textbox1.text

I have no idea why. I tried commenting a few things related to the code but none of it makes it work.

Any ideas?

Recommended Answers

All 2 Replies

Member Avatar for Unhnd_Exception

If your code looks like this then

Public Class Form1
   Dim sTemp as String = textbox1.text
End Class

The text box has not been created yet. Move the line into the Constructor or Load Event

Public Class Form1
    Private sTemp As String

    Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        sTemp = TextBox1.Text
    End Sub

End Class

Thanks! Did the trick!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.