943,772 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 2007
  • VB.NET RSS
Dec 31st, 2008
0

How do I declare a single Object instance then reuse it in each ComboBox?

Expand Post »
All these New Object()s are identical (and in fact, much longer!) How do I declare a single instance then reuse it in each ComboBox .Items.AddRange()? I am using Visual Studio 2008/Visual Basic.

VB.NET Syntax (Toggle Plain Text)
  1. verticalBarComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})
  2. backSlashComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})
  3. colonComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})
  4. quoteComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})

Thanks!
Reputation Points: 18
Solved Threads: 2
Light Poster
edgar5 is offline Offline
30 posts
since Dec 2008
Jan 1st, 2009
0

Re: How do I declare a single Object instance then reuse it in each ComboBox?

declare simply array from object datatype then call AddRange for all combo boxes and pass this array!
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jan 1st, 2009
0

Re: How do I declare a single Object instance then reuse it in each ComboBox?

As RamyMahrous said use an array. If you deceide to add or remove anything later you only need to do it in one place.
VB.NET Syntax (Toggle Plain Text)
  1. Dim ary As String() = {" single space", "- hyphen", " - <single space>hyphen<single space>", "` open single quote", "=", "~", "!"}
  2.  
  3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4. verticalBarComboBox.Items.AddRange(ary)
  5. backSlashComboBox.Items.AddRange(ary)
  6. colonComboBox.Items.AddRange(ary)
  7. quoteComboBox.Items.AddRange(ary)
  8. End Sub
Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002
Jan 1st, 2009
0

Re: How do I declare a single Object instance then reuse it in each ComboBox?

Thanks to both!

As this is my first VB project, I needed the code snippet.
Reputation Points: 18
Solved Threads: 2
Light Poster
edgar5 is offline Offline
30 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Does this leak memory?
Next Thread in VB.NET Forum Timeline: Save password...plz help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC