Dim variable problem

C

Christina

I have the following code...

Dim a As Double
Dim b As Double
Dim L As Double
Dim q As Double
Dim r As Double
Dim s As Double
Dim t As Double
Dim u As Double

f 10100 <= Station < 11200 Or 12500 <= Station < 14040 And
Ramp = "FRANKLIN" And CutFill = "C" Then
a = 1.5
b = a
q = -0.02
r = 0.01
s = 0.33

ElseIf 10100 <= Station < 11200 Or 12500 <= Station <
14040 And Ramp = "FRANKLIN" And CutFill = "F" Then
a = 0
b = 8
q = -0.02
r = 0.01
s = -0.33
End If

My problem is that the code is not assigning the variables
b through s a value. The "a" variable works fine and is
1.5 in the immediate view as it should be. Does anyone
know why the other variable isn't working?
 
R

Robert

Try this out, this works!

Dim s_Ramp As String
Dim s_CutFill As String
Dim l_Station As Long

Dim a As Double
Dim b As Double
Dim L As Double
Dim q As Double
Dim r As Double
Dim s As Double
Dim t As Double
Dim u As Double

If (l_Station >= 10100 And l_Station >= 11200) _
Or (l_Station >= 12500 And l_Station > 14040) _
And s_Ramp = "FRANKLIN" And s_CutFill = "C" Then

a = 1.5
b = a
q = -0.02
r = 0.01
s = 0.33

ElseIf (l_Station >= 10100 And l_Station >= 11200) _
Or (l_Station >= 12500 And l_Station > 14040) _
And s_Ramp = "FRANKLIN" And s_CutFill = "F" Then

a = 0
b = 8
q = -0.02
r = 0.01
s = -0.33
End If

I believe the variable must be before the constant in an
IF statement. Let me know!
 
V

Van T. Dinh

You cannot use the logical abbreviation

A < B < C

as in Mathematics. In VBA, you need to use:

(A < B) AND (B < C)
 
C

Christina

Thanks for your help, but Ramp, Cutfull, and Station are
not variables, they are actual values entered into my form.

I also tried seperating the A<B<C TO (A<B) AND (B<C) as
was sugessted in another responce. This did not help. It
realy seems like for some reason, the variables are not
being assigned a number.
 
V

Van T. Dinh

1. Have you used the parentheses to specify *exactly* the order of
operation of ANDs and ORs in your expression? I wouldn't like to rely on
Access to work out the order of operation in a criteria like yours.

2. Note that Robert translated the ternary inequality to 2 binary
inequalities incorrectly. I hoped you didn't copy his expressions without
checking onto your new code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top