Alex Rivera | Logout

ASP/VBScript "Gotchas"

Asked 2008-11-13T16:15:58.030
9

I'm supporting/enhancing a web application written in Classic ASP/VBScript. It has been about 10 years since I have used either in a day to day capacity. I just ran across an issue that I would consider a "gotcha" and was wondering if others had similar things that I should learn to be aware of.

My issue:
I had to convert a Column in a SQL Table from float to decimal. It turns out that decimal isn't a type that is really supported (or supported well) in vbscript. So the following code:

Dim var1, var2

var1 = rs("DecimalField1").Value
var2 = rs("DecimalField2").Value

If (var1 <> var2) Then
    'Do Something'
End If

Would blow up with a Type Mismatch error on the line:

If (var1 <> var2) Then

After much searching I found out that:

var1 = CDBL(rs("DecimalField1").Value)
var2 = CDBL(rs("DecimalField2").Value)

resolves the issue. But that didn't seem like an obvious thing and it took me a while to figure out why the heck I was getting a Type Mismatch on that line.

So my question to everyone is, what other little quirks like this have you run across? What are some things within ASP/vbscript that you would think of as "gotchas" that I should be on the lookout for?

Edit
Report

2 Answers

3

VBScript has a nastly way of letting you call subs with parenthesis if you only have 1 parameter. However, if that paramater is passed by reference, the return value does not come out if you use parenthesis:

<% OPTION EXPLICIT %>
<%

sub MakeLonger(byref something)
    something = "hello " & something 
end sub

dim msg
msg = "World"

MakeLonger(msg)
response.write msg
response.write "<br />"

MakeLonger msg
response.write msg

%>

Output is:

World 
hello World
answered 2009-01-26T20:14:47.593
0

classic ASP has a lot of gotchas if u never worked with it :) i would recommend having a look at ajaxed library which is a still maintained classic asp library. It helps you to get rid of most common gotchas when dealing with legacy apps.

answered 2009-01-27T03:43:15.210

Your Answer