String, not Boolean

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a piece of code that's acting funny. The variable is set as a string,
not a Boolean. The variable could be: Yes, No, Unk or INC. yet, if it's one
of the last two, it throws an error because it believes it's a Boolean. Is
there anyway to get around this? Code is below.

Thanks in Advance!
Elena



If strStat = "Yes" Then
intGreen = intGreen + 1
intSec = intSec + 1
End If
If strStat = "No" Then
intRed = intRed + 1
intSec = intSec + 1
End If
If strStat = "UNK" Or "INC" Then
intYellow = intYellow + 1
End If
 
Elena
If strStat = "UNK" Or "INC" Then

here is your boolean, probably you mean

If strStat = "UNK" Or strStat = "INC" Then
even better
if strStat = "UNK" OrElse strStat = "INC" Then

I hope this helps,

Cor
 
The last if statement is incorrect. Write it like this:

If strStat = "UNK" Or strStat = "INC" Then
intYellow = intYellow + 1
End If

/claes
 
Thanks everyone,

That fixed it!



Claes Bergefall said:
The last if statement is incorrect. Write it like this:

If strStat = "UNK" Or strStat = "INC" Then
intYellow = intYellow + 1
End If

/claes
 
Elena said:
I have a piece of code that's acting funny. The variable is set as a
string,
not a Boolean. The variable could be: Yes, No, Unk or INC. yet, if it's
one
of the last two, it throws an error because it believes it's a Boolean.
Is
there anyway to get around this? Code is below.

If strStat = "Yes" Then
intGreen = intGreen + 1
intSec = intSec + 1
End If
If strStat = "No" Then
intRed = intRed + 1
intSec = intSec + 1
End If
If strStat = "UNK" Or "INC" Then
intYellow = intYellow + 1
End If

\\\
If strStat = "UNK" OrElse strStat = "INC" Then
...
End If
///

- or -

\\\
Select Case strStat
Case...
...
Case "UNK", "INC"
...
...
End Select
///
 
Why are all the easy ones answered so frequent with exact the same answers
??

Well i am hijacking this thread because i noticed the following

Your code

should be in my opinion

If strStat = "Yes" Then
intGreen += 1
intSec += 1
elseIf strStat = "No" Then
intRed += 1
intSec += 1
elseIf strStat = "UNK" OrElse "INC" Then
intYellow+= 1
End If

why ?? in your situation we have three evaluations

or as only Herfried Noticed and showed
the in my opinion best way ( because of readability ) and optimization if
the method is called often ( case that happens most often should then be the
first case in the select case )


Select Case strStat
Case "Yes"
intGreen += 1
intSec += 1
Case "No"
intRed += 1
intSec += 1
Case "UNK", "INC"
intYellow+= 1
End Select

regards

Michel Posseth [MCP]
 
Michel,

Four of the answers where in a timespan of 8 minutes.

And from Austria comes often an Echo, that is probably because of those high
mountains there.

Cor

Michel Posseth said:
Why are all the easy ones answered so frequent with exact the same answers
??

Well i am hijacking this thread because i noticed the following

Your code

should be in my opinion

If strStat = "Yes" Then
intGreen += 1
intSec += 1
elseIf strStat = "No" Then
intRed += 1
intSec += 1
elseIf strStat = "UNK" OrElse "INC" Then
intYellow+= 1
End If

why ?? in your situation we have three evaluations

or as only Herfried Noticed and showed
the in my opinion best way ( because of readability ) and optimization if
the method is called often ( case that happens most often should then be
the first case in the select case )


Select Case strStat
Case "Yes"
intGreen += 1
intSec += 1
Case "No"
intRed += 1
intSec += 1
Case "UNK", "INC"
intYellow+= 1
End Select

regards

Michel Posseth [MCP]
 
Cor Ligthert said:
Four of the answers where in a timespan of 8 minutes.

And from Austria comes often an Echo, that is probably because of those
high mountains there.

LOL, no, not really. I simply wanted to show the 'Select Case' alternative.
 
Back
Top