![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | boolean localization problem Hi, I have found that on different languages the boolean value may differ (not the value itself - but its string representation...) For example the "IPEnabled" boolean value (see http://msdn.microsoft.com/en-us/libr...17(VS.85).aspx ) : On an english Windows installation the boolean value for "IPenabled" will be given as a string : "true" / "false" On a french Windows it will be "vrai" / "faux" ... and on a German Windows "wahr" / "falsch" .... etc. Is there a way to get a boolean value language independent (from the WMI classes), so for example -1 / 0 instead of language dependent strings ? Thank you |
My System Specs![]() |
| | #2 (permalink) |
| | Re: boolean localization problem Heinz schrieb: Quote: > Hi, > > I have found that on different languages the boolean value may differ (not > the value itself - but its string representation...) > > For example the "IPEnabled" boolean value (see > http://msdn.microsoft.com/en-us/libr...17(VS.85).aspx ) : > > On an english Windows installation the boolean value for "IPenabled" will > be given as a string : "true" / "false" > On a french Windows it will be "vrai" / "faux" ... and on a German Windows > "wahr" / "falsch" .... etc. > > Is there a way to get a boolean value language independent (from the WMI > classes), so for example -1 / 0 instead of language dependent strings ? > > Thank you > text representations are created when you cast/convert the boolean value to a string Quote: Quote: >> wscript.echo cstr(true) if you cast it - implicitly or explicitly - to a number, you'll get 0 resp. -1 Quote: Quote: >> wscript.echo True, False, CInt( True ), cInt( False ) As the strings are correct for informing a user and you don't need conversions to use booleans in expression, I wonder why this is a problem for you (just interested). |
My System Specs![]() |
| | #3 (permalink) |
| | Re: boolean localization problem Heinz, It really is a boolean. What you're seeing is an artifact of using MsgBox for output display. MsgBox coerces certain data types to localized strings. If you're worried about localization issues, I would avoid using MsgBox unless really needed for actual _choices_ to be made. Instead, use WScript.Echo. If you do need to use MsgBox - or InputBox, it has the same issues - for getting feedback from a user, coerce the value to an integer before displaying it. The value will then be rendered as a number. Demo code: dim x: x = True ' The following shows the type name, vartype, and normal representation of x: ' Boolean 11 -1 WScript.Echo "from WScript.Echo:", TypeName(x), VarType(x), x ' The following shows the localized string value for x: MsgBox x ' which is equivalent to this: WScript.Echo CStr(x) ' Since MsgBox is mangling it, no boolean coercion will help, no matter how ridiculous: MsgBox CBool(CBool(CBool(CBool(x)))) ' This, however, does work: just turn it into an integer MsgBox CInt(x) ' Note the same issues happen with InputBox: InputBox "This is x as converted by InputBox automatically: " & x InputBox "This is x pre-coerced to integer: " & CInt(x) "Heinz" <no@xxxxxx> wrote in message news:eyE5izO5JHA.1432@xxxxxx Quote: > Hi, > > I have found that on different languages the boolean value may differ (not > the value itself - but its string representation...) > > For example the "IPEnabled" boolean value (see > http://msdn.microsoft.com/en-us/libr...17(VS.85).aspx ) : > > On an english Windows installation the boolean value for "IPenabled" will > be given as a string : "true" / "false" > On a french Windows it will be "vrai" / "faux" ... and on a German Windows > "wahr" / "falsch" .... etc. > > Is there a way to get a boolean value language independent (from the WMI > classes), so for example -1 / 0 instead of language dependent strings > ? > > Thank you > > > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: boolean localization problem Alex K. Angelopoulos schrieb: Quote: > Heinz, > It really is a boolean. What you're seeing is an artifact of using > MsgBox for output display. MsgBox coerces certain data types to > localized strings. display functions dutifully convert the data to be shown to a (localized) text representation (probably by using CStr() internally). Quote: > If you're worried about localization issues, I would avoid using MsgBox > unless really needed for actual _choices_ to be made. Instead, use > WScript.Echo. communicating with a user, using "True", "Wahr", or "vrai", ... seems appropriate to me. That's why I don't like the next proposal at all. Quote: > If you do need to use MsgBox - or InputBox, it has the same issues - for > getting feedback from a user, coerce the value to an integer before > displaying it. The value will then be rendered as a number. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: boolean localization problem "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message news:4a27a45b$0$32663$9b4e6d93@xxxxxx-online.net... Quote: > Alex K. Angelopoulos schrieb: Quote: >> Heinz, >> It really is a boolean. What you're seeing is an artifact of using MsgBox >> for output display. MsgBox coerces certain data types to localized >> strings. > I would avoid words like "artifact", "coerce", or "mangling". All > display functions dutifully convert the data to be shown to a (localized) > text representation (probably by using CStr() internally). the value to a string from what I can tell. Quote: Quote: >> If you're worried about localization issues, I would avoid using MsgBox >> unless really needed for actual _choices_ to be made. Instead, use >> WScript.Echo. > WScript.Echo behaves exactly like MsgBox; so why the "instead"? When > communicating with a user, using "True", "Wahr", or "vrai", ... seems > appropriate to me. That's why I don't like the next proposal at all. x=true WScript.Echo x The reason I recommended the coercion wasn't because it's "always better", but because Heinz wanted output that was in the form of -1/0 - and that gets it for him. Quote: Quote: >> If you do need to use MsgBox - or InputBox, it has the same issues - for >> getting feedback from a user, coerce the value to an integer before >> displaying it. The value will then be rendered as a number. > [...] |
My System Specs![]() |
| | #6 (permalink) |
| | Re: boolean localization problem "ekkehard.horner" <ekkehard.horner@xxxxxx> schrieb im Newsbeitrag news:4a279578$0$32676$9b4e6d93@xxxxxx-online.net... Quote: > Heinz schrieb: Quote: >> Hi, >> >> I have found that on different languages the boolean value may differ >> (not the value itself - but its string representation...) >> >> For example the "IPEnabled" boolean value (see >> http://msdn.microsoft.com/en-us/libr...17(VS.85).aspx ) : >> >> On an english Windows installation the boolean value for "IPenabled" >> will be given as a string : "true" / "false" >> On a french Windows it will be "vrai" / "faux" ... and on a German >> Windows "wahr" / "falsch" .... etc. >> >> Is there a way to get a boolean value language independent (from the WMI >> classes), so for example -1 / 0 instead of language dependent >> strings ? >> >> Thank you >> > A boolean value is either True or False. The language specific > text representations are created when you cast/convert the boolean > value to a string > Quote: Quote: > >> wscript.echo cstr(true) > > if you cast it - implicitly or explicitly - to a number, you'll get > 0 resp. -1 > Quote: Quote: > >> wscript.echo True, False, CInt( True ), cInt( False ) > > As the strings are correct for informing a user and you don't need > conversions to use booleans in expression, I wonder why this is > a problem for you (just interested). > the problem is (or was) that I write the result of a boolean variable like "IPEnabled" to a textfile - so in the textfile I get either true","false" - "wahr","falsch" - "vrai","faux" etc. The problem starts when I read this textfile into an application and try to determine whether this boolean was true or false... But CInt(boolean) does the trick - instead of a text it writes "-1" or "0" to the textfile (ok... this is a string, too.... but it is not language dependent and I can convert it to a number :-) Actually it is easy... seems that I had not enough breakfast coffee this moring :-) thank your for the help |
My System Specs![]() |
| | #7 (permalink) |
| | Re: boolean localization problem Alex K. Angelopoulos schrieb: Quote: > > > "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message > news:4a27a45b$0$32663$9b4e6d93@xxxxxx-online.net... Quote: >> Alex K. Angelopoulos schrieb: Quote: >>> Heinz, >>> It really is a boolean. What you're seeing is an artifact of using >>> MsgBox for output display. MsgBox coerces certain data types to >>> localized strings. >> I would avoid words like "artifact", "coerce", or "mangling". All >> display functions dutifully convert the data to be shown to a (localized) >> text representation (probably by using CStr() internally). > OK, artifact is a _bad_ word here; but not coerce. MsgBox really is > coercing the value to a string from what I can tell. > but I still think, MsgBox does the right thing without unduly force to represent a boolean by a (localized) "True" or "False". Quote: Quote: Quote: >>> If you're worried about localization issues, I would avoid using >>> MsgBox unless really needed for actual _choices_ to be made. Instead, >>> use WScript.Echo. >> WScript.Echo behaves exactly like MsgBox; so why the "instead"? When >> communicating with a user, using "True", "Wahr", or "vrai", ... seems >> appropriate to me. That's why I don't like the next proposal at all. > Exactly? > x=true > WScript.Echo x WScript.Echo Result, Expected, CStr( Result = Expected ) I should have known better. So I have to take back my "All display functions ..." statement also. Some functions/subs - notably WScript.Echo - misbehave. Thanks for pointing out my mistake. Quote: > > The reason I recommended the coercion wasn't because it's "always > better", but because Heinz wanted output that was in the form of -1/0 - > and that gets it for him. > Quote: Quote: >>> If you do need to use MsgBox - or InputBox, it has the same issues - >>> for getting feedback from a user, coerce the value to an integer >>> before displaying it. The value will then be rendered as a number. >> [...] |
My System Specs![]() |
| | #8 (permalink) |
| | Re: boolean localization problem Inline - you can sort of recant your mistake ; ) "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message news:4a27b378$0$32674$9b4e6d93@xxxxxx-online.net... Quote: > Alex K. Angelopoulos schrieb: Quote: >> >> "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message >> news:4a27a45b$0$32663$9b4e6d93@xxxxxx-online.net... Quote: >>> Alex K. Angelopoulos schrieb: >>>> Heinz, >>>> It really is a boolean. What you're seeing is an artifact of using >>>> MsgBox for output display. MsgBox coerces certain data types to >>>> localized strings. >>> >>> I would avoid words like "artifact", "coerce", or "mangling". All >>> display functions dutifully convert the data to be shown to a >>> (localized) >>> text representation (probably by using CStr() internally). >> OK, artifact is a _bad_ word here; but not coerce. MsgBox really is >> coercing the value to a string from what I can tell. >> > below), > but I still think, MsgBox does the right thing without unduly force to > represent a boolean by a (localized) "True" or "False". to the underlying data, it's simply being rendered as a localized string - like dates. Quote: Quote: Quote: >>>> If you're worried about localization issues, I would avoid using >>>> MsgBox unless really needed for actual _choices_ to be made. Instead, >>>> use WScript.Echo. >>> >>> WScript.Echo behaves exactly like MsgBox; so why the "instead"? When >>> communicating with a user, using "True", "Wahr", or "vrai", ... seems >>> appropriate to me. That's why I don't like the next proposal at all. >> Exactly? >> x=true >> WScript.Echo x > You are right. Having written tons of lines like > > WScript.Echo Result, Expected, CStr( Result = Expected ) > > I should have known better. So I have to take back my "All display > functions ..." statement also. Some functions/subs - notably > WScript.Echo - misbehave. > > Thanks for pointing out my mistake. like MsgBox, stringing together multiple elements with & - which gives us the same behavior, two-state value rendered as a localized string representation: WScript.Echo true & vbNullString |
My System Specs![]() |
| | #9 (permalink) |
| | Re: boolean localization problem Heinz schrieb: Quote: > "ekkehard.horner" <ekkehard.horner@xxxxxx> schrieb im Newsbeitrag > news:4a279578$0$32676$9b4e6d93@xxxxxx-online.net... Quote: >> Heinz schrieb: Quote: >>> Hi, >>> >>> I have found that on different languages the boolean value may differ >>> (not the value itself - but its string representation...) Quote: Quote: >> As the strings are correct for informing a user and you don't need >> conversions to use booleans in expression, I wonder why this is >> a problem for you (just interested). Quote: > the problem is (or was) that I write the result of a boolean variable like > "IPEnabled" to a textfile - so in the textfile I get either > true","false" - "wahr","falsch" - "vrai","faux" etc. > The problem starts when I read this textfile into an application and try to > determine whether this boolean was true or false... > > But CInt(boolean) does the trick - instead of a text it writes "-1" or > "0" to the textfile (ok... this is a string, too.... but it is not language > dependent and I can convert it to a number :-) [...] Quote: > thank your for the help |
My System Specs![]() |
| | #10 (permalink) |
| | Re: boolean localization problem Alex K. Angelopoulos schrieb: Quote: > Inline - you can sort of recant your mistake ; ) > > "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message > news:4a27b378$0$32674$9b4e6d93@xxxxxx-online.net... > Quote: >> Alex K. Angelopoulos schrieb: Quote: >>> >>> "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message >>> news:4a27a45b$0$32663$9b4e6d93@xxxxxx-online.net... >>>> Alex K. Angelopoulos schrieb: >>>>> Heinz, >>>>> It really is a boolean. What you're seeing is an artifact of using >>>>> MsgBox for output display. MsgBox coerces certain data types to >>>>> localized strings. >>>> >>>> I would avoid words like "artifact", "coerce", or "mangling". All >>>> display functions dutifully convert the data to be shown to a >>>> (localized) >>>> text representation (probably by using CStr() internally). >>> >>> OK, artifact is a _bad_ word here; but not coerce. MsgBox really is >>> coercing the value to a string from what I can tell. >>> >> below), >> but I still think, MsgBox does the right thing without unduly force to >> represent a boolean by a (localized) "True" or "False". > Good point, actually. Probably the best word is "render" - nothing > happens to the underlying data, it's simply being rendered as a > localized string - like dates. Quote: Quote: Quote: >>>>> If you're worried about localization issues, I would avoid using >>>>> MsgBox unless really needed for actual _choices_ to be made. >>>>> Instead, use WScript.Echo. >>>> >>>> WScript.Echo behaves exactly like MsgBox; so why the "instead"? When >>>> communicating with a user, using "True", "Wahr", or "vrai", ... seems >>>> appropriate to me. That's why I don't like the next proposal at all. >>> >>> Exactly? >>> x=true >>> WScript.Echo x >> You are right. Having written tons of lines like >> >> WScript.Echo Result, Expected, CStr( Result = Expected ) >> >> I should have known better. So I have to take back my "All display >> functions ..." statement also. Some functions/subs - notably >> WScript.Echo - misbehave. >> >> Thanks for pointing out my mistake. > I changed my mind while you were posting. People tend to use > WScript.Echo like MsgBox, stringing together multiple elements with & - > which gives us the same behavior, two-state value rendered as a > localized string representation: > > WScript.Echo true & vbNullString you'll have to think about that when using Join too. Thanks again for setting me straight. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| When and how to set a boolean variable to true? | .NET General | |||
| Boolean searchs in Photo Gallery? | Vista file management | |||
| Is possible to Boolean filters like author AND NOT in Win Pictures | Vista music pictures video | |||
| Any possibility for boolean operators in message rules? | Vista mail | |||