7 Replies - 870 Views - Last Post: 09 March 2016 - 10:30 PM Rate Topic: -----

#1 DVDEEMAN  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-March 16

LEARNING VB - Having issues with getting my code to calculate prices

Posted 07 March 2016 - 05:03 PM

So i watched several tutorials and have not been able to get my code to calculate the prices of my selected atems on my restaurant ordering form. Everything else works fine, I got this far and now im stuck... The code keeps calculating all the items on my form instead of only my selected items.


Public Class Form1

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbo_Meat.SelectedIndexChanged

If cbo_Meat.SelectedIndex = 0 Then

cbo_Style.Items.Clear()

cbo_Style.Items.Add("Curried")

cbo_Style.Items.Add("Brown Stewed")

cbo_Style.Items.Add("Fried")

 

ElseIf cbo_Meat.SelectedIndex = 1 Then

cbo_Style.Items.Clear()

cbo_Style.Items.Add("Jerked")

cbo_Style.Items.Add("Pot Roasted")

End If

 

 

'/////////////////////////////////////////// DEFAULT

If cbo_Meat.SelectedIndex = 0 Then

cbo_Style.SelectedIndex = 0

End If

 

If cbo_Meat.SelectedIndex = 1 Then

cbo_Style.SelectedIndex = 0

End If

End Sub

Private Sub btb_Review_order_Click(sender As Object, e As EventArgs) Handles btb_Review_order.Click

 

'//////////////////////////////////////////////////////////////////////////intSIZE

 

Dim Price_Small As Integer

Price_Small = 250

Dim Price_Medium As Integer

Price_Medium = 350

Dim price_Large As Integer

price_Large = 500

'//////////////////////////////////////////////////////////////////////////intSTARCH

Dim starch1 As Integer

starch1 = 50

Dim starch2 As Integer

starch2 = 70

Dim starch3 As Integer

starch3 = 100

'//////////////////////////////////////////////////////////////////////////intBEV

Dim Bev_Size1_medium_OJ As Integer

Bev_Size1_medium_OJ = 100

Dim Bev_Size2_large_OJ As Integer

Bev_Size2_large_OJ = 150

Dim Bev_Size3_small_cwater As Integer

Bev_Size3_small_cwater = 150

Dim Bev_Size4_medium_cwater As Integer

Bev_Size4_medium_cwater = 200

Dim Bev_Size5_large_soda As Integer

Bev_Size5_large_soda = 180

'//////////////////////////////////////////////////////////////////////////intTOTAL

Dim total As Integer

txt_Total_Cost.Text = total

'//////////////////////////////////////////////////////////////////////////

 

'Dim Calculate_Price As Integer

 

'//////////////////////////////////////////////////////////////////////////////////////////

If rb_small.Checked Is True And

chb_Rice.Checked = True And Or

chb_Mashed_P.Checked = True And Or

chb_Pasta = True And

Cbo_Beverage.SelectedIndex = 0 And

cbo_Size.SelectedItem = ("Medium") And Or cbo_Size.SelectedItem = ("Large") Then

total = (Price_Small + Price_Medium + price_Large + starch1 + starch2 + starch3 + Bev_Size1_medium_OJ + Bev_Size2_large_OJ)

End If

 

'//////////////////////////////////////////////////////////////////////////////LUNCH_size/LISTBOX

'Adds (SIZE OF LUNCH) to List box

ListBox1.Items.Clear()

If rb_small.Checked = True Then

ListBox1.Items.Add("Small Lunch $250")

ElseIf rb_medium.Checked = True Then

ListBox1.Items.Add("Medium Lunch $350")

ElseIf rb_large.Checked = True Then

ListBox1.Items.Add("Large Lunch $500")

End If

'/////////////////////////////////////////////////////////////////////////////MEAT_style/LISTBOX

'Adds (MEAT CHOICE & MEAT STYLE) to List box

 

'////CHICKEN

If cbo_Meat.SelectedIndex = 0 AndAlso

cbo_Style.SelectedItem = ("Curried") Then

ListBox1.Items.Add("Chicken, Curried")

End If

If cbo_Meat.SelectedIndex = 0 AndAlso

cbo_Style.SelectedItem = ("Brown Stewed") Then

ListBox1.Items.Add("Chicken, Brown Stewed")

End If

If cbo_Meat.SelectedIndex = 0 AndAlso

cbo_Style.SelectedItem = ("Fried") Then

ListBox1.Items.Add("Chicken, Fried")

End If

 

'////PORK

If cbo_Meat.SelectedIndex = 1 AndAlso

cbo_Style.SelectedItem = ("Jerked") Then

ListBox1.Items.Add("Pork, Jerked")

End If

If cbo_Meat.SelectedIndex = 1 AndAlso

cbo_Style.SelectedItem = ("Pot Roasted") Then

ListBox1.Items.Add("Pork, Pot Roasted")

End If

 

'/////////////////////////////////////////////////////////////////////////////STARCH

'Adds (STARCH) to list box

 

If chb_Rice.Checked Then

ListBox1.Items.Add("Rice $50")

End If

If chb_Mashed_P.Checked Then

ListBox1.Items.Add("Mashed Potatoes $70")

End If

If chb_Pasta.Checked Then

ListBox1.Items.Add("Pasta $100")

End If

'/////////////////////////////////////////////////////////////////////////////////Beverage

'Orange Juice to list box

If Cbo_Beverage.SelectedIndex = 0 AndAlso

cbo_Size.SelectedItem = ("Medium") Then

ListBox1.Items.Add("Orange Juice, Medium $150")

End If

If Cbo_Beverage.SelectedIndex = 0 AndAlso

cbo_Size.SelectedItem = ("Large") Then

ListBox1.Items.Add("Orange Juice, Large $200")

End If

'Coconut Water to list box

 

If Cbo_Beverage.SelectedIndex = 1 AndAlso

cbo_Size.SelectedItem = ("Small") Then

ListBox1.Items.Add("Coconut Water, Small $130")

End If

If Cbo_Beverage.SelectedIndex = 1 AndAlso

cbo_Size.SelectedItem = ("Medium") Then

ListBox1.Items.Add("Coconut Water, Medium $170")

End If

 

'Soda to list box

 

If Cbo_Beverage.SelectedIndex = 2 AndAlso

cbo_Size.SelectedItem = ("Large") Then

ListBox1.Items.Add("Soda, Large $150")

End If

 

 

End Sub

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

rb_small.Checked = True

cbo_Meat.SelectedIndex = 0

cbo_Style.SelectedIndex = 0

chb_Rice.Checked = True

Cbo_Beverage.SelectedIndex = 2

cbo_Size.SelectedIndex = 0

 

 

End Sub

Private Sub txt_Large_Price_TextChanged(sender As Object, e As EventArgs) Handles txt_Large_Price.TextChanged, Txt_Pasta_Price.TextChanged, txt_Mashed_Price.TextChanged, txt_Rice_Price.TextChanged

End Sub

Private Sub txt_Total_Cost_TextChanged(sender As Object, e As EventArgs) Handles txt_Total_Cost.TextChanged

 

 

 

 

End Sub

Private Sub Cbo_Beverage_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Cbo_Beverage.SelectedIndexChanged

If Cbo_Beverage.SelectedIndex = 0 Then

cbo_Size.Items.Clear()

cbo_Size.Items.Add("Medium")

cbo_Size.Items.Add("Large")

 

 

ElseIf Cbo_Beverage.SelectedIndex = 1 Then

cbo_Size.Items.Clear()

cbo_Size.Items.Add("Small")

cbo_Size.Items.Add("Medium")

ElseIf Cbo_Beverage.SelectedIndex = 2 Then

cbo_Size.Items.Clear()

cbo_Size.Items.Clear()

cbo_Size.Items.Add("Large")

End If

End Sub

Private Sub txt_Beverage_Cost_TextChanged(sender As Object, e As EventArgs) Handles txt_Beverage_Cost.TextChanged

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End Sub

Private Sub cbo_Size_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbo_Size.SelectedIndexChanged

 

 

 

'orange juice bev cost

If Cbo_Beverage.SelectedIndex = 0 AndAlso

cbo_Size.SelectedItem = ("Medium") Then

