Is there a logical explanation why the following code will not work?
I came across this problem in an app I'm working on where I have to increment a variable ('A') by .1 inside of a loop and If 'A'='B' then 'do something'. It works fine when 'B' is 1.1 or 1.2, but when it's 1.3 and above, it skips what it's suppose to do. According to Debug 'A'=1.3 and 'B'=1.3 but 'A' does not equal 'B'.
To try this simple test you'll need a Form with 2 Labels (Label1 & Label2) and a Command Button (Command1). Then click the button to add .1 to 'A'.
Option Explicit
Private A As Single
Private B As Single
Private Sub Command1_Click()
A = A + 0.1
Label1 = A
If A = B Then Beep
End Sub
Private Sub Form_Load()
A = 1
B = 1.3
Label1 = A
Label2 = B
End Sub
Any thoughts?
Thanks
I came across this problem in an app I'm working on where I have to increment a variable ('A') by .1 inside of a loop and If 'A'='B' then 'do something'. It works fine when 'B' is 1.1 or 1.2, but when it's 1.3 and above, it skips what it's suppose to do. According to Debug 'A'=1.3 and 'B'=1.3 but 'A' does not equal 'B'.
To try this simple test you'll need a Form with 2 Labels (Label1 & Label2) and a Command Button (Command1). Then click the button to add .1 to 'A'.
Option Explicit
Private A As Single
Private B As Single
Private Sub Command1_Click()
A = A + 0.1
Label1 = A
If A = B Then Beep
End Sub
Private Sub Form_Load()
A = 1
B = 1.3
Label1 = A
Label2 = B
End Sub
Any thoughts?
Thanks