We help IT Professionals succeed at work.

Code problem

Derek Brown
Derek Brown asked
on
246 Views
Last Modified: 2012-05-28
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?
Comment
Watch Question

NorieAnalyst Assistant
CERTIFIED EXPERT

Commented:
What are the values of OAM and S and how is the first one not working?

Author

Commented:
Hi
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?
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
What is Box1 ?

mx
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
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.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
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)
NorieAnalyst Assistant
CERTIFIED EXPERT

Commented:
MX has a good point, what is Box1 and where is it located?

Also, how is the code being run?
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
If OAM is a field, try fully qualifying your reference to that:

Me.OAM

or

Me!OAM

Author

Commented:
Private Sub NOM_AfterUpdate()
DrawBoxes2
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
Original PositionAfter Event
Sceenshot A is original location
B is after event where the box10 seems to have gone to the right instead of the left
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
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.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I didn't know that. God help me I've only been doing this for 20 years. Self taught you know.

Thank you.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.