Home All Groups Group Topic Archive Search About
Author
12 Jun 2006 3:06 PM
Elena
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

Author
12 Jun 2006 3:13 PM
Ahmed
Try the following:

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


Elena wrote:
Show quoteHide quote
> 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
Author
12 Jun 2006 3:15 PM
Cor Ligthert [MVP]
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
Author
12 Jun 2006 3:17 PM
RMT
If strStat = "UNK" Or strStat = "INC" Then
    intYellow = intYellow + 1
End If




Show quoteHide quote
"Elena" <El***@discussions.microsoft.com> wrote in message
news:889C245B-A262-47B4-ABE9-1FEB8EB138BE@microsoft.com...
>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
Author
12 Jun 2006 3:17 PM
Claes Bergefall
The last if statement is incorrect. Write it like this:

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

   /claes

Show quoteHide quote
"Elena" <El***@discussions.microsoft.com> wrote in message
news:889C245B-A262-47B4-ABE9-1FEB8EB138BE@microsoft.com...
>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
Author
12 Jun 2006 3:21 PM
Elena
Thanks everyone,

That fixed it!



Show quoteHide quote
"Claes Bergefall" wrote:

> The last if statement is incorrect. Write it like this:
>
> If strStat = "UNK" Or strStat = "INC" Then
>     intYellow = intYellow + 1
> End If
>
>    /claes
>
> "Elena" <El***@discussions.microsoft.com> wrote in message
> news:889C245B-A262-47B4-ABE9-1FEB8EB138BE@microsoft.com...
> >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
>
>
>
Author
12 Jun 2006 3:57 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Elena" <El***@discussions.microsoft.com> schrieb:
>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
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
12 Jun 2006 5:02 PM
Michel Posseth [MCP]
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

>>                                   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

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]







Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht
news:uH3rYjjjGHA.456@TK2MSFTNGP05.phx.gbl...
> "Elena" <El***@discussions.microsoft.com> schrieb:
>>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
> ///
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://classicvb.org/petition/>
Author
12 Jun 2006 6:08 PM
Cor Ligthert [MVP]
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

Show quoteHide quote
"Michel Posseth [MCP]" <mic***@posseth.com> schreef in bericht
news:e5KFeJkjGHA.4044@TK2MSFTNGP03.phx.gbl...
> 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
>
>>>                                   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
>
> 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]
>
>
>
>
>
>
>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht
> news:uH3rYjjjGHA.456@TK2MSFTNGP05.phx.gbl...
>> "Elena" <El***@discussions.microsoft.com> schrieb:
>>>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
>> ///
>>
>> --
>> M S   Herfried K. Wagner
>> M V P  <URL:http://dotnet.mvps.org/>
>> V B   <URL:http://classicvb.org/petition/>
>
>
Author
12 Jun 2006 8:17 PM
Herfried K. Wagner [MVP]
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>