Public Const BatchStartPosition As Double = 11242.11
picBatch(Index).Left = 11242.11
If BatchStartPosition = picBatch(i).Left Then
MsgBox ("Batch is in start position.")
End If
The problem is the decimals: the Left property is expressed in twips which is an Integer (actually a Long).
Try 11242 and it'll work.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
Assuming that picBatch is a control, it actually shouldn't trigger - as that is not a valid value for .Left (so it gets rounded to the nearest valid position).
have you put a break point to see what is happening?
what sub is this called in?
i believe that positions of controls are set to the nearest appropriate value
Code:
Picture1.Left=11242.11
?Picture1.Left
11242
For a form, the Left and Top properties are always expressed intwips; for a control, they are measured in units depending on the coordinate system of its container. The values for these properties change as the object is moved by the user or by code. For the CommonDialog and Timer controls, these properties aren't available atrun time.
For either property, you can specify a single-precision number.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
okay here is a list of everything I tried before I posted.
I created a picturebox on my form and set it where I wanted my button "add batch" to create a batch. I took the left property of it and inserted it in my code. I thought it was weird I got a .11 at the end.
After several tries I have set debug.prints to print the left position of the batch. it shows it as 11242.11
I have changed BatchStartPosition to a double, single, long, integer.
from the information in all the replys here, why do you not change your constant to an integer (whole number, no decimal places) then your code should work
if you can not do that then round your values when you test like if picture1.left = round(batchstartposition, 0) then
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
You've found a common issue with Double and Single.. they aren't particularly accurate (and like with Date values are not actually displayed the same way they are stored), so you need a certain level of rounding to match numbers that seem to be identical. Note that it needs to be done for both sides of the comparison, so your check should be like this:
Code:
If Round(BatchStartPosition,2) = Round(CDbl(frmLaser.Line9.X1), 2) Then
(there is no need for CDbl there, as the variable is a Double already)
Note that this issue would be less likely to happen if you had declared BatchStartPosition with the same data type as the things you are storing it to and comparing it to (so Single), but you should still use rounding to be safe.