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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with if..else statement 1

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
I am trying to construct a string that I need to use in my if..else statment as:


aryState = array("NY","CA","FL")


if ubound(aryState) = 0 then

strNull = "(isnull(rs(1)) or rs(1) = 0)"

elseif ubound(aryState) = 1 then

strNull = "(isnull(rs(1)) or rs(1) = 0) and (isnull(rs(2)) or rs(2) = 0)"

elseif ubound(aryState) = 2 then

strNull = "(isnull(rs(1)) or rs(1) = 0) and (isnull(rs(2)) or rs(2) = 0) and (isnull(rs(3)) or rs(3) = 0)"
....

end if


strNull = "(isnull(rs(1)) or rs(1) = 0) and (isnull(rs(2)) or rs(2) = 0) and (isnull(rs(3)) or rs(3) = 0)"


if strNull then
...do something
else
...do something else
end if

and is getting syntax error.

This is just a simple example, I set my strNull variable using a for..next loop because my aryState varies from 1 to 50 elements.

Is this possible? is there any way to get around it>?

Any help will be greatly appreciated.


 
Hmm, kinda hard to understand exactly what your asking...

However, it sounds like you might need a Else If statement...

In simple code,

Code:
    if  strNull = "Something" then
       ...do something
    else if strNull = "Something else" then
       ...do something else
    else if strNull = "Something else else" then
       ...do something else else
    else
       ...do something else becuase strNull did not equal anything above.
    end if
    end if
    end if

V/r,

SPC Key
United States Army
 
thanks fopr the quick response.

Actually this is what I need the variable for:


strNull = "(isnull(rs(1)) or rs(1) = 0) and (isnull(rs(2)) or rs(2) = 0) and (isnull(rs(3)) or rs(3) = 0)"

if strNull then
...do something
else
...do something else
end if

so that it will read as:

if isnull(rs(1)) or rs(1) = 0) and (isnull(rs(2)) or rs(2) = 0) and (isnull(rs(3)) or rs(3) = 0) then

...do something
else
...do something else
end if

 
[tt]aryState = array("NY","CA","FL")

dim strNull, bNull, i
dim aryCriteria()
redim aryCriteria(ubound(aryState))

for i=0 to ubound(aryState)
aryCriteria(i)="(isnull(rs(" & (i+1) & ").value) or rs(" & (i+1) & ").value = 0)"
next
strNull=join(aryCriteria," and ")
bNull=eval(strNull)

if bNull then
'do something
else
'do something else
end if[/tt]
 
Thanks tsuji for introducing me to eval()!
Worked like a charm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top