-
Aug 11th, 2009, 09:26 AM
#1
Thread Starter
New Member
[RESOLVED] CDbl problem
Hi,
I'm currently having a problem with CDbl which I can't seem to solve.
I run xy.vbs with 1 argument: 0.5
Now I need to convert that argument to Double using CDbl(oArgs(0))
However, it throws: 5 instead of 0.5
The problem is that:
CDBl(0.5) = 0.5
CDBl("0.5") = 5
How can I convert my argument so it'll be handled like CDbl(0.5)
I also need this for a second CDbl conversion later in my script where I then compare both values.
The second one is extracted from a string, so kind of the same problem there.
Last edited by Tenchuu; Aug 12th, 2009 at 09:08 AM.
-
Aug 11th, 2009, 01:51 PM
#2
Re: CDbl problem
Originally Posted by Tenchuu
Hi,
I'm currently having a problem with CDbl which I can't seem to solve.
I run xy.vbs with 1 argument: 0.5
Now I need to convert that argument to Double using CDbl(oArgs(0))
However, it throws: 5 instead of 0.5
The problem is that:
CDBl(0.5) = 0.5
CDBl("0.5") = 5
How can I convert my argument so it'll be handled like CDbl(0.5)
I also need this for a second CDbl conversion later in my script where I then compare both values.
The second one is extracted from a string, so kind of the same problem there.
I tried this code.
Code:
Dim c
c = Cdbl("0.5")
c = c * 20
Wscript.Echo c
I get 10 as the output. So I do believe it works. How are you passing the value to the script?
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Aug 12th, 2009, 03:25 AM
#3
Thread Starter
New Member
Re: CDbl problem
OK, since I get 100 as an output I tried to insert "0,5". It therefore only recognises the current language format.
Lesson learnt. Gotta find a way around this since it should be neutral to the local format.
-
Aug 12th, 2009, 08:09 AM
#4
Re: CDbl problem
While this is technically for the wrong language (VB6), I suspect your problem will be solved by the advice in the article How can I handle different locales? from our Classic VB FAQs (in the FAQ forum)
-
Aug 12th, 2009, 08:28 AM
#5
Thread Starter
New Member
Re: CDbl problem
Yea this is VB, I have searched for 3 hours and didn't find any function like that for vbs, however I worked around it with a little function, even though I didn't want to do that.
Code:
Function DecimalConversion(number)
demoval = CStr(CDbl(1/2))
DecimalChar = Mid(demoval, 2, 1)
if DecimalChar = "," Then
DecimalConversion = CDbl(Replace(number, ".", ","))
End If
End Function
-
Aug 12th, 2009, 09:00 AM
#6
Re: CDbl problem
Originally Posted by Tenchuu
Yea this is VB, I have searched for 3 hours and didn't find any function like that for vbs, however I worked around it with a little function, even though I didn't want to do that.
Code:
Function DecimalConversion(number)
demoval = CStr(CDbl(1/2))
DecimalChar = Mid(demoval, 2, 1)
if DecimalChar = "," Then
DecimalConversion = CDbl(Replace(number, ".", ","))
End If
End Function
So the issue is resolved?
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Aug 12th, 2009, 09:07 AM
#7
Thread Starter
New Member
Re: CDbl problem
That's more like a workaround, but yeah, one could say it's resolved
-
Aug 12th, 2009, 11:07 AM
#8
Re: CDbl problem
Originally Posted by Tenchuu
That's more like a workaround, but yeah, one could say it's resolved
How do you pass parameters as an argument to a script, from the command line?
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Apr 22nd, 2018, 06:58 AM
#9
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|