Hi! everyone i have simple mini Calculator application. I have a plusminusdot(0) CommandButton to put -ve sign, next i have plusminusdot(1) CommandButton to put period (.) sign. I have code below:
Private Sub plusminusdot_Click(Index As Integer)
If NewNum Then
Text1.Text = ""
NewNum = False
End If
If Index = 1 Then
If InStr(1, Text1.Text, ".", vbTextCompare) = 0 Then
Text1.Text = Text1.Text & "."
End If
Else
If Index = 0 Then
If Len(Text1.Text) >= 1 Then
If InStr(1, Text1.Text, "-", vbTextCompare) = 0 Then
Text1.Text = "-" & Text1.Text
Else
If InStr(1, Text1.Text, "-", vbTextCompare) = 1 Then
Text1.Text = Mid(Text1.Text, 2, Len(Text1.Text))
End If
End If
End If
End If
End If
End Sub
NewNum is Boolean datatype that will be set when a calculator takes a new number. Can anyone help understanding the above code? What is the role of InStr(), Mid(). :)
Private Sub plusminusdot_Click(Index As Integer)
If NewNum Then
Text1.Text = ""
NewNum = False
End If
If Index = 1 Then
If InStr(1, Text1.Text, ".", vbTextCompare) = 0 Then
Text1.Text = Text1.Text & "."
End If
Else
If Index = 0 Then
If Len(Text1.Text) >= 1 Then
If InStr(1, Text1.Text, "-", vbTextCompare) = 0 Then
Text1.Text = "-" & Text1.Text
Else
If InStr(1, Text1.Text, "-", vbTextCompare) = 1 Then
Text1.Text = Mid(Text1.Text, 2, Len(Text1.Text))
End If
End If
End If
End If
End If
End Sub
NewNum is Boolean datatype that will be set when a calculator takes a new number. Can anyone help understanding the above code? What is the role of InStr(), Mid(). :)