我需要實現的主要目標是使用戶輸入的詳細信息(例如使用的分鐘數和總費用等)在一個列表中顯示給用戶,一旦所有框都有已被填寫。然後,他們可以將該框/列表框中的文本保存到PC上的txt文件中。將文本加載到列表框中
這幾乎是我所需要做的。我似乎無法做到這一點,並不知道我該怎麼做。這是迄今爲止我所應用的代碼。
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub btn1TotalCost_Click(sender As Object, e As EventArgs) Handles btn1TotalCost.Click
'Declaring the variables.
Dim MinutesAllowed As Integer
Dim MinutesUsed As Integer
Dim TextsAllowed As Integer
Dim TextsUsed As Integer
Dim DataAllowed As Integer
Dim DataUsed As Integer
Dim MinutesTotalCost As Double
Dim TextsTotalCost As Double
Dim DataTotalCost As Double
Dim MonthlyCost As Double
Dim TotalCost As Double
MinutesAllowed = Val(txtBoxMinutesAllowed.Text)
MinutesUsed = Val(txtBoxMinutesUsed.Text)
TextsAllowed = Val(txtBoxTextsAllowed.Text)
TextsUsed = Val(txtBoxTextsUsed.Text)
DataAllowed = Val(txtBoxDataAllowed.Text)
DataUsed = Val(txtBoxDataUsed.Text)
MinutesTotalCost = Val(txtBoxTotalCost.Text)
TextsTotalCost = Val(txtBoxTotalCost.Text)
DataTotalCost = Val(txtBoxTotalCost.Text)
TotalCost = Val(txtBoxTotalCost.Text)
'Calculation For Minutes
MinutesAllowed = Val(txtBoxMinutesAllowed.Text)
MinutesUsed = Val(txtBoxMinutesUsed.Text)
MonthlyCost = Val(txtBoxMonthlyCost.Text)
'If the minutes allowed is greater than or equal to the minutes used, no extra charge is added.
If MinutesAllowed >= MinutesUsed Then
MinutesTotalCost = 0
Else 'If the minutes used is greater than the minutes allowed, each minute is multiplied by 00.30p.
MinutesTotalCost = (MinutesUsed - MinutesAllowed) * 0.3
End If
txtBoxTotalCost.Text = CType(MinutesTotalCost + MonthlyCost, String)
'Calculation For Texts
TextsAllowed = Val(txtBoxTextsAllowed.Text)
TextsUsed = Val(txtBoxTextsUsed.Text)
MonthlyCost = Val(txtBoxMonthlyCost.Text)
'If the texts allowed is greater than or equal to the texts used, no extra charge is added.
If TextsAllowed >= TextsUsed Then
TextsTotalCost = 0
Else 'If the texts used is greater than the texts allowed, each text is multiplied by 00.15p.
TextsTotalCost = (TextsUsed - TextsAllowed) * 0.15
End If
txtBoxTotalCost.Text = CType(TextsTotalCost + MonthlyCost, String)
'Calculation For Data
DataAllowed = Val(txtBoxDataAllowed.Text)
DataUsed = Val(txtBoxDataUsed.Text)
MonthlyCost = Val(txtBoxMonthlyCost.Text)
'If the data allowed is greater than or equal to the data used, no extra charge is added.
If DataAllowed >= DataUsed Then
DataTotalCost = 0
Else 'If the data used is greater than the data allowed, 10.00 is added to the total cost.
DataTotalCost = 10
End If
txtBoxTotalCost.Text = CType(DataTotalCost + MonthlyCost + TextsTotalCost + MinutesTotalCost, Double)
End Sub
End Class
PhoneNumber可能不應該是一個Decimal。你爲什麼要設置所有的數字變量=「」? – LarsTech
@LarsTech我知道,但我試過Integer,Double和Decimal但無濟於事 – FutureProgrammer
您將字符串分配給小數。你試圖達到什麼目標?將PhoneNumber定義爲字符串或爲其指定一個數字值,例如0 –