2012-04-11 134 views
-4

我在大學時,正在創建一個應用程序。但是我的應用程序中有兩個主要問題。我的應用程序是一個比薩應用程序,它允許比薩店內的員工將訂單發送到廚房(這只是一個列表框)。但是,數學不起作用,由於某種原因,正確的定價不會顯示在訂單的標籤中。我嘗試過不同的寫法和放置代碼的方式,但結果總是一樣的。另外,我每桌有五位顧客。如果我選擇所有客戶訂單並單擊發送,則只會發送客戶2的訂單。不是其他任何客戶,但是如果我只是自己做客戶,它就可以工作。創建一個(VB)應用程序,它不能正常工作

下面是我的代碼,希望有人能告訴我我哪裏會出錯,因爲我認爲即時通訊僅僅是盲目的,因爲我查看了整個事物並且無法看到它的問題。預先感謝任何給予解決方案的幫助/反饋。

APP代碼:

Public Class Form1 
    Dim myformat As String = "{0,-10}{1,-25}{2,-15}{3,-30}{4,-10}" 
    Dim cost As Single 
    Dim base As String 
    Dim pizza As String 
    Dim table As String 
    Dim topping As String 
    Dim drink As String 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     ListBox1.Items.Add(String.Format(myformat, "table", "pizza", "base", "topping", "drink")) 
    End Sub 
    Private Sub STK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles STK.Click 


    '------------------table no-------------------' 
    If tableno.Text = "1" Then 
     table = "1" 
    ElseIf tableno.Text = "2" Then 
     table = "2" 
    ElseIf tableno.Text = "3" Then 
     table = "3" 
    ElseIf tableno.Text = "4" Then 
     table = "4" 
    ElseIf tableno.Text = "5" Then 
     table = "5" 
    ElseIf tableno.Text = "6" Then 
     table = "6" 
    ElseIf tableno.Text = "7" Then 
     table = "7" 
    ElseIf tableno.Text = "8" Then 
     table = "8" 
    ElseIf tableno.Text = "9" Then 
     table = "9" 
    ElseIf tableno.Text = "10" Then 
     table = "10" 
    ElseIf tableno.Text = "11" Then 
     table = "11" 
    ElseIf tableno.Text = "12" Then 
     table = "12" 
    ElseIf tableno.Text = "13" Then 
     table = "13" 
    ElseIf tableno.Text = "14" Then 
     table = "14" 
    ElseIf tableno.Text = "15" Then 
     table = "15" 
    ElseIf tableno.Text = "16" Then 
     table = "16" 
    ElseIf tableno.Text = "17" Then 
     table = "17" 
    ElseIf tableno.Text = "18" Then 
     table = "18" 
    ElseIf tableno.Text = "19" Then 
     table = "19" 
    ElseIf tableno.Text = "20" Then 
     table = "20" 
    ElseIf tableno.Text = "21" Then 
     table = "21" 
    ElseIf tableno.Text = "22" Then 
     table = "22" 
    ElseIf tableno.Text = "23" Then 
     table = "23" 
    ElseIf tableno.Text = "24" Then 
     table = "24" 
    ElseIf tableno.Text = "25" Then 
     table = "25" 
    End If 
    '---------------pizza type 1----------------' 
    If pizza1.Text = "Planet Cheese" Then 
     pizza = "Planet Cheese" 
     cost = 4.0 
    ElseIf pizza1.Text = "Planet Special" Then 
     pizza = "Planet Special" 
     cost = 5.0 
    ElseIf pizza1.Text = "Planet Vegi" Then 
     pizza = "Planet Vegi" 
     cost = 4.5 
    ElseIf pizza1.Text = "Planet Feast" Then 
     pizza = "Planet Feast" 
     cost = 6.0 
    ElseIf pizza1.Text = "Planet Itella" Then 
     pizza = "Planet Itella" 
     cost = 6.5 
    End If 
    '---------------pizza type 2----------------' 
    If pizza2.Text = "Planet Cheese" Then 
     pizza = "Planet Cheese" 
     cost = 4.0 
    ElseIf pizza2.Text = "Planet Special" Then 
     pizza = "Planet Special" 
     cost = 5.0 
    ElseIf pizza2.Text = "Planet Vegi" Then 
     pizza = "Planet Vegi" 
     cost = 4.5 
    ElseIf pizza2.Text = "Planet Feast" Then 
     pizza = "Planet Feast" 
     cost = 6.0 
    ElseIf pizza2.Text = "Planet Itella" Then 
     pizza = "Planet Itella" 
     cost = 6.5 
    End If 


    '---------------pizza type 3----------------' 
    If pizza3.Text = "Planet Cheese" Then 
     pizza = "Planet Cheese" 
     cost = 4.0 
    ElseIf pizza3.Text = "Planet Special" Then 
     pizza = "Planet Special" 
     cost = 5.0 
    ElseIf pizza3.Text = "Planet Vegi" Then 
     pizza = "Planet Vegi" 
     cost = 4.5 
    ElseIf pizza3.Text = "Planet Feast" Then 
     pizza = "Planet Feast" 
     cost = 6.0 
    ElseIf pizza3.Text = "Planet Itella" Then 
     pizza = "Planet Itella" 
     cost = 6.5 
    End If 

    '---------------pizza type 4----------------' 
    If pizza4.Text = "Planet Cheese" Then 
     pizza = "Cheese and Tamato" 
     cost = 4.0 
    ElseIf pizza4.Text = "Planet Special" Then 
     pizza = "Planet Special" 
     cost = 5.0 
    ElseIf pizza4.Text = "Planet Vegi" Then 
     pizza = "Planet Vegi" 
     cost = 4.5 
    ElseIf pizza4.Text = "Planet Feast" Then 
     pizza = "Planet Feast" 
     cost = 6.0 
    ElseIf pizza4.Text = "Planet Itella" Then 
     pizza = "Planet Itella" 
     cost = 6.5 
    End If 

    '---------------pizza type 5----------------' 
    If pizza5.Text = "Planet Cheese" Then 
     pizza = "Planet Cheese" 
     cost = 4.0 
    ElseIf pizza2.Text = "Planet Special" Then 
     pizza = "Planet Special" 
     cost = 5.0 
    ElseIf pizza5.Text = "Planet Vegi" Then 
     pizza = "Planet Vegi" 
     cost = 4.5 
    ElseIf pizza2.Text = "Planet Feast" Then 
     pizza = "Planet Feast" 
     cost = 6.0 
    ElseIf pizza5.Text = "Planet Itella" Then 
     pizza = "Planet Itella" 
     cost = 6.5 
    End If 


    '---------------base 1 ------------' 
    If norm1.Checked Then 
     base = "norm" 
    ElseIf thin1.Checked Then 
     base = "thin" 
    ElseIf CB1.Checked Then 
     base = "CB" 
    ElseIf BSC1.Checked Then 
     base = "BSC" 
    End If 
    '---------------base 2 ------------' 
    If norm2.Checked Then 
     base = "norm" 
    ElseIf thin2.Checked Then 
     base = "thin" 
    ElseIf CB2.Checked Then 
     base = "CB" 
    ElseIf BSC2.Checked Then 
     base = "BSC" 
    End If 
    '---------------base 3 ------------' 
    If norm3.Checked Then 
     base = "norm" 
    ElseIf thin3.Checked Then 
     base = "thin" 
    ElseIf CB3.Checked Then 
     base = "CB" 
    ElseIf BSC3.Checked Then 
     base = "BSC" 
    End If 
    '---------------base 4 ------------' 
    If norm4.Checked Then 
     base = "norm" 
    ElseIf thin4.Checked Then 
     base = "thin" 
    ElseIf CB4.Checked Then 
     base = "CB" 
    ElseIf BSC4.Checked Then 
     base = "BSC" 
    End If 
    '---------------base 5 ------------' 
    If norm5.Checked Then 
     base = "norm" 
    ElseIf thin5.Checked Then 
     base = "thin" 
    ElseIf CB5.Checked Then 
     base = "CB" 
    ElseIf BSC5.Checked Then 
     base = "BSC" 
    End If 





    '----------topping1----' 
    If cheese1.Checked = True Then 
     topping = "Cheese" 
     cost = cost + 1.0 
    End If 
    If pepperoni1.Checked = True Then 
     topping = "Pepperoni" 
     cost = cost + 1.0 
    End If 
    If onion1.Checked = True Then 
     topping = "onion" 
     cost = cost + 1.0 
    End If 
    If peppers1.Checked = True Then 
     topping = "Peppers" 
     cost = cost + 1.0 
    End If 
    If sausage1.Checked = True Then 
     topping = "sausage" 
     cost = cost + 1.0 
    End If 
    If tuna1.Checked = True Then 
     topping = "tuna" 
     cost = cost + 1.0 
    End If 
    If meatballs1.Checked = True Then 
     topping = "meatballs" 
     cost = cost + 1.0 
    End If 






    '----------topping2----' 
    If cheese2.Checked = True Then 
     topping = "Cheese" 
     cost = cost + 1.0 
    End If 
    If pepperoni2.Checked = True Then 
     topping = "Pepperoni" 
     cost = cost + 1.0 
    End If 
    If onion2.Checked = True Then 
     topping = "onion" 
     cost = cost + 1.0 
    End If 
    If peppers2.Checked = True Then 
     topping = "Peppers" 
     cost = cost + 1.0 
    End If 
    If sausage2.Checked = True Then 
     topping = "sausage" 
     cost = cost + 1.0 
    End If 
    If tuna2.Checked = True Then 
     topping = "tuna" 
     cost = cost + 1.0 
    End If 
    If meatballs2.Checked = True Then 
     topping = "meatballs" 
     cost = cost + 1.0 
    End If 





    '----------topping3----' 
    If cheese3.Checked = True Then 
     topping = "Cheese" 
     cost = cost + 1.0 
    End If 
    If pepperoni3.Checked = True Then 
     topping = "Pepperoni" 
     cost = cost + 1.0 
    End If 
    If onion3.Checked = True Then 
     topping = "onion" 
     cost = cost + 1.0 
    End If 
    If peppers3.Checked = True Then 
     topping = "Peppers" 
     cost = cost + 1.0 
    End If 
    If sausage3.Checked = True Then 
     topping = "sausage" 
     cost = cost + 1.0 
    End If 
    If tuna3.Checked = True Then 
     topping = "tuna" 
     cost = cost + 1.0 
    End If 
    If meatballs3.Checked = True Then 
     topping = "meatballs" 
     cost = cost + 1.0 
    End If 






    '----------topping4----' 
    If cheese4.Checked = True Then 
     topping = "Cheese" 
     cost = cost + 1.0 
    End If 
    If pepperoni4.Checked = True Then 
     topping = "Pepperoni" 
     cost = cost + 1.0 
    End If 
    If onion4.Checked = True Then 
     topping = "onion" 
     cost = cost + 1.0 
    End If 
    If peppers4.Checked = True Then 
     topping = "Peppers" 
     cost = cost + 1.0 
    End If 
    If sausage4.Checked = True Then 
     topping = "sausage" 
     cost = cost + 1.0 
    End If 
    If tuna4.Checked = True Then 
     topping = "tuna" 
     cost = cost + 1.0 
    End If 
    If meatballs4.Checked = True Then 
     topping = "meatballs" 
     cost = cost + 1.0 
    End If 







    '----------topping5----' 
    If cheese5.Checked = True Then 
     topping = "Cheese" 
     cost = cost + 1.0 
    End If 
    If pepperoni5.Checked = True Then 
     topping = "Pepperoni" 
     cost = cost + 1.0 
    End If 
    If onion5.Checked = True Then 
     topping = "onion" 
     cost = cost + 1.0 
    End If 
    If peppers5.Checked = True Then 
     topping = "Peppers" 
     cost = cost + 1.0 
    End If 
    If sausage5.Checked = True Then 
     topping = "sausage" 
     cost = cost + 1.0 
    End If 
    If tuna5.Checked = True Then 
     topping = "tuna" 
     cost = cost + 1.0 
    End If 
    If meatballs5.Checked = True Then 
     topping = "meatballs" 
     cost = cost + 1.0 
    End If 







    '---------------drink1-----------------------' 
    If drink1.Text = "Cola" Then 
     drink = "Cola" 
     cost = cost + 0.9 
    ElseIf drink1.Text = "Fruit Punch" Then 
     drink = "Fruit Punch" 
     cost = cost + 0.8 
    ElseIf drink1.Text = "J2o" Then 
     drink = "J2o" 
     cost = cost + 0.9 
    ElseIf drink1.Text = "Alien Blaster" Then 
     drink = "Alien Blaster" 
     cost = cost + 0.9 
    ElseIf drink1.Text = "Alien Brains" Then 
     drink = "Alien Brains" 
     cost = cost + 0.9 
    End If 





    '---------------drink2-----------------------' 
    If drink2.Text = "Cola" Then 
     drink = "Cola" 
     cost = cost + 0.9 
    ElseIf drink2.Text = "Fruit Punch" Then 
     drink = "Fruit Punch" 
     cost = cost + 0.8 
    ElseIf drink2.Text = "J2o" Then 
     drink = "J2o" 
     cost = cost + 0.9 
    ElseIf drink1.Text = "Alien Blaster" Then 
     drink = "Alien Blaster" 
     cost = cost + 0.9 
    ElseIf drink1.Text = "Alien Brains" Then 
     drink = "Alien Brains" 
     cost = cost + 0.9 
    End If 




    '---------------drink3-----------------------' 
    If drink3.Text = "Cola" Then 
     drink = "Cola" 
     cost = cost + 0.9 
    ElseIf drink3.Text = "Fruit Punch" Then 
     drink = "Fruit Punch" 
     cost = cost + 0.8 
    ElseIf drink3.Text = "J2o" Then 
     drink = "J2o" 
     cost = cost + 0.9 
    ElseIf drink1.Text = "Alien Blaster" Then 
     drink = "Alien Blaster" 
     cost = cost + 0.9 
    ElseIf drink1.Text = "Alien Brains" Then 
     drink = "Alien Brains" 
     cost = cost + 0.9 
    End If 




    '---------------drink4-----------------------' 
    If drink4.Text = "Cola" Then 
     drink = "Cola" 
     cost = cost + 0.9 
    ElseIf drink4.Text = "Fruit Punch" Then 
     drink = "Fruit Punch" 
     cost = cost + 0.8 
    ElseIf drink4.Text = "J2o" Then 
     drink = "J2o" 
     cost = cost + 0.9 
    ElseIf drink1.Text = "Alien Blaster" Then 
     drink = "Alien Blaster" 
     cost = cost + 0.9 
    ElseIf drink1.Text = "Alien Brains" Then 
     drink = "Alien Brains" 
     cost = cost + 0.9 
    End If 





    '---------------drink5-----------------------' 
    If drink5.Text = "Cola" Then 
     drink = "Cola" 
     cost = cost + 0.9 
    ElseIf drink5.Text = "Fruit Punch" Then 
     drink = "Fruit Punch" 
     cost = cost + 0.8 
    ElseIf drink5.Text = "J2o" Then 
     drink = "J2o" 
     cost = cost + 0.9 
    ElseIf drink1.Text = "Alien Blaster" Then 
     drink = "Alien Blaster" 
     cost = cost + 0.9 
    ElseIf drink1.Text = "Alien Brains" Then 
     drink = "Alien Brains" 
     cost = cost + 0.9 
    End If 

    ListBox1.Items.Add(String.Format(myformat, table, pizza, base, topping, drink)) 


    totallabel.Text = Format(cost, "currency") 
