1

I am using Visual Basic Express 2010 edition. I have a combo box named cboTester, an output combobox called cboOutput and a separate class called 'ListClass'

The cboTester has 3 options, EN, FR and DE.

In the list class I have 3 string arrays;

Public Shared Tester_EN() {"Yes", "No"} Public Shared Tester_FR() {"Maybe", "Kind of"} Public Shared Tester_DE() {"No", "No way"}

Is there a way using vb.net that I can use the input from the cboTester do determine how cboOutput is populated?

I was thinking it would something similar to the answer detailed below. Please note; this is written free-type and not copied and pasted from somewhere I can check it!

private sub cboTester_SelectedIndexChanged()
 if cboTester_SelectedItem = "EN" then
    strTest = "EN"
 else if cboTester_SelectedItem = "FR" then
    strTest = "FR" ...
end if

ArrayName = "ListClass.Tester_" & strTest

cboOutput.items.addrange(ArrayName)

--- EDIT BELOW THE LINE 14/06/2013 2:45AM GMT It seems like I could do with giving a bit more information here.

The reason why I want to do it like this is because I have lots and lots of arrays, which are set up with the description of Arrayname_Lang (eg. Reasons_EN, Reasons_FR, Reasons_DE, House_EN, House_FR,House_DE) So I want to be able to write my load functions as;

cboReasons.Items.AddRange("ListClass.reasons" & language)

rather than having to write each possible variant

Thanks Maudise

1 Answer 1

1

I'd make your three Tester variables a single Dictionary(Of String, String()), with keys "EN", "FR", and "DE":

Public Shared Tester as Dictionary(Of String, String())
...
Tester = new Dictionary(Of String, String())
Tester.Add("EN", {"Yes", "No"});
Tester.Add("FR", {"Maybe", "Kind of"});
Tester.Add("DE", {"No", "No way"});

and then use:

cboOutput.items.addrange(Tester(cboTester_SelectedItem)))

(Sorry for any syntax discrepancies, my VB.NET is a bit rusty)

Sign up to request clarification or add additional context in comments.

3 Comments

Hi,I tried and made a few amendments but it doesn't work. I'm getting NullREferenceException. ` Private Sub cboTester_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboTester.SelectedIndexChanged cboOutput.Items.AddRange(tester(cboTester.SelectedText)) End Sub` Public tester As Dictionary(Of String, String()) tester.Add("EN", {"Yes", "No"}) tester.Add("FR", {"Maybe", "Kind of"}) tester.Add("DE", {"No", "No Way"})
Edited - you need to instantiate the object before you call 'Add'.
Thanks, I've added it to make it "Test_EN" or "Test_FR" and then I've changed the cboOutput.items.addrange(tester("Test_"&cboTester.selectedItem)) and that seems to be working. I should be able to adapt it from here. THANKS! I'll be back if I need any more!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.