Stupid question on syntax

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have the following statement and I am getting the 'Expression expected'
error on the &.

If Flds(0) = CStr(IIf(Reader.GetString(Reader.GetOrdinal("AccNam")) Is
Nothing, "", Reader.GetString(Reader.GetOrdinal("AccNam")))) AND & _
Flds(1) = CStr(IIf(Reader.GetString(Reader.GetOrdinal("AccNam")) Is
Nothing, "", Reader.GetString(Reader.GetOrdinal("AccNam")))) then

Fld is an array of strings.

How can I fix it?

Many Thanks

Regards
 
Hi

I have the following statement and I am getting the 'Expression expected'
error on the &.

If Flds(0) = CStr(IIf(Reader.GetString(Reader.GetOrdinal("AccNam")) Is
Nothing, "", Reader.GetString(Reader.GetOrdinal("AccNam")))) AND & _
   Flds(1) = CStr(IIf(Reader.GetString(Reader.GetOrdinal("AccNam"))Is
Nothing, "", Reader.GetString(Reader.GetOrdinal("AccNam")))) then

Fld is an array of strings.

How can I fix it?

Many Thanks

Regards

Wow.

I'd say refactor your code so you can understand it first, then the
error should be obvious.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
If I take out the '& _' and bring it on the same line then it works...so
something to do with &

Thanks

Regards

Hi

I have the following statement and I am getting the 'Expression expected'
error on the &.

If Flds(0) = CStr(IIf(Reader.GetString(Reader.GetOrdinal("AccNam")) Is
Nothing, "", Reader.GetString(Reader.GetOrdinal("AccNam")))) AND & _
Flds(1) = CStr(IIf(Reader.GetString(Reader.GetOrdinal("AccNam")) Is
Nothing, "", Reader.GetString(Reader.GetOrdinal("AccNam")))) then

Fld is an array of strings.

How can I fix it?

Many Thanks

Regards

Wow.

I'd say refactor your code so you can understand it first, then the
error should be obvious.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
John said:
If I take out the '& _' and bring it on the same line then it works...so
something to do with &

Yeah... I'd say 'AND & Flds(1)' wouldn't be valid in any language.
 
John said:
If I take out the '& _' and bring it on the same line then it
works...so something to do with &

Looks to me like you just need to remove the "&".

The line continuation sequence is just " _" (space, underscore) at the end
of the line, no ampersand is required.

But I do have to agree with Seth, that code is pretty hard to read!
 
John said:
If I take out the '& _' and bring it on the same line then it works...so
something to do with &

'&' is VB's string concatenation operator. '_' is used to indicate that a
statement is broken up to the text line. If I understand your code snippet
correctly, just remove the '&' operator.
 
Hi John,

If you are using VB 2008, you should use If(.....) rather than IIf(.....)
 
John,

My answer is the same as from Seth.

Why are you obfuscation your code for yourself?

It gives you not any benefit to set it in one line, beside obfuscating (only
the readable version), the dll will stay the same.

Cor
 
Back
Top