End Sub 
+4

爲什麼'tableno.Tex = table'而不是所有這些'if..else' ?! – 2012-04-11 02:15:23

+7

你的第一個問題,這不是C#。 – Gabe 2012-04-11 02:15:28

+1

痛苦的閱讀問題和代碼。 – 2012-04-11 02:17:18

回答

0

嘗試使用C#帶開關的情況下。代碼會更加readable.As據我undrestood成本不Pizzas.After增加了pizas檢查代碼的成本,應+ =價格代替成本= pizzaprice

另外編輯隨後BASE1 code.Pizzaone的順序,摘心1,drink1等和ListBox.Add。然後做同樣pizza2,pizza3等後跟一個listbox.add

+0

好吧,太好了。感謝您的反饋意見。此外,當我運行我的應用程序,我必須點擊「發送到廚房」按鈕一次或兩次以獲得應用程序的工作。是因爲代碼的順序嗎? – user1325468 2012-04-11 02:26:52

+0

我不認爲這是因爲代碼的順序。嘗試更改代碼的順序。根據當前代碼,似乎只有一個客戶訂單將被添加到列表框 – 2012-04-11 02:32:56

1

歡迎來到StackOverflow。它是你學習如何調試的時間,這裏是一個開始(不可否認的是,這個人並不是那麼好(他甚至不使用快捷鍵 - 但它應該足夠簡單,以供任何人理解):http://www.youtube.com/watch?v=jxR_ngGIpQM 。回來一次,你已經調試代碼

在平均時間這裏有一些指針:

一)利用交換機(或在VB.Net稱爲選擇),而不是所有的如果,elseif的語句。例如這樣的:

If tableno.Text = "1" Then 
table = "1" 
ElseIf tableno.Text = "2" Then 
table = "2" 

可以表示要好得多:

Select Case tableno.Text 
Case Is = 1 

Case Is < 5 

Case Is < 10 

Case Is > 9 

End Select 

它仍然是沒有意義的,我認爲表變量只是複製文本框的Text屬性,所以你可以只使用tableno.Text代替名爲table的變量。如果你將要圍繞通過這個變量的其他功能,然後就這樣的代碼是:

tableno = tableno.Text ' 50 lines less of code! 

B)這是另外一個例子,看你如何分配if語句時,你可以只是一次分配如:

If drink1.Text = "Cola" Then 
drink = "Cola" 
cost = cost + 0.9 
ElseIf drink1.Text = "Fruit Punch" Then 
drink = "Fruit Punch" 

它更容易只是做了一個線上的的if else語句的結束,如:

drink = drink1.Text 

三)不要硬編碼值(價格,產品名稱,等C)!將值存儲在數據庫甚至文本文件中!

d)如果測試布爾條件不要打擾測試,如果它等於true。例如

If cheese3.Checked Then