Link to home
Start Free TrialLog in
Avatar of Derek Brown
Derek BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Code problem

Can anyone tell me how this

Dim SPL As Single  'Start point left
SPL = (190 * 56.7) - ((OAM * 0.5) * S)
Box1.Left = SPL

Is different from this
Box1.Left = (190 * 56.7) - ((OAM * 0.5) * S)

Second One works but the first one doesn't.  Have I got some corruption or is it something really stupid?
Avatar of Norie

What are the values of OAM and S and how is the first one not working?
Avatar of Derek Brown


OAM is a field

Dim S as Single
S = 200
OAM = 3000

The first moves the onscreen Box1 Left possition the second does not???

Wierd eh?

I am not sure what time you have there but it is bed time for me. Is it OK if I respond again tomorrow after you have had a look at this problem?
Double-check your usage, and ensure that your control name (Box1) is correct.

Using the same values for OAM and S between the two variations, the results are identical for me. (They both shift the control to the same horizontal position, with no errors).

Not sure exactly how your testing this - but of course if you run one immediately after the other without changing OAM or S, you're not going to see the box move.
To test that thought out, try setting up another box -- Box2.

Keep your first block of code the same:
Dim SPL As Single  'Start point left
SPL = (190 * 56.7) - ((OAM * 0.5) * S)
Box1.Left = SPL

Open in new window

And modify your second to work on Box2:

Box2.Left = (190 * 56.7) - ((OAM * 0.5) * S)

Open in new window

You *should* see that both boxes move to the same horizontal position.

(btw, I tested this by arbitrarily using 1 for both OAM and S)
MX has a good point, what is Box1 and where is it located?

Also, how is the code being run?
If OAM is a field, try fully qualifying your reference to that:



Private Sub NOM_AfterUpdate()
Box10.Left = SPL
Box11.Left = (190 * 56.7) - ((1 * 0.5) * 1)
End Sub
Public Sub DrawBoxes2()
Dim SPL As Single  'Start point left
SPL = (190 * 56.7) - ((1 * 0.5) * 1)
End Sub

Box10 is Blue
Box11 is red
User generated imageUser generated image
Sceenshot A is original location
B is after event where the box10 seems to have gone to the right instead of the left
even though spl is in a public sub the variable itself is private to that sub.  It is zero elsewhere.

Instead of using a sub use a function to return spl where needed.
Avatar of mbizup
Flag of Kazakhstan image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I didn't know that. God help me I've only been doing this for 20 years. Self taught you know.

Thank you.