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.

verticalBarComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " -  <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})
 backSlashComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " -  <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})
 colonComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " -  <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})
 quoteComboBox.Items.AddRange(New Object() {" single space", "- hyphen", " -  <single space>hyphen<single space>", "` open single quote", "=", "~", "!"})

Thanks!

declare simply array from object datatype then call AddRange for all combo boxes and pass this array!

As RamyMahrous said use an array. If you deceide to add or remove anything later you only need to do it in one place.

Dim ary As String() = {" single space", "- hyphen", " -  <single space>hyphen<single space>", "` open single quote", "=", "~", "!"}

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        verticalBarComboBox.Items.AddRange(ary)
        backSlashComboBox.Items.AddRange(ary)
        colonComboBox.Items.AddRange(ary)
        quoteComboBox.Items.AddRange(ary)
    End Sub

Thanks to both!

As this is my first VB project, I needed the code snippet.

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.