txt_Beverage_Cost.Text = ("$150")

End If

If Cbo_Beverage.SelectedIndex = 0 AndAlso

cbo_Size.SelectedItem = ("Large") Then

txt_Beverage_Cost.Text = ("$200")

End If

'Coconut bev cost

 

If Cbo_Beverage.SelectedIndex = 1 AndAlso

cbo_Size.SelectedItem = ("Small") Then

txt_Beverage_Cost.Text = ("$150")

End If

If Cbo_Beverage.SelectedIndex = 1 AndAlso

cbo_Size.SelectedItem = ("Medium") Then

txt_Beverage_Cost.Text = ("$170")

End If

 

'Soda to bev cost

 

If Cbo_Beverage.SelectedIndex = 2 AndAlso

cbo_Size.SelectedItem = ("Large") Then

txt_Beverage_Cost.Text = ("$150")

End If

 

End Sub

End Class

This post has been edited by macosxnerd101: 07 March 2016 - 05:26 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: LEARNING VB - Having issues with getting my code to calculate prices

#2 DVDEEMAN  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-March 16

Re: LEARNING VB - Having issues with getting my code to calculate prices

Posted 07 March 2016 - 06:52 PM

WOW... 27 VIEWS AND NO HELP...

37 VIEWS...
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13554
  • View blog
  • Posts: 54,090
  • Joined: 12-June 08

Re: LEARNING VB - Having issues with getting my code to calculate prices

Posted 07 March 2016 - 06:53 PM

Please be cognizant this is a volunteer forum. Folks answer topics on their time.
Was This Post Helpful? 0
  • +
  • -

#4 DVDEEMAN  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-March 16

Re: LEARNING VB - Having issues with getting my code to calculate prices

Posted 07 March 2016 - 06:57 PM

@MODI123_1

APOLAGIES...
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • say what now
  • member icon

Reputation: 6408
  • View blog
  • Posts: 25,891
  • Joined: 12-December 12

Re: LEARNING VB - Having issues with getting my code to calculate prices

Posted 08 March 2016 - 08:38 AM

This is for VB.NET not VB6. Question moved to VB.NET forum.
Was This Post Helpful? 0
  • +
  • -

#6 0Pain0Gain  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 116
  • Joined: 15-December 15

Re: LEARNING VB - Having issues with getting my code to calculate prices

Posted 08 March 2016 - 09:23 AM

I read through all the code.... (small tip, dont use so much spacing, code compacted is easier to read, use comments to give notifications as you read it.)

I have created systems like this in the past for online stores for adding up the variants to get a total.

The issue you have is so many AND OR statements based on checkboxes

If rb_small.Checked Is True And
chb_Rice.Checked = True And Or
chb_Mashed_P.Checked = True And Or
chb_Pasta = True And
Cbo_Beverage.SelectedIndex = 0 And
cbo_Size.SelectedItem = ("Medium") And Or cbo_Size.SelectedItem = ("Large") Then
total = (Price_Small + Price_Medium + price_Large + starch1 + starch2 + starch3 + Bev_Size1_medium_OJ + Bev_Size2_large_OJ)
End If




Dim size_cost As Double
    If rb_small.Checked Then
        size_cost = 9.5
    ElseIf rb_medium.Checked Then
        size_cost = 10.5
    ElseIf rb_large.Checked Then
        size_cost = 11.5
    End If



If you did a set of these instead then added up the double variables at the end if would make it alot clearer and probably reduce the code down to 20-30 lines

You could also encase this in a loop to handle multiple order selections.

Hope this helps
Was This Post Helpful? 1
  • +
  • -

#7 DVDEEMAN  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-March 16

Re: LEARNING VB - Having issues with getting my code to calculate prices

Posted 09 March 2016 - 10:00 PM

Thanks you.. gonna try now..

This post has been edited by andrewsw: 10 March 2016 - 01:22 AM
Reason for edit:: Removed previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#8 DVDEEMAN  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-March 16

Re: LEARNING VB - Having issues with getting my code to calculate prices

Posted 09 March 2016 - 10:30 PM

Thank you... based on the snippet and the advice i was able to figure it out..respect... all the way from JAMAICA!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1