Shared values between forms

rickrod99

New member
Joined
Mar 17, 2007
Messages
3
Programming Experience
5-10
Hi everyone. I am new here. I am actually new to VB. I am proficient in C++, Perl, PHP and Java. I recently started to learn VB because my employer decided that they wanted an application written in VB so down that path I went. I am really starting to like VB but unfortunately I am running into a few stumbling blocks.

I have one form that is instatiated when the main function starts and I have a module which has my other functions in it. I am trying to populate the fields on the original form with the values from the functions in the module. I have declared the variables on the form as "public shared" variables. When I call the variables, for example form1.TboxDisp.text = "xxxx" from the module I get Object reference not set to an instance of an object.

I dont understand this because if my variable is a publicly shared variable and it is seen from one form to the other it should be able to populate the other form with the values.

Any help here would be great.

Thanks
 
I dont understand how you can be proficient in at least two OO languages and hit this as a stumbling block?

making something "shared" is the equivalent of static in java/c++
You dont want to make these "variables" shared!


To allow one object to set another object's attributes you should declare them as properties:

VB.NET:
  private firstNameTextBox as TextBox
  public property FirstName as String
    Get
      return firstNameTextBox.Text
    End Get
    Set
      firstNameTextBox.Text = value
    End Set
  End Property

However, if you consider other established OO practice, we should have one form ask the other, rather than tell the other.

COnsider OpenFIleDialog

You show it, the user picks the file, the form closes, then you interrogate it to see what file was picked.

The OpenFileDialog does not Push the filename to your form


If you want to talk a little more about your design, I can help you with the OO design theory side of it..
 
cjard,
First let me say thank you. Although you almost took offense to the idea that I said I am proficient at the previous languages, I beleive I am. Logic wise I know what I want to do, syntax wise I fall short on VB since I am not familiar with the language. However thanks again and I will take your suggestion into consideration.
 
Oh, I wasnt offended.. I just couldnt understand! :)

When I picked up VBN, I found the following document invaluable:
http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html

You dont specifically mention whether you have experience of C# but its such a close mix of C++ and Java that I think you'll find it quite readable. Some aspects of VB may frustrate you (its not possible to write a for loop in vb like we do in C, without using GoTo statements) but by and large, its nice and easy to get into. One tip I do recommend is to stay away from legacy vb6 compatibilty functions (take away the reference to Microsoft.VisualBasic.dll from your projects), and to turn Option Strict ON..

This will keep you within the .Net core framework, without relying on functions that are VB specific (e.g use Convert.ToInt32(), not CInt(), Use MessageBox.Show(), not MsgBox(). Use string.Substring(), not Mid(string) etc), and you write code that is strictly type-safe at design time..

There's an awful lot of scope for bugs in VB with the default settings, and most professional VBN programmers I know change these settings very soon.
 
Back
Top