Can't convert Cstr(number) to Cdbl(number)

Please answer the following question before I got brain damage:
The code above sends reques to script and returns cost of shipping, number of days, and error/ok in format: charge=769.65 days=4 err_msg=OK
After each value follow special characters Chr(13) and Chr(10). The code succesfully filters the needed value, (I need to filter only the charge and store it as CDbl). However, when I try to dblCharge = Cdbl(strCharge) it comes up with Type mismatch.

<%
Dim objXMLHTTP
Dim sURL
Dim qs
Dim sMethod

qs = "http://drc.edeliver.com.au/rateCalc.asp?Height=100&Length=100&Width=100&Weight=20000&Pickup_Postcode=4152&Destination_Postcode=3333&Country=AU&Service_Type=STANDARD&Quantity=21"

sMethod = "GET"
set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
objXMLHTTP.Open sMethod, qs, false
objXMLHTTP.Send
 
init = CStr(objXMLHTTP.responseText)                                     ' Unformatted, unfiltered return
aa = Replace(init, "charge=", "", 1, -1, 1) + " "                  ' Removes charge=
bb = Replace(aa, "days=", "", 1, -1, 1) + " "                        ' Removes days=
c = CStr(Replace(bb, "err_msg=", "", 1, -1, 1)) + " "            ' Removes err_msg
price = Cstr(Left(c, 5))                                                      ' Filters the charge value
days_pr = Left(c, 9)                                                            ' Filters the days value
days = Right (days_pr, 2)                                                      ' Filters the days value too

                        price = Replace(price, Chr(32), "")                  ' Removes formatting characters
                price = Replace(price, Chr(09), "")
                price = Replace(price, Chr(13), "")
                price = Replace(price, Chr(10), "")
               
shippingCharge            = CStr(price)

'response.write CStr(price)                                                        ' Will show what I want
response.write Cdbl(shippingCharge)                                      ' Type mismatch: 'Cdbl'

%>
LVL 2
SkrobotovAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rohanbairat3Commented:
try Cdbl(price*1)
rohanbairat3Commented:
Can u post in

response.write shippingCharge
SkrobotovAuthor Commented:
doesn't help
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

rohanbairat3Commented:
what is the output of this

response.write shippingCharge

???
Anthony PerkinsCommented:
response.write Cdbl(Replace(shippingCharge, vbCrLf, ''))                                ' Type mismatch: 'Cdbl'

Anthony PerkinsCommented:
It would probably help also, if you assign a value to shippingCharge in the first place or use a variable that has been assigned the value :)

As in:

<%
Dim objXMLHTTP
Dim sURL
Dim qs
Dim sMethod

qs = "http://drc.edeliver.com.au/rateCalc.asp?Height=100&Length=100&Width=100&Weight=20000&Pickup_Postcode=4152&Destination_Postcode=3333&Country=AU&Service_Type=STANDARD&Quantity=21"

sMethod = "GET"
set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
objXMLHTTP.Open sMethod, qs, false
objXMLHTTP.Send
 
init = CStr(objXMLHTTP.responseText)                               ' Unformatted, unfiltered return
aa = Replace(init, "charge=", "", 1, -1, 1) + " "               ' Removes charge=
bb = Replace(aa, "days=", "", 1, -1, 1) + " "                    ' Removes days=
c = CStr(Replace(bb, "err_msg=", "", 1, -1, 1)) + " "          ' Removes err_msg
price = Cstr(Left(c, 5))                                             ' Filters the charge value
days_pr = Left(c, 9)                                                  ' Filters the days value
days = Right (days_pr, 2)                                             ' Filters the days value too

                    price = Replace(price, Chr(32), "")               ' Removes formatting characters
                price = Replace(price, Chr(09), "")
                price = Replace(price, Chr(13), "")
                price = Replace(price, Chr(10), "")
               
shippingCharge          = CStr(price)

'response.write CStr(price)                                               ' Will show what I want
response.write Cdbl(Replace(price, vbCrLf, ''))                                
%>
Anthony PerkinsCommented:
Never mind, please ignore my last comment, I see where you are assigning the value to shippingCharge.

So all you need to do is change:
price = Cstr(Left(c, 5))                                             ' Filters the charge value
...
response.write Cdbl(shippingCharge)

To:
price = Cstr(Left(c, 6))                                             ' Filters the charge value
...
response.write Cdbl(Replace(shippingCharge, vbCrLf, ''))
SkrobotovAuthor Commented:
Thank you for your comments, but none of the above helped, I am still figuring out solution

It just says Microsoft VBScript runtime error '800a000d'

Type mismatch: 'Cdbl'

gomikocharCommented:
Hi Skrobotov

IMO, the actual way to get the data you are trying to extract is as follows:

