多计算VB.NET
嗨朋友们,我在vb.net中比较新鲜,当我启动带有访问数据库的vb.net我的第一个应用程序启动错误实际上我正在尝试多个计算数量*率=小计和总数并在访问数据库中插入此数据但是有些事情是错的
我尝试过的事情:
Private Sub BtnCal_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理BtnCal.Click
Dim QtyInteger,Qty2Integer As Integer
Dim RateDecimal,TotalDecimal,Rate2Decimal,Total2Decimal作为十进制
QtyInteger = Integer.Parse(Txt1.Text)
Qty2Integer = Integer.Parse(Txt4.Text)
RateDecimal = Decimal.Parse(Txt2.Text)
Rate2Decimal = Decimal.Parse(Txt5.Text)
TotalDecimal = QtyInteger * RateDecimal
Total2Decimal = Qty2Integer * Rate2Decimal
Txt3.Text = TotalDecimal.ToString(N)
Txt6.Text = Total2Decimal.ToString(N)
End Sub
hi Friends,i am fresher in vb.net ,when i am starting vb.net with access database my first application start error actually i am trying multiple calculation Qty* rate= subtotal and total and insert this data in access db but some things are wrong
What I have tried:
Private Sub BtnCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCal.Click
Dim QtyInteger, Qty2Integer As Integer
Dim RateDecimal, TotalDecimal, Rate2Decimal, Total2Decimal As Decimal
QtyInteger = Integer.Parse(Txt1.Text)
Qty2Integer = Integer.Parse(Txt4.Text)
RateDecimal = Decimal.Parse(Txt2.Text)
Rate2Decimal = Decimal.Parse(Txt5.Text)
TotalDecimal = QtyInteger * RateDecimal
Total2Decimal = Qty2Integer * Rate2Decimal
Txt3.Text = TotalDecimal.ToString("N")
Txt6.Text = Total2Decimal.ToString("N")
End Sub
首先更改所有内容的名称:帮自己一个忙,并停止使用Visual Studio默认名称 - 你可能还记得TextBox8是手机号码今天,但是当你必须在三周内修改它时,你会吗?使用描述性名称 - 例如tbMobileNo - 您的代码变得更容易阅读,更自我记录,更易于维护 - 并且编码速度更快,因为Intellisense可以通过三次击键来tbMobile,其中TextBox8需要思考大概和8次击键...
然后,开始记住用户犯错误:输入错误。
当你使用Integer.Parse时如果您提供的字符串不是整数,它将抛出异常 - 因此请改用TryParse,并向用户报告问题:
Start by changing the names of everything: do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...
Then, start remembering that users make mistakes: they type wrong.
When you use Integer.Parse it will throw an exception if the string you provide isn't an integer - so use TryParse instead, and report problems to the user:
Dim QtyInteger As Integer
If Not Integer.tryParse(Txt1.Text, QtyInteger) Then
' Report problem to user
...
Return
End If
如果这不能解决您的问题,那么您需要更详细地解释您正在做的导致问题的原因,你得到的任何错误,以及你没想到的错误,或者没有做到的错误!
If that doesn't fix your problem, then you need to explain in a lot more detail exactly what you are doing that causes the problem, any error you get, and what it does that you didn't expect, or doesn't do that you did!