Problems with boolean

  • Thread starter Thread starter Mehul Malhotra
  • Start date Start date
M

Mehul Malhotra

Hi all! I've just started playing around with Visual
Basic 6.0 and tried to make a calculator just for fun.
Everything works except for the decimal button which has
some serious issues!! Everytime I click the button it
will display a decimal point on the screen which is
obviously not what I want.
I used the following declaration at the beginning of the
code
Private decimalclick as Boolean

and then the procedure for the decimal button click is as
follows

Private Sub decpt_Click()

If decimalclick = False Then
display.Caption = display.Caption + "."
decimalclick = True
End If

End Sub

The logic to me is sound, but it is evident that the
decimalclick value continues to stay False, please help
me out.
Thanks alot
 
* "Mehul Malhotra said:
Hi all! I've just started playing around with Visual
Basic 6.0 and tried to make a calculator just for fun.
Everything works except for the decimal button which has
some serious issues!! Everytime I click the button it
will display a decimal point on the screen which is
obviously not what I want.
I used the following declaration at the beginning of the
code
Private decimalclick as Boolean

and then the procedure for the decimal button click is as
follows

Private Sub decpt_Click()

If decimalclick = False Then
display.Caption = display.Caption + "."
decimalclick = True
End If

Your code should work. Nevertheless, I would use '&' to concatenate
strings and write 'If Not DecimalClick Then...'.
 
.. . .
Everything works except for the decimal button

So; you don't want a[nother] decimal to appear if you already have
one in the display - how about this?:

Private Sub decpt_Click()
If Instr( display.Caption, "." ) = 0 Then
display.Caption = display.Caption & "."
Else
Beep ' ;-)
End If
End Sub

HTH,
Phill W.
 
Back
Top