silly ASP question

W

Wendell Buckner

I call an activex object and it's returning values from a status variable
zero padded but I don't want it zero padded. for example:

<%
dim temp
temp = myObject.Status

response.write ("Here's the value " & temp)
%>


which displays:

Here's the value 00001

I want it to display

Here's the value 00001

I tried to use this to fix it but it doesn't work:


<%
dim temp
temp = str(val(myObject.Status))

response.write ("Here's the value " & temp)
%>

Why can't I use "str" or "val"? I thought I could use the vb style commands
in ASP code...

so I did this...

<%
dim temp
temp = myObject.Status
temp = temp + 0

response.write ("Here's the value " & temp)
%>

But there must be better way to format the output than this
 
R

Roland Hall

in message
: I call an activex object and it's returning values from a status variable
: zero padded but I don't want it zero padded. for example:

: <%
: dim temp
: temp = myObject.Status
: response.write ("Here's the value " & temp)
: %>
:
: which displays:
:
: Here's the value 00001
:
: I want it to display
:
: Here's the value 00001

Hmmm.. these look the same to me. Is your objective to have Here's the
value 1?

: I tried to use this to fix it but it doesn't work:
:
: <%
: dim temp
: temp = str(val(myObject.Status))
:
: response.write ("Here's the value " & temp)
: %>
:
: Why can't I use "str" or "val"? I thought I could use the vb style
commands
: in ASP code...

str is a variant at this point since it has not been assigned.

: so I did this...
:
: <%
: dim temp
: temp = myObject.Status
: temp = temp + 0
:
: response.write ("Here's the value " & temp)
: %>
:
: But there must be better way to format the output than this

Better, schmetter...but you could use this:

<%
dim temp
temp = CInt(myObject.Status)
response.write ("Here's the value " & temp)
%>

or

<%
dim temp
temp = Replace(myObject.Status),"0","")
response.write ("Here's the value " & temp)
%>

If after you assigned temp a value, you could check it to see what type of
variable it is.
Response.Write(typename(temp)) ' typename is your friend
It'll probably return 'string'.

CInt will convert it to an integer and remove the leading zeros.
Replace will remove ALL zeros, which may not be what you want.
Ex. 00010 would still return 1, instead of 10.

You could use regular expressions to truncate leading zeros but CInt should
be sufficient.

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
D

dlbjr

You may want to use CDbl(myObject.Status)
Since the number may be 6 digits do to the leading 0's.
The Integer size may be to small.

dlbjr
 
R

Roland Hall

in message : You may want to use CDbl(myObject.Status)
: Since the number may be 6 digits do to the leading 0's.
: The Integer size may be to small.

Unless the result value is greater than the integer range, then there is no
need to use the extra memory for double precision. However, if the result
was greater than an the size of an integer, the next logical type would be
long. (CLng).

Int could also be used in place of CInt.

00000000000000000000000000000000010 will still be returned as 10 with Int or
CInt, but 00000000000000000000000000000000010.9 is different between the
two. Int will return 10 because it truncates the fractional part and CInt
will return 11 because it rounds. CLng would also return 11. If he wanted
to maintain double precision then he would then want to use CDbl, which
would return 10.9.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top