-3
我和我的朋友正在研究一個簡單的課程程序,允許您根據字符串設置爲Processing
或Sales
來確定工資。我們希望它確定,當您將Sales
放在文本框中時,它會計算出您輸入的小時數。銷售額乘以20.Visual Basic If..Then..Else String statement
這是我們目前所擁有的。
Private Sub calcButton_Click(sender As Object, e As EventArgs) Handles calcButton.Click
'declare
Dim total As Double
Dim weekly As Double
Dim weekly1 As Double
Dim weekly2 As Double
Dim weekly3 As Double
Dim weekly4 As Double
Dim hours1 As Double
Dim hours2 As Double
Dim hours3 As Double
Dim hours4 As Double
Dim dep1 As Integer
Dim dep2 As Integer
Dim dep3 As Integer
Dim dep4 As Integer
Double.TryParse(hoursWorked1TB.Text, hours1)
Double.TryParse(hoursworked2TB.Text, hours2)
Double.TryParse(hoursWorked3TB.Text, hours3)
Double.TryParse(hoursWorked4TB.Text, hours4)
'as decimal
weeklyPay1.Text = weekly.ToString("C1")
weeklyPay2.Text = weekly.ToString("C1")
weeklyPay3.Text = weekly.ToString("C1")
weeklyPay4.Text = weekly.ToString("C1")
'sales and processing
If dep1TB.Text = "Sales" Then
dep1 = 20
ElseIf dep1TB.Text = "Processing" Then
dep2 = 15
Else : dep1 = 0
End If
If dep2TB.Text = "Sales" Then
dep2 = 20
ElseIf dep2TB.Text = "Processing" Then
dep2 = 15
Else : dep2 = 0
End If
If dep3TB.Text = "Sales" Then
dep3 = 20
ElseIf dep3TB.Text = "Processing" Then
dep3 = 15
Else : dep3 = 0
End If
If dep4TB.Text = "Sales" Then
dep4 = 20
ElseIf dep4TB.Text = "Processing" Then
dep2 = 15
Else : dep4 = 0
End If
'calculations
weekly1 = hours1 * dep1
weekly2 = hours2 * dep2
weekly3 = hours3 * dep3
weekly4 = hours4 * dep4
total = weekly1 + weekly2 + weekly3 + weekly4
End Sub
後來我決定了我們需要一個作爲字符串變量,但一切仍然返回爲0
您需要在完成計算後設置文本框的文本*。 – 2015-03-02 20:25:27
似乎你有Option Strict On,我不得不在這一倡議中向你表示祝賀。 – 2015-03-02 20:37:55
我看到了Tripp的編輯,並在weeklyPay需要相應的數字以便在正確的文本框中打印後才意識到它。謝謝你的幫助。 – user3011165 2015-03-02 20:38:58