Hi david:
It may be that you don't need to ask the user what there decimal character is.
You could obtain the current locale with the 
GetThreadLocale<http://msdn.microsoft.com/en-us/library/windows/desktop/dd318127(v=vs.85).aspx>
 function, Then you'd need to call either the 
GetLocaleInfo<http://msdn.microsoft.com/en-gb/library/windows/desktop/dd318101(v=vs.85).aspx>
 or the 
GetLocaleInfoEx<http://msdn.microsoft.com/en-gb/library/windows/desktop/dd318103(v=vs.85).aspx>
 function depending whether your running on vista and above. Finally, you need 
to look for either one of two localization constants, either 
LOCALE_SDECIMAL<http://msdn.microsoft.com/en-us/library/windows/desktop/dd373841(v=vs.85).aspx>
 or 
LOCALE_SMONDECIMALSEP<http://msdn.microsoft.com/en-gb/library/windows/desktop/dd373857(v=vs.85).aspx>.
There could be multiple characters in either of thouse constants.
The LocaleInfo object within Window-Eyes doesn't give us this information.
I hope this gives you some what of a start, if you need any more help shout up!
Cheers
Sean.
From: David [mailto:[email protected]]
Sent: 01 January 2013 19:06
To: [email protected]
Subject: Re: VBS code - floating point numbers

Bruce,
Thanks for your attempt to help. Sorry, but your sample code has two drawbacks 
- hence won't do the trick.

First of all, you have locked the decimal point character, to always be the 
period (or dot) sign - in your Replace instruction. Since the script is going 
to accept input from the user, and the user could have chosen another character 
for the decimal point - through his locale settings - I cannot lock the 
character in a Replace instruction. Unless, there would happen to be an easy 
way to determine what character the computer is using for a decimal point, at 
any given time. May very likely be new to you, but if I switch from English US 
keyboard layout on my computer, and make the Keyboard Layout any of the 
Scandinavian ones for instance, even the Del-key on the numeric keypad, will no 
longer give a period when numlock is on. So, if I set the keyboard to Danish 
for instance, and enter a number like 123.45 on the numeric keypad, the number 
that is actually being entered (and which the script will see), is 123,45. Just 
to illustrate that changing the locale setting of the computer, will result in 
the numbers being differently entered, even with the same keys. You make an 
Excel spreadsheet under English US Locale, entering some decimal numbers, they 
all will show up with the Period as a decimal point. Keep the same spreadsheet 
unaltered, but change your Locale settings to another language, and your Excel 
spreadsheet will immediately have all its numbers displaying with commas as the 
decimal point. And, at least under Windows XP, I saw a place where you could 
choose which character should be used for your decimal point, under the Locale 
settings.

Secondly, and maybe the easiest to show you, is that your sample code, simply 
makes one big number, from the original number. Maybe I wasn't all clear on 
what I want to accomplish, and so you must have misunderstood the target of the 
issue. What your sample code does, is to change the number
    123.4567890
, into
    1234567890
. But that is not what I want. Smile.

Here is a few examples. Below, on each line, I will enter two numbers. The 
first one, is the number that the script will be receiving through any kind of 
input, the second number on the line, is what I expect for a return. Hopefully, 
this will clarify what I am after.
    3.42 = 42
    3.141592 = 141592
    123.4567890 = 4567890
    5.934 = 934
    6.7812 = 7812
.

Thanks again, for giving it a try.


----- Original Message -----
From: BX<mailto:[email protected]>
To: [email protected]<mailto:[email protected]>
Sent: Tuesday, January 01, 2013 4:45 PM
Subject: Re: VBS code - floating point numbers


Hi Dave,
    Try this simple conversion method and see if it works!
        Bruce

Example Dim sdbl, dblValue
dblValue = 123.4567890
sdbl = CStr( dblValue)
Replace( sdbl, ".", "")
dblValue = CDbl( sdbl)

Sent: Tuesday, January 01, 2013 10:13 AM
Subject: Re: VBS code - floating point numbers

Thanks Bruce, for your feedback.

Now, the script will receive inputs, and it could never be told how many 
decimals will be in the incoming number. The number I gave, was just to 
illustrate. One time, you will get the number 3.42, next time 5.4495; and 
another time 123.9087654.

The ideas you outlined, will they work? Of course, I could use your approach (* 
1000000.0), but that I guess, would not work if there is only 3 or 4 decimals. 
And, what if you get a number with 10 decimals. I then would have to come up 
with a way to determine how many decimals are in the incoming number, before I 
could take your approach - wouldn't I? Or, am I missing your point.


----- Original Message -----
From: BX<mailto:[email protected]>
To: [email protected]<mailto:[email protected]>
Sent: Tuesday, January 01, 2013 3:57 PM
Subject: Re: VBS code - floating point numbers

Hi Dave,

    You just use the decimal factor, if you want to move it 3 places the use 
times 1000.
    Now to keep things in the same format make sure use use the decimal point 
all the time. Even though VB does not care, too loose in it's numbering systems.

  123.4567890 * 1000000.0

    Or a shift left would also do the same thing...

        Bruce


I have been playing for a while now, with a tricky numeric issue. Hopefully, it 
is just that I have overlooked some kind of instruction. What I am trying to 
do, is to derive the decimals, from a floating point number.

Let's for instance say, you have the number:
    123.4567890
I know, you can use the Int Or CInt instructions on this number, and it will 
return 123. That is, the digits to the left of the decimal point. But what I am 
after, is a way to have returned the digits to the right of the decimal point - 
in the example above, that would give 4567890. I really can't seem to find an 
instruction that will let me do this. Or, maybe it is named somthing, that my 
English knowledge would not have included. Smile. So if anyone out there, would 
happen to know of such an instruction or workarounds for this task, I would 
greatly appreciate your feedback.

OK, You would think, that if we did a basic piece of math, things should not 
get too complicated. So I thought, if I take my original number, and subtract 
the Int value of the number, I would end up with a simple decimal number, that 
I then could do some extra work on. Well, I tried a code like this:
X = 123.4567890
speak x -int(x)
. What I did expect, was to get the return value of "0.4567890". But, that's 
not what I get. My script will speak out the number of
    0.456789000000001
. and if you do a more direct way, like:
    speak 123.4567890 -123
; you might end up with an even less predictable number.

Well, my idea was - for a workaround - to have converted the returned value 
into a string, and then simply omitted the first two characters (which would be 
0.). Then, I could have converted the final string back to a number, and had 
the job done. Not exactly anything straight forward, but it would have been a 
workaround. Yet, long as the returned value is not as expected, that workaround 
would not be useful.

Again, is there an instruction in VBS, that will directly return only the 
digits to the right of the decimal point?

One more thing. Some of you, might be wondering, why don't I just convert the 
original number into a string, and then split by the decimal point. A code like 
this:
    x = 123.4567890
    NumString = Split(X, ".")
    Speak NumString(1)
. OK, this would work perfectly; long as we are operating numbers that follow 
English standard, with the dot-sign as the decimal point. But in other 
languages, the comma-sign is used as a decimal point. Since I want the script 
to work, no matter the locale setting of the computer, and the corresponding 
decimal point character, I would have been more satisfied with a direct 
instruction for deriving the digits to the right of the decimal point.

Hope all of this makes sense, and that someone could give me a kick in the 
right direction for a solution.

Reply via email to