2 Replies - 539 Views - Last Post: 07 November 2012 - 11:20 PM Rate Topic: ***** 1 Votes

#1 lightGraphn_Fiend  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-November 12

I need help in my Visual Basic class.

Posted 07 November 2012 - 03:12 PM

Public Class Project6

    Dim SelectorInteger As Integer
    Dim ArrayInteger(6, 4) As Integer
    Dim MyDialogResult As DialogResult

    Private Sub Project6_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        ArrayInteger(0, 0) = 40D
        ArrayInteger(1, 0) = 50D
        ArrayInteger(2, 0) = 21D
        ArrayInteger(3, 0) = 25D
        ArrayInteger(4, 0) = 50D
        ArrayInteger(5, 0) = 25D
        ArrayInteger(6, 0) = 20D

        ArrayInteger(0, 1) = 43D
        ArrayInteger(1, 1) = 43D
        ArrayInteger(2, 1) = 36D
        ArrayInteger(3, 1) = 25D
        ArrayInteger(4, 1) = 75D
        ArrayInteger(5, 1) = 33D
        ArrayInteger(6, 1) = 35D

        ArrayInteger(0, 2) = 55D
        ArrayInteger(1, 2) = 65D
        ArrayInteger(2, 2) = 48D
        ArrayInteger(3, 2) = 25D
        ArrayInteger(4, 2) = 100D
        ArrayInteger(5, 2) = 41D
        ArrayInteger(6, 2) = 47D

        ArrayInteger(0, 3) = 68D
        ArrayInteger(1, 3) = 78D
        ArrayInteger(2, 3) = 61D
        ArrayInteger(3, 3) = 25D
        ArrayInteger(4, 3) = 125D
        ArrayInteger(5, 3) = 50D
        ArrayInteger(6, 3) = 60

        ArrayInteger(0, 4) = 90D
        ArrayInteger(1, 4) = 110D
        ArrayInteger(2, 4) = 86D
        ArrayInteger(3, 4) = 25D
        ArrayInteger(4, 4) = 150D
        ArrayInteger(5, 4) = 60D
        ArrayInteger(6, 4) = 90D

    End Sub

    Private Sub LookupCostButton_Click(sender As System.Object, e As System.EventArgs) Handles LookupCostButton.Click
        'Dim RowInteger, ColumnInteger As Integer
        'Dim SalePriceDecimal As Decimal
        Dim BooleanFound As Boolean = False


        If SpaServiceComboBox.Text <> "" And OneFourthHourRadioButton.Checked = True And RoomNumberListBox.SelectedIndex <> -1 Or
          HalfHourRadioButton.Checked = True And SpaServiceComboBox.Text <> "" And RoomNumberListBox.SelectedIndex <> -1 Or
          ThreeFourthRadioButton.Checked = True And SpaServiceComboBox.Text <> "" And RoomNumberListBox.SelectedIndex <> -1 Or
          HourRadioButton.Checked = True And SpaServiceComboBox.Text <> "" And RoomNumberListBox.SelectedIndex <> -1 Or
          HourAndHalfRadioButton.Checked = True And SpaServiceComboBox.Text <> "" And RoomNumberListBox.SelectedIndex <> -1 Then

            For i As Integer = 0 To SpaServiceComboBox.Items.Count - 1

                For y As Integer = 0 To SelectorInteger

                    For x As Integer = 0 To RoomNumberListBox.Items.Count - 1

                        If SpaServiceComboBox.SelectedIndex = i And RoomNumberListBox.SelectedIndex = x And SelectorInteger = y Then

                            MessageBox.Show(SpaServiceComboBox.Items(i).ToString & " reserved room " &
                                            RoomNumberListBox.Items(x).ToString & " cost " & ArrayInteger(x, y), "Room reservation")

                            SpaServiceComboBox.Text = ""
                            RoomNumberListBox.SelectedIndex = -1
                            BooleanFound = True

                        End If

                        'Exit For
                    Next x

                Next y


            Next i

        Else
            MessageBox.Show("Please select a Spa Service, Room, and Amount of time you'd like to reserve and get the cost", "Fill out all info")
        End If

    End Sub

 Private Sub RadioButtons_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles OneFourthHourRadioButton.CheckedChanged,
        HalfHourRadioButton.CheckedChanged, ThreeFourthRadioButton.CheckedChanged, HourRadioButton.CheckedChanged, HourAndHalfRadioButton.CheckedChanged

        Dim RadioButtonselector As RadioButton

        RadioButtonselector = CType(sender, RadioButton)


        If RadioButtonselector.Checked = OneFourthHourRadioButton.Checked Then
            SelectorInteger = 0

        ElseIf RadioButtonselector.Checked = HalfHourRadioButton.Checked Then
            SelectorInteger = 1

        ElseIf RadioButtonselector.Checked = ThreeFourthRadioButton.Checked Then
            SelectorInteger = 2

        ElseIf RadioButtonselector.Checked = HourRadioButton.Checked Then
            SelectorInteger = 3

        Else
            SelectorInteger = 4
        End If

    End Sub


I am a beginner at Visual Basic, and my teacher wants a multidimensional code that will cause this spa service price to come up with those values. How could I make the array work, and have the currency to come up in the ServicePriceTextBox?

This post has been edited by modi123_1: 07 November 2012 - 03:18 PM
Reason for edit:: highlight the text and just click the 'code' button in the text editor


Is This A Good Question/Topic? 0
  • +

Replies To: I need help in my Visual Basic class.

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,289
  • Joined: 18-April 07

Re: I need help in my Visual Basic class.

Posted 07 November 2012 - 04:28 PM

That if statement is one long complicated mess. Try simplifying it by putting ifs inside of other ifs and then once you get to the point where you have valid data, then you can use the values to select the correct value and display the price.

For instance...

If SpaServiceComboBox.Text <> "" And RoomNumberListBox.SelectedIndex <> -1 then
      Dim Room as Integer = RoomNumberListBox.SelectedIndex

      If OneFourthHourRadioButton.Checked then
           ServicePriceTextBox.Text = ArrayInteger(Room,0)   
      ElseIf HalfHourRadioButton.Checked then
           ServicePriceTextBox.Text = ArrayInteger(Room,1)
      ElseIf ThreeFourthRadioButton.Checked then
           ServicePriceTextBox.Text = ArrayInteger(Room,2)
      ElseIf HourRadioButton.Checked then
           ServicePriceTextBox.Text = ArrayInteger(Room,3)
      ElseIf HourAndHalfRadioButton.Checked then
           ServicePriceTextBox.Text = ArrayInteger(Room,4)
      Else
           ServicePriceTextBox.Text = "Ask Receiptionist About Pricing"
      End If
End If



The above code is an example. But here we have taken the room number and checked which radio button has been selected. Based on those two pieces of info, we look up the price from ArrayInteger and put the price into our Textbox.

Things to take away from this is that we don't have to test the same thing multiple times (Why check if the spa service combo text is not null each time? test it once and if it passes, continue on with other checks.

:)
Was This Post Helpful? 1
  • +
  • -

#3 lightGraphn_Fiend  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-November 12

Re: I need help in my Visual Basic class.

Posted 07 November 2012 - 11:20 PM

That helped a lot actually. My teacher is just huge on spreading the code out, but doesn't explain how to simplify it as much. Thanks for explaining it along with the code. Now, I have another one that is getting me all sorts of confused. I'll probably post again soon, but don't know how to as much.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1