1

Ok so here's the relevant code:

Public Shared compSelect(9) As ComboBox
Public Shared compPercent(9) As TextBox
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Data.LoadComponents("C:/Users/Jon/Documents/Visual Studio 2013/Projects/QuickBlend/QuickBlend/QuickBlend/Resources/databaseText.txt")
    MsgBox("finished loading")
    MainForm.compSelect = {CompSelect1, CompSelect2, CompSelect3, CompSelect4, CompSelect5, CompSelect6, CompSelect7, CompSelect8, CompSelect9, CompSelect10}
    MainForm.compPercent = {CompPercent1, CompPercent2, CompPercent3, CompPercent4, CompPercent5, CompPercent6, CompPercent7, CompPercent8, CompPercent9, CompPercent10}
    For Each box As ComboBox In MainForm.compSelect
        box.DataSource = Data.Components
        box.DisplayMember = "Name"
        For Each comp As String In Data.ComponentNames
            box.Items.Add(comp)
        Next
        MsgBox("looped")
    Next
    MsgBox("finished loop")
End Sub

As you can see, I've placed various MsgBoxes to see exactly whats going on. It never displays the "looped" message box. Can anybody explain to me why it's completely skipping the for loop? Been working on this for a while and got fed up with it. Thanks in advance for the help! =)

4
  • 1
    are you getting any exceptions? Commented Aug 2, 2013 at 18:42
  • put a breakpoint on For Each box... and see if MainForm.compSelect has any items. Commented Aug 2, 2013 at 18:44
  • And check Data.ComponentNames... and compPercent is not used in the sampple code Commented Aug 2, 2013 at 19:00
  • Why are you binding the datasource to the combo AND adding the items to the combo? Commented Aug 2, 2013 at 19:43

2 Answers 2

2

MainForm.compSelect should be Me.compSelect since this is the instance(has been filled with comboboxes) and not just the fully qualified name of the object that has not been filled.

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

2 Comments

Thank you so much. The reason I did MainForm.compSelect is because I, for whatever reason, thought I was calling compSelect from a static context. I have a lot of experience with static and instance variable due to java, but I guess since it's a different language I just got confused. Thanks again!
No worries, each language has it's subtleties.
0

Your problem is that you are setting the datasource for the comboBox, and then trying to add items to it. .NET does not like this, and will just exit the Sub that tries to do this, without warning (unless you have exception handling added in). Your code should be...

Public Shared compSelect(9) As ComboBox
Public Shared compPercent(9) As TextBox
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Data.LoadComponents("C:/Users/Jon/Documents/Visual Studio 2013/Projects/QuickBlend/QuickBlend/QuickBlend/Resources/databaseText.txt")
MsgBox("finished loading")
MainForm.compSelect = {CompSelect1, CompSelect2, CompSelect3, CompSelect4, CompSelect5, CompSelect6, CompSelect7, CompSelect8, CompSelect9, CompSelect10}
MainForm.compPercent = {CompPercent1, CompPercent2, CompPercent3, CompPercent4, CompPercent5, CompPercent6, CompPercent7, CompPercent8, CompPercent9, CompPercent10}
For Each box As ComboBox In MainForm.compSelect
    box.DataSource = Data.Components
    box.DisplayMember = "Name"
    'take this stuff out, it is not needed
    'For Each comp As String In Data.ComponentNames
        'box.Items.Add(comp)
    'Next
    MsgBox("looped")
Next
MsgBox("finished loop")
End Sub

Comments

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.