在错误检查中使用哪个循环?

时间:2014-04-19 23:22:36

标签: vb.net

我不需要答案,只是建议或提示使用何种类型的循环。如果用户在numLegal/LettercopyLegal/Letter中输入非数字值,则会使用循环。它会要求重新输入价值。这也是我的第一篇文章,所以如果我做错了,请原谅我。

我在考虑在转换用户输入后放置While循环。

    Dim numLetter, numLegal, copyLetter, copyLegal As Integer
    Const legalRate As Decimal = 0.06D, letterRate As Decimal = 0.05D, colorcopyRate As  Decimal = 0.49D, bindingRate As Decimal = 1.25D
    Dim colorcopy, binding, bistotal, total As Decimal

    'convert
    numLegal = CInt(numPagesLegalText.Text)
    numLetter = CInt(numPagesLetterText.Text)
    copyLegal = CInt(numCopiesLegalText.Text)
    copyLetter = CInt(numCopiesLetterText.Text)

    'calculate color copy
    If colorRadiobutton.Checked Then
        colorcopy = (numLegal + numLetter) * colorcopyRate
        colorcopyLabel.Text = colorcopy.ToString("c2")
    Else
        colorcopyLabel.Text = "$0.00"
    End If
    'binding button
    If bindingRadiobutton.Checked Then
        Dim numbinding As Integer = CInt(InputBox("How many sets need to be bound?"))
        binding += bindingRate * numbinding
        bindingLabel.Text = (bindingRate * numbinding).ToString("c2")
    Else
        bindingLabel.Text = "$0.00"
    End If
    'buisness cards
    If buiscardsRadiobutton.Checked = True Then

        Const rate100 As Decimal = 65D
        Const rate150 As Decimal = 55D
        Const rate200 As Decimal = 45D

        Dim buisnesscards As Integer = CInt(InputBox("How many buisness cards are needed?"))

        If buisnesscards >= 100 AndAlso buisnesscards <= 149 Then
            buisnesscardLabel.Text = rate100.ToString("c2")
            bistotal = rate100 + total
        End If
        If buisnesscards >= 150 AndAlso buisnesscards <= 200 Then
            buisnesscardLabel.Text = rate150.ToString("c2")
            bistotal = rate150 + total
        End If
        If buisnesscards > 200 Then
            buisnesscardLabel.Text = rate200.ToString("c2")
            bistotal = rate200 + total
        End If
    Else
        buisnesscardLabel.Text = "$0.00"
    End If
    total = ((numLegal * copyLegal) * legalRate) + ((numLetter * copyLetter) * letterRate) + colorcopy + binding + bistotal

    'display

    totalpriceLabel.Text = total.ToString("c2")
    copyLabel.Text = ((numLegal * copyLegal) + (numLetter * copyLetter)).ToString

0 个答案:

没有答案