ljaques
asked on
'IF' with 'AND'/'OR' ...
This is VERY ODD...
pos = instr(1,"HELLO WORLD","XX")
'pos will = 0 since "XX" wont be found in it
if pos > 0 or (pos > 0 and mid("HELLO WORLD",pos)="WORLD") then
'process whatever
endif
The if statement above is ILLEGAL in VB because eventhough i have a "pos > 0" for the second condition in the "if" statement it still processes the entire condition making the "mid" function invalid since pos cannot be < 1:
ILLEGAL: mid("HELLO WORLD",0)="WORLD")
This is correct but since i had the "pos > 0" at the beginning of the 2nd condtion it should not have allowed the rest of the condition to be processed thus preventing the mid() function from returning an error. I have NEVER seen any other programming language do this before. It is like vb is checking the validity of the ENTIRE line before it begins to process it. Really ODD! Is there a way around this, preferably keeping my entire conditions all in one "if" statement?
pos = instr(1,"HELLO WORLD","XX")
'pos will = 0 since "XX" wont be found in it
if pos > 0 or (pos > 0 and mid("HELLO WORLD",pos)="WORLD") then
'process whatever
endif
The if statement above is ILLEGAL in VB because eventhough i have a "pos > 0" for the second condition in the "if" statement it still processes the entire condition making the "mid" function invalid since pos cannot be < 1:
ILLEGAL: mid("HELLO WORLD",0)="WORLD")
This is correct but since i had the "pos > 0" at the beginning of the 2nd condtion it should not have allowed the rest of the condition to be processed thus preventing the mid() function from returning an error. I have NEVER seen any other programming language do this before. It is like vb is checking the validity of the ENTIRE line before it begins to process it. Really ODD! Is there a way around this, preferably keeping my entire conditions all in one "if" statement?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ljaques...
crummy hack but will keep it on one line
If pos > 0 Or (Mid("HELLO WORLD", IIf(pos, pos, 1)) = "WORLD") Then
'process whatever
End If
crummy hack but will keep it on one line
If pos > 0 Or (Mid("HELLO WORLD", IIf(pos, pos, 1)) = "WORLD") Then
'process whatever
End If
Friend Ljaques: unfortunately, this is one of the ton of stupid things Microstuff did when developed VB. The most atonishing thing I've found is the unability to use the "#" char in Format$(), as it worked since decades ago... ~~~>:(