The second doesn't work because you are trying to put code ( bob = "hello"; ) outside of a method (we know it's outside of a method because of the 'public' on bob, you can't declare public method variables).
I should work. Take a look at this simple example:
string a; //this will not be initialized, but there will be no error in compile time
string b = "b";
public void MyMethod()
a = "a";
string c; //this will not be initialized, but there will be no error in compile time
string d = "d";
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...