|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
String, not Booleannot 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 Try the following:
> If strStat = "UNK" Or strStat = "INC" Then Elena wrote:> intYellow = intYellow + 1 > End If 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 Elena
> If strStat = "UNK" Or "INC" Then here is your boolean, probably you meanIf strStat = "UNK" Or strStat = "INC" Then even better if strStat = "UNK" OrElse strStat = "INC" Then I hope this helps, Cor 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 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 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 > > >
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/> 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 should be in my opinion>> 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 = "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/> 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/> > > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb: LOL, no, not really. I simply wanted to show the 'Select Case' alternative.> 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. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Auto-Updates using MSI
Set PrivateFont in browser richtextbox changing fontstyles for selected text is it possible to get delegates from properties directly? "Global" objects Parsing the appended data of log file in real time Control.BackColor Transparency, Control.BackColor = Color.Transparent XML-RPC Copying A Control Not As A Reference Change the rowspan, columnspan property of a button control in a TableLayoutPanel at runtime |
|||||||||||||||||||||||