Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strange fenomenon

Status
Not open for further replies.

Biocide

Programmer
Oct 12, 2005
12
SE
Can someone explain this?

if textbox M0F1 is 1,2 and
textbox M1F1 is 2,2
ill get my msgbox that it is max? 2,2 - 1,2 = 1 not bigger than 1!!
if i change the numbers to 2,1 - 1,1 its ok and 2,3 - 1,3 is ok!!

Code:
Private Sub CommandButton1_Click()

'Kontrolera att användaren har matat in värden i alla textrutor
If M0F1 = Nill Then MsgBox ("Bla bla bla")
If M0F2 = Nill Then MsgBox ("ble ble ble")
If M0F3 = Nill Then MsgBox ("blu blu blu")
If M1F1 = Nill Then MsgBox ("bli bli bli")
If M1F1 = Nill Then MsgBox ("sensured")
If M1F1 = Nill Then MsgBox ("top secret")
If M1F1 = Nill Then MsgBox ("You wish")
If M1F1 = Nill Then MsgBox ("Maby if u ask")
If M1F1 = Nill Then MsgBox ("later")

'Byt ut alla . mot ,
M0F1 = Replace(M0F1, ".", ",")
M1F1 = Replace(M1F1, ".", ",")
M2F1 = Replace(M2F1, ".", ",")
M0F2 = Replace(M0F2, ".", ",")
M1F2 = Replace(M1F2, ".", ",")
M2F2 = Replace(M2F2, ".", ",")
M0F3 = Replace(M0F3, ".", ",")
M1F3 = Replace(M1F3, ".", ",")
M2F3 = Replace(M2F3, ".", ",")

'Kontrollera att det är rätt mängd
gramFärgF1 = M1F1 - M0F1
gramFärgF2 = M1F2 - M0F2
gramFärgF3 = M1F3 - M0F3
test = gramFärgF1
Min = 0.8
Max = 1
If gramFärgF1 > Max Then MsgBox ("Du har mer än 1 gram färg i form 1, gör om provet med mindre färg")
If gramFärgF1 < Min Then MsgBox ("Du har mindre än 0.8 gram färg i form 1, gör om provet med mer färg")
If gramFärgF2 > Max Then MsgBox ("Du har mer än 1 gram färg i form 2, gör om provet med mindre färg")
If gramFärgF2 < Min Then MsgBox ("Du har mindre än 0.8 gram färg i form 2, gör om provet med mer färg")
If gramFärgF3 > Max Then MsgBox ("Du har mer än 1 gram färg i form 3, gör om provet med mindre färg")
If gramFärgF3 < Min Then MsgBox ("Du har mindre än 0.8 gram färg i form 3, gör om provet med mer färg")
 

Comparing floating point values with integers can cause strange results.

If you step thru the code in debug mode, you will probably see that (M0F1 - M1F1) probably has a value like 1.00000000000000000075

You need to add a bit of code. Instead of simply using
[tt]
if Z > Max then ....
[/tt]
use something like
[tt]
if (Z - Max) > .000001 then ...
[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top