调试时,售出的汽车数量不正确. [英] The number of cars sold don't come out correct when debugging.
本文介绍了调试时,售出的汽车数量不正确.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Option Explicit On
Option Infer On
Option Strict Off
Public Class main
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Static cars1 As Integer
Static cars2 As Integer
Static cars3 As Integer
Static cars4 As Integer
Dim txtID As String
Dim txtNumberSold As Integer
txtID = ID.Text
txtNumberSold = convertintx(NumberSold.Text)
If txtID.Substring(0, 1) = "F" Or txtID.Substring(0, 1) = "f" Then
cars1 = cars1 + txtNumberSold
Button1.Text = cars1
End If
If txtID.Substring(0, 1) = "P" Or txtID.Substring(0, 1) = "p" Then
cars2 = cars2 + txtNumberSold
Button2.Text = cars2
End If
If txtID.Substring(3, 1) = "1" Then
cars3 = cars3 + txtNumberSold
Button3.Text = cars3
End If
If txtID.Substring(3, 1) = "2" Then
cars4 = cars4 + txtNumberSold
Button4.Text = cars4
End If
ID.Text = ""
NumberSold.Text = ""
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Text = "0"
Button2.Text = "0"
Button3.Text = "0"
Button4.Text = "0"
End Sub
Private Function convertintx(ByVal strx As String)
If strx = "" Then
strx = "0"
End If
Dim s As String
s = strx
Dim str(10) As String
Dim number(10) As Integer
Dim sum As Integer
sum = 0
str = Split(s, "+")
Dim i As Integer
For i = 0 To str.Length - 1
number(i) = CInt(str(i))
sum += number(i)
Next
Return sum
End Function
推荐答案
海洋,
看来您使这个问题复杂化了,但是您实际上并没有对应该做什么的想法.
请提供更多有关您要解决的问题的详细信息,给定输入的预期输出是什么,等等.
如果此时我必须给您答案,我建议简化此方法.例如,如果您实际上只有4种情况下的输入(f1,f2,p1,p2),为什么不只使用四个按钮呢?
与其在单击处理程序中创建静态变量,不如在类级别创建私有变量并确保正确初始化它们(它们将在表单持续时间内保持有效).最好用一个类来表示您的模型,尽管那可能太复杂了,无法入门.
祝你好运.
干杯.
Ocean,
It looks like you are over-complicating this problem, but you really haven''t given much idea as to what this should do.
Please give a little more detail on the problem you''re trying to solve, what your expected outputs for the given inputs would be, etc.
If I had to give you an answer at this point, I would suggest simplifying the approach. For instance, if you really only have 4 cases of input (f1, f2, p1, p2) why not just use four buttons?
Rather than creating static variables in your click handler, create private variables at the class level and make sure you initialize them correctly (they will live for the duration of your form). Better would be a class to represent your model, though that might be too complex to get you started.
Best of luck.
Cheers.
这篇关于调试时,售出的汽车数量不正确.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文