Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Ok - please forgive me for this dumb question, but I need help with some basic VB.Net sytax.

 

I want to make use of the combo box .contains method. The method uses "value as object" as it's input. I have a string variable that I want to pass into the method so I can see if my string is contained within the combo box. However, the method keeps generating the "Object reference not set to an instance of an object".

 

How can I reference the string variable correctly? I've tried creating a new object and setting it equal to the string - but I know there is just something stupid I'm missing with my sytax. :mad:

 

-Falcon

Posted

Sure

 

This is a quick example of what will cause the problem - though slightly diferrent than what I was explaining above. The problem I'm having is simply how to get a string referenced correctly so it can be put into a function that requires an 'Object' as input?

 

       Dim cmbExample As ComboBox

       cmbExample.Items.Add("Test")

 

-Falcon

Posted

the problem is not with the string. If this is how you're doing it then you're only creating a reference to a combobox, you need to initialize it

 

Dim cmbExample As ComboBox

cmbExample=New ComboBox()

cmbExample.Items.Add("Test")

Proudly a Palestinian

Microsoft ASP.NET MVP

My Blog: wessamzeidan.net

Posted

Yeah - you're right. I actually figured out my problem too. I was using 2 different forms and forgot to make the constructor between the forms... so every time I tried to access a variable on the original form it threw the error about object referencing.

 

So - my problem is fixed! Thanks!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...