1 Replies - 1318 Views - Last Post: 21 April 2012 - 06:11 PM Rate Topic: -----

#1 IT_Newbie35   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-April 12

Try/Catch for array using 2 comboboxes

Posted 21 April 2012 - 05:35 PM

I'm working on a college VB project using an 2D array with 2 combo boxes. One combo box selects a size and the other selects a style. I have everything working correctly with calculations except I need each combo box to pop up a message box if the user doesn't make a selection in a combo box. It will pop up for one combo box, but not the other. My question is how do I get the program to pop up a message box for each combo box independently? Should I use Try/Catch or would another method work better? (I'm using VB Studio 2010)

Private Sub CalculateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateToolStripMenuItem.Click
        'Retrieve price of selection.

        'Dim FoundBoolean As Boolean
        Dim SizeIndexInteger As Integer
        Dim StyleIndexInteger As Integer
        Dim ToppingsTotalDecimal As Decimal
        Dim DiscountDecimal As Decimal
        Dim AmountDueDecimal As Decimal
        Dim PizzaDecimal As Decimal
        Dim SalesTaxDecimal As Decimal

            SizeIndexInteger = SizeComboBox.SelectedIndex                                       
            StyleIndexInteger = StyleComboBox.SelectedIndex
            If SizeIndexInteger <> -1 And StyleIndexInteger <> -1 Then
                PizzaTextBox.Text = PizzaArrayDecimal(StyleIndexInteger, SizeIndexInteger).ToString("c")
                PizzaDecimal = PizzaArrayDecimal(StyleIndexInteger, SizeIndexInteger)
            Else
                MessageBox.Show("Select the pizza size.", "Selection Incomplete",
                 MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If



Is This A Good Question/Topic? 0
  • +

Replies To: Try/Catch for array using 2 comboboxes

#2 sela007   User is offline

  • D.I.C Addict

Reputation: 139
  • View blog
  • Posts: 841
  • Joined: 21-December 11

Re: Try/Catch for array using 2 comboboxes

Posted 21 April 2012 - 06:11 PM

If your goal is that user must select both comboboxes ,i think your code is fine. But try with this:
If Not ComboBox1.SelectedItem Is Nothing And Not ComboBox2.SelectedItem Is Nothing Then
'...
End If


You can also do checking with ComboBox.Text

This post has been edited by sela007: 21 April 2012 - 06:13 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1