收银机计算总额 [英] Cash Register calculating total

查看:126
本文介绍了收银机计算总额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我到目前为止的代码:



This is the code i have so far:

Dim TotalAmount As String = Nothing
    Dim NextAmount As String = Nothing
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyData.ToString.Contains("D") AndAlso IsNumeric(e.KeyData.ToString.Replace("D", Nothing)) Then
            NextAmount &= CStr(e.KeyData.ToString.Replace("D", Nothing))
        End If
        If e.KeyCode = Keys.Enter Then
            Try
                Label1.Text = "£" & (CDec(TotalAmount.ToString("D2")) + CDec(NextAmount.ToString("D2")))
                NextAmount = Nothing
            Catch ex As Exception
                MsgBox("ERROR")
            End Try
        End If
        e.Handled = True
    End Sub





它应该做的是使NextAmount当前输入的数量,例如i如果输入2367,它将输出£& 00.00 + 23.67这将是23.67英镑。

我只是得到了ERROR msgbox。



你可以帮助填充我希望每个按键都进入NextAmount,但输出中填充零;这将包括530和5.3成为£05.30



我已经尝试了几个小时但不能专注于它背后的逻辑 - 请帮助我的冷获胜大概一周不见了



谢谢



What it's supposed to do is make NextAmount the amount currently entered, such as if you enter 2367, it'll output £ & 00.00 + 23.67 which would be £23.67.
I'm just getting the ERROR msgbox.

Could you help with the padding as I want each keypress to go in NextAmount, but with padding of zeros in the output; this would include both 530 and 5.3 becoming £05.30

I've tried for hours but can't concentrate on the logic behind it- please help out as my cold won't be gone for about a week

Thanks

推荐答案

对于初学者来说

For starters
CDec(TotalAmount.ToString("D2"))

我认为应该是

CDec(TotalAmount).ToString("D2")

因为你声明 Dim TotalAmount As String



其次 D2仅允许使用整数类型,因此请尝试F2。



您还可以找到 MSDN参考资料 [ ^ ]有用

as you have declared Dim TotalAmount As String

Secondly "D2" is only allowed with integral types only so try "F2" instead.

You may also find the MSDN reference[^] useful


这篇关于收银机计算总额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