Skrobotov
asked on
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("MSXML 2.ServerXM LHTTP.3.0" )
objXMLHTTP.Open sMethod, qs, false
objXMLHTTP.Send
init = CStr(objXMLHTTP.responseTe xt) ' 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'
%>
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("MSXML
objXMLHTTP.Open sMethod, qs, false
objXMLHTTP.Send
init = CStr(objXMLHTTP.responseTe
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'
%>
try Cdbl(price*1)
Can u post in
response.write shippingCharge
response.write shippingCharge
ASKER
doesn't help
what is the output of this
response.write shippingCharge
???
response.write shippingCharge
???
response.write Cdbl(Replace(shippingCharg e, vbCrLf, '')) ' Type mismatch: 'Cdbl'
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("MSXML 2.ServerXM LHTTP.3.0" )
objXMLHTTP.Open sMethod, qs, false
objXMLHTTP.Send
init = CStr(objXMLHTTP.responseTe xt) ' 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, ''))
%>
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("MSXML
objXMLHTTP.Open sMethod, qs, false
objXMLHTTP.Send
init = CStr(objXMLHTTP.responseTe
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, ''))
%>
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(shippingCharg e, vbCrLf, ''))
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(shippingCharg
ASKER
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'
It just says Microsoft VBScript runtime error '800a000d'
Type mismatch: 'Cdbl'
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.
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.
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.
Thank you.
>>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("MSXML 2.ServerXM LHTTP.3.0" )
objXMLHTTP.Open sMethod, qs, false
objXMLHTTP.Send
init = CStr(objXMLHTTP.responseTe xt) ' 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.
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("MSXML
objXMLHTTP.Open sMethod, qs, false
objXMLHTTP.Send
init = CStr(objXMLHTTP.responseTe
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.
ASKER
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'
ALL of the above solution come up with
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'Cdbl'
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.responseTe xt)
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
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.responseTe
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
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("MSXML 2.ServerXM LHTTP.3.0" )
objXMLHTTP.Open "GET", qs, False
objXMLHTTP.Send()
strReturnedData = objXMLHTTP.ResponseText()
arrData = Split(strReturnedData, vbCrLf)
Set ReturnedData = Server.CreateObject("Scrip ting.Dicti onary")
For Each DataKey In arrData
arrDataElements = Split(DataKey, "=")
ReturnedData.Add arrDataElements(0), arrDataElements(1)
Next
Response.Write(ReturnedDat a("charge" ))
<%
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("MSXML
objXMLHTTP.Open "GET", qs, False
objXMLHTTP.Send()
strReturnedData = objXMLHTTP.ResponseText()
arrData = Split(strReturnedData, vbCrLf)
Set ReturnedData = Server.CreateObject("Scrip
For Each DataKey In arrData
arrDataElements = Split(DataKey, "=")
ReturnedData.Add arrDataElements(0), arrDataElements(1)
Next
Response.Write(ReturnedDat
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.
>>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.
ASKER
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)
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)
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!!!
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!!!