Hi there

i have a problem with my little calculator project, i did everything but i got stuck at the decimal place, What i want the calculator to do is to give out an error when a user try to put in morethan one decimal point eg. 12.30.30 or 12..30.

can somebody help me please.

regards

Marcus


here is my code

Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
Else
tbcalculate.Text = tbcalculate.Text & btnOne.Text
tbChange.Clear()
End If
End Sub
Private Sub btnTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTwo.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
Else
tbcalculate.Text = tbcalculate.Text & btnTwo.Text
tbChange.Clear()
End If
End Sub
Private Sub btnThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThree.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
Else
tbcalculate.Text = tbcalculate.Text & btnThree.Text
tbChange.Clear()
End If
End Sub
Private Sub btnFour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFour.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
Else
tbcalculate.Text = tbcalculate.Text & btnFour.Text
tbChange.Clear()
End If
End Sub
Private Sub btnFive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFive.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
Else
tbcalculate.Text = tbcalculate.Text & btnFive.Text
tbChange.Clear()
End If
End Sub
Private Sub btnSix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSix.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
Else
tbcalculate.Text = tbcalculate.Text & btnSix.Text
tbChange.Clear()
End If
End Sub
Private Sub btnSeven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeven.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
Else
tbcalculate.Text = tbcalculate.Text & btnSeven.Text
tbChange.Clear()
End If
End Sub
Private Sub btnEight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEight.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
Else
tbcalculate.Text = tbcalculate.Text & btnEight.Text
tbChange.Clear()
End If
End Sub
Private Sub btnNine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNine.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
Else
tbcalculate.Text = tbcalculate.Text & btnNine.Text
tbChange.Clear()
End If
End Sub
Private Sub btnZero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZero.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
ElseIf tbcalculate.Text = Nothing Then
MsgBox("Must not have Zero dollards to change")
Else
tbcalculate.Text = tbcalculate.Text & btnZero.Text
End If
End Sub
Private Sub btnDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecimal.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
ElseIf tbcalculate.Text = Nothing Then
MsgBox("Must not have less than total amount")
Else
tbcalculate.Text = tbcalculate.Text & btnDecimal.Text
End If
DecimalFlag = True
End Sub
Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
If tbCal.Text = Nothing Then
MsgBox("Must have a TOTAL to calculate change")
ElseIf tbcalculate.Text = Nothing Then
MsgBox("Must have a Cash Amount to calculate change")
ElseIf total1 > tbcalculate.Text Then
MsgBox("Total can not be greater than Cash amount")
Else
cal1 = tbcalculate.Text - total1
tbChange.Text = FormatCurrency(cal1)
End If
tbcalculate.Text = 0
tbcalculate.Clear()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
tbChange.Clear()
tbcalculate.Text = 0
tbcalculate.Clear()
End Sub

Where is the routine which checks for multiple decimal points? Did you even attempt it?

I didn't read your code(too confusing) but whatever type of string or text you have

Dim MyString,WhatToSearch as string
if mystring.indexof(whattosearch) >= 2 then
'Code Here
end if

Try using a boolean to indicate the decimal point has been used already and ignore it if true.

Dim DecUsed As Boolean = False

    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = 190 Then
            If DecUsed Then
                e.Handled = True
                e.SuppressKeyPress = True
            Else
                DecUsed = True
            End If
        End If
    End Sub
This article has been dead for over six months. Start a new discussion instead.