R – ASP/VBScript “Gotchas”

asp-classicdecimalvbscript

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?

Best Answer

Repeat after me: All good VB programmers use Option Explicit

It will keep you from accidentally declaring a new variable and using it - thus throwing off whatever you are doing.

Beyond that, it depends on what you're doing.

Related Topic