我有一个重置按钮,可以这么说(它实际上是一个下拉菜单项)。当你点击它时,理论上它应该清除所有内容(列表框,文本框,标签等......)并将运行总数重置为0.
没有。我可以使用以下3中的任何一个将标签TEXT重置为0: lbl1.text =“0”或“”或String.isEmpty
但是运行计数器保留了内存中的最后一个条目,因此当我尝试启动一个新计数器时,它只是对现有计数器的新值进行处理。这不是我想要的。
例如,假设我在重置父表单之前,我的计数器是25,我的常量为5.我重置表单,一切似乎都归零。但是当我再次开始计数时,我的计数器告诉我,我的值现在是30而不是5.如果我从头开始,它应该是5。
我在这里使用模块和表单,所以我不确定从这里开始。
Private Sub ResetToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ResetToolStripMenuItem.Click
boxProducts.Items.Clear()
lblSubtotal.Text = "0"
lblTax.Text = "0"
lblShipping.Text = "0"
lblTotal.Text = "0"
End Sub
这是我的模块:
Module Module1
Const decTax As Decimal = 0.06
Dim decShipping As Decimal = 2.0
Dim decTotalTax As Decimal
Dim decTotalPrice As Decimal
Dim decTotalShipping As Decimal
Dim decSubtotal As Decimal
Dim decPrintPrice As Decimal
Dim decAudioPrice As Decimal
Function getPrintPrice(ByVal strPrintName As String) As Decimal
If strPrintName = "I Did It Your Way (Print)" Then
decPrintPrice = 11.95
ElseIf strPrintName = "The History of Scotland (Print)" Then
decPrintPrice = 14.5
ElseIf strPrintName = "Learn Calculus in One Day (Print)" Then
decPrintPrice = 29.95
ElseIf strPrintName = "Feel the Stress" Then
decPrintPrice = 18.5
End If
Return decPrintPrice
End Function
Function getAudioPrice(ByVal strAudioName As String) As Decimal
If strAudioName = "Learn Calculus in One Day (Audio)" Then
decAudioPrice = 29.95
ElseIf strAudioName = "The History of Scotland (Audio)" Then
decAudioPrice = 14.5
ElseIf strAudioName = "Learn Calculus in One Day (Audio)" Then
decAudioPrice = 29.95
ElseIf strAudioName = "Feel the Stress (Audio)" Then
decAudioPrice = 18.5
End If
Return decAudioPrice
End Function
Function getSubtotal(ByVal strName As String) As Decimal
If strName = "I Did It Your Way (Print)" Then
decSubtotal += 11.95
ElseIf strName = "The History of Scotland (Print)" Then
decSubtotal += 14.5
ElseIf strName = "The History of Scotland (Audio)" Then
decSubtotal += 14.5
ElseIf strName = "Learn Calculus in One Day (Print)" Then
decSubtotal += 29.95
ElseIf strName = "Learn Calculus in One Day (Audio)" Then
decSubtotal += 29.95
ElseIf strName = "Feel the Stress (Print)" Then
decSubtotal += 18.5
ElseIf strName = "Relaxation Techniques (Audio)" Then
decSubtotal += 11.5
End If
Return decSubtotal
End Function
Function getTotalShipping(ByVal strName As String) As Decimal
decTotalShipping += decShipping
Return decTotalShipping
End Function
Function getTax(ByVal strName As String) As Decimal
decTotalTax = decTax * decSubtotal
Return decTotalTax
End Function End Module
答案 0 :(得分:0)
Private Sub ResetToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ResetToolStripMenuItem.Click
boxProducts.Items.Clear()
lblSubtotal.Text = "0"
lblTax.Text = "0"
lblShipping.Text = "0"
lblTotal.Text = "0"
decShipping = 0
decTotalTax = 0
decTotalPrice = 0
decTotalShipping = 0
decSubtotal = 0
decPrintPrice = 0
decAudioPrice = 0
End Sub