Dim init
Dim temp1
Dim aa
Dim price
Dim days
Dim errmsg

  ' this is how receive the formatted data (if I'm not wrong):
  init = "charge=769.65" + vbCrLf + "days = 4" + vbCrLf + "err_msg = OK"

  ' extract price
  aa = Replace(init, "charge=", "", 1, -1, 1)
  temp1 = InStr(aa, vbLf)        ' NOTE: its vbLF and not vbCRLF
  price = CDbl(Left(aa, temp1 - 2))

  ' extract days
  aa = Mid(aa, temp1 + 1)
  aa = Replace(aa, "days = ", "", 1, -1, 1)
  temp1 = InStr(aa, vbLf)
  days = CLng(Left(aa, temp1 - 2))

  ' extract error message
  aa = Mid(aa, temp1 + 1)
  errmsg = Replace(aa, "err_msg = ", "", 1, -1, 1)

Waiting for your response...

Thank you.
gomikocharCommented:
Sorry about a mistake in my previous post, you'll have to replace vbLF with CHR(10) to make it work in VBScript I guess.

Thank you.
Anthony PerkinsCommented:
>>Thank you for your comments, but none of the above helped, I am still figuring out solution<<
If you had taken the time to test my solution you would have got a Syntax Error not a Type Mismatch.  

Do yourself a favor and test this out (this works for me):

<%
Dim objXMLHTTP
Dim sURL
Dim qs
Dim sMethod

qs = "http://drc.edeliver.com.au/rateCalc.asp?Height=100&Length=100&Width=100&Weight=20000&Pickup_Postcode=4152&Destination_Postcode=3333&Country=AU&Service_Type=STANDARD&Quantity=21"

sMethod = "GET"
set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
objXMLHTTP.Open sMethod, qs, false
objXMLHTTP.Send
 
init = CStr(objXMLHTTP.responseText)                               ' Unformatted, unfiltered return
aa = Replace(init, "charge=", "", 1, -1, 1) + " "               ' Removes charge=
bb = Replace(aa, "days=", "", 1, -1, 1) + " "                    ' Removes days=
c = CStr(Replace(bb, "err_msg=", "", 1, -1, 1)) + " "          ' Removes err_msg
price = Cstr(Left(c, 6))                                             ' Filters the charge value
days_pr = Left(c, 9)                                                  ' Filters the days value
days = Right (days_pr, 2)                                             ' Filters the days value too

                    price = Replace(price, Chr(32), "")               ' Removes formatting characters
                price = Replace(price, Chr(09), "")
                price = Replace(price, Chr(13), "")
                price = Replace(price, Chr(10), "")
               
shippingCharge          = CStr(price)

'response.write CStr(price)                                               ' Will show what I want
response.write Cdbl(ShippingCharge)

%>

Having said that, there are better ways of skinning this cat.

SkrobotovAuthor Commented:
I had syntax error but than I replaced '' to ""

ALL of the above solution come up with

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'Cdbl'
deighcCommented:
The unprocessed output looks like this:

charge=769.65
days=4
err_msg=OK

So the easiest way to get the 'charge' value would be to split the string on the vbcrlf character, the replace "charge=" with nothing:

' split the output (this gives you an array of lines)
init = CStr(objXMLHTTP.responseText)  
arrLines = split(init, vbcrlf)
' now get the numeric info from the first line of text
aa = cdbl(replace(arrLines(0), "charge=", ""))

BUT this will only work if your operating system uses the . character as the decimal seperator. It it uses something different then you need an additional step of replacing the . with whatever character is used as the decimal seperator
AlfaNoMoreCommented:
This would be my preferred option:

<%
Dim objXMLHTTP
Dim sURL
Dim qs
Dim sMethod
Dim strReturnedData
Dim arrData, arrDataElements
Dim ReturnedData

qs = "http://drc.edeliver.com.au/rateCalc.asp?Height=100&Length=100&Width=100&Weight=20000&Pickup_Postcode=4152&Destination_Postcode=3333&Country=AU&Service_Type=STANDARD&Quantity=21"

set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
objXMLHTTP.Open "GET", qs, False
objXMLHTTP.Send()

strReturnedData = objXMLHTTP.ResponseText()
arrData = Split(strReturnedData, vbCrLf)
Set ReturnedData = Server.CreateObject("Scripting.Dictionary")

For Each DataKey In arrData
   arrDataElements = Split(DataKey, "=")
   ReturnedData.Add arrDataElements(0), arrDataElements(1)
Next


Response.Write(ReturnedData("charge"))
Anthony PerkinsCommented:
deighc,

>>BUT this will only work if your operating system uses the . character as the decimal seperator.<<
Good point and if the questioner uses a comma for the decimal place, would explain why I have no problems with the code and the questioner does.
SkrobotovAuthor Commented:
AlfaNoMore,

I replaced objXMLHTTP.ResponseText() to objXMLHTTP.ResponseText and it now gives me this error:

Microsoft VBScript runtime error '800a0009'
Subscript out of range: '[number: 0]'

on line where   ReturnedData.Add arrDataElements(0), arrDataElements(1)

SkrobotovAuthor Commented:
deighc,

Thanks for showing the better way to split it, bu I still have Type Mismatch error

Could this be some sort of bug in ASP itself? I'm stuck. I just have to find any possible way to get this value out
deighcCommented:
What are the language settings on your server?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SkrobotovAuthor Commented:
deighc,

Thanks for solving this promlem, I had Russian language set for all non-unicode programs, I changed it to english and it worked!

Thanks everyone!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.