very strange behavor

  • Thread starter Thread starter Trapulo
  • Start date Start date
T

Trapulo

If CStr(params(4).Value).Length = 0 Then params(4).Value = DBNull.Value

Debugging I check this:
? CStr(params(4).Value).Length = 0

False

? CStr(params(4).Value)

"3"

But executing the code params(4).Value = DBNull.Value is executed!!

p.s. Dim params(4) As SqlParameter, where sql parameter came from MS Data
access block
 
Trapulo said:
If CStr(params(4).Value).Length = 0 Then params(4).Value =
DBNull.Value

Debugging I check this:
? CStr(params(4).Value).Length = 0

False

? CStr(params(4).Value)

"3"

But executing the code params(4).Value = DBNull.Value is
executed!!

p.s. Dim params(4) As SqlParameter, where sql parameter came from MS
Data access block

Change the code from a single-line If-then to a block If-then:

If CStr(params(4).Value).Length = 0 Then
params(4).Value = DBNull.Value
end if

Check again to see if the code is /really/ executed. Sometimes the IDE
behaves as if the statement in a single-line if-then is executed, but it
isn't.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
* "Trapulo said:
If CStr(params(4).Value).Length = 0 Then params(4).Value = DBNull.Value

Debugging I check this:
? CStr(params(4).Value).Length = 0

False

? CStr(params(4).Value)

"3"

But executing the code params(4).Value = DBNull.Value is executed!!

I don't think so. The 'If' is executed, not the 'Then' "branch",
nevertheless, the whole line is marked. You can see that by using the
block 'If...Then':

\\\
If ... Then
...
End If
///
 
Yes, if I split IF..THEN in more than one row the condition in evaluated.

Bug of the ide or of the compiler.. :(
 
Back
Top