We help IT Professionals succeed at work.

Convert boolean value to String

Roger Trippaers
Roger Trippaers used Ask the Experts™
on
Hello,

we want to control the IBAN bank number, with the code below we can get the (Boolean) value back as True or False, but we need to put the value in a normal value (string) to work with.

We work with ASP Classic.

Can you help us?
Thanks.
<%
dim IBANCHECK 
URLToRSS = "http://www.ibanbic.be/IBANBIC.asmx/CheckBBAN?Value="&Value&""
Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP.3.0")
xmlHttp.Open "Get", URLToRSS, false
xmlHttp.Send(null)

IBANCHECK=xmlHttp.ResponseText

Set xmlHttp = Nothing ' clear XML
%>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Hello,

I just checked and the returned XML response is:

<?xml version="1.0" encoding="UTF-8"?>
<boolean xmlns="http://tempuri.org/">false</boolean>

As you are using ResponseText property, you will probably get 'false' as a string in IBANCHECK variable anyway.

As a first attempt, have you already tried printing that value? Also try using following to be sure that it is indeed a boolean variable.

IF IBANCHECK THEN
  Response.Write("Yes it is TRUE")
ELSE
  Response.Write("No it is FALSE")
END IF

To convert it to boolean (or any intrinsic data-type for that matter) to string use CStr function as in
strIBANCHECK = CStr(IBANCHECK)

Hope it helps!
Roger TrippaersSEO consultant

Author

Commented:
We need to check if a Belgian IBAN account number is correct.

This is the url where we do the check:

http://www.ibanbic.be/IBANBIC.asmx?op=controleIBAN


When we enter a correct IBAN account number we get the value "true", so it not automatically get "false" back.

When we try your code we get the followin error:
-----------------------------------------------------------------------------
Runtimefout Microsoft VBScript error '800a000d'

Type does not match: '[string: "<?xml version="1.0" "]'

check_iban_db.asp, line 31
----------------------------------------------------------
Line 31: IF IBANCHECK THEN
SEO consultant
Commented:
We found the solution ourself, see code below:
IBANCHECK=xmlHttp.ResponseText
IBANCHECKR=Right(IBANCHECK,15)
IBANCHECKL=Left(IBANCHECKR,5)
IBANCHECKLOK=RTRIM(IBANCHECKL)
IBANCHECKLOK1=LTRIM(IBANCHECKLOK)

Open in new window

Roger TrippaersSEO consultant

Author

Commented:
found the solution ourself and submitted it for other users
Top Expert 2007

Commented:
Or this:
''
IBANCHECK = Trim(Left(Right(xmlHttp.ResponseText, 15), 5))
''

Open in new window


No objection to closure as such.

One suggestion is to implement a solution which is not error-prone. The current will fail at the slightest change in response text.

The ideal way to do it would be to load the response in the XMLDocument, search the node and then extract the value. A dedicated function would be nice to have.

Top Expert 2007

Commented:
I concur; I merely refactored the multiple lines of code into a single line as posted by rogerspain.