Solved

Long Dim error in classic ASP code

Posted on 2009-04-10
7
682 Views
Last Modified: 2012-05-06
In classic asp, I am trying to add 32813 + 8000 together and store it into a variabl - because it is over 32767, it is rolling the answer to 42813 instead of 112813.. so I'm trying to declare a LONG variable to handle it, but I'm getting an error trying to declare a long variable:

Microsoft VBScript compilation error '800a0401'
Expected end of statement
/resmgr/test_long.asp, line 8
Dim NewI as Long
---------^

HELP! Can someone help me figure out how I can do this?

<%@ Language=VBScript %>

<% Option Explicit %>
 

<!--#include file="loggedin.asp"-->

<!--#include file="dsn.asp"-->

<%
 

Dim NewI as Long

Dim ThisI

Dim iList
 

NewI = 32813

response.write "invoice=" & NewI
 

thisI = clng(NewI) + 8000
 

response.write "<br>thisI=" & thisI

%>

Open in new window

0
Comment
Question by:bawalker
7 Comments
 
LVL 5

Assisted Solution

by:Aanvik
Aanvik earned 50 total points
ID: 24118294
Don;t use As long.

Try this and it should work.
Dim NewI
Dim ThisI
Dim iList
0
 

Author Comment

by:bawalker
ID: 24118362
If I remove the "as Long" it gets me back to my original problem where trying to add 32813 + 8000 and save it into a variable gives me the wrong answer..  I need to store the answer in a variable somehow.. how can I do that and get the correct answer?
0
 

Author Comment

by:bawalker
ID: 24118426
Here is my latest code - and here is the result:

Starting number = 32813
32813 + 8000 = 40813
<%@ Language=VBScript %>

<% Option Explicit %>
 

<!--#include file="loggedin.asp"-->

<!--#include file="dsn.asp"-->

<%
 

Dim NewI

Dim ThisI

Dim iList
 

NewI = 32813

response.write "Starting number = " & NewI
 

thisI = clng(NewI) + 8000
 

response.write "<br>32813 + 8000 = " & thisI

%>

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Accepted Solution

by:
spprivate earned 100 total points
ID: 24118712
Dim i
Dim s

i=CLng(32813)
s=i+CLng(8000)
Response.Write(s)

THis works correctly
0
 
LVL 15

Expert Comment

by:spprivate
ID: 24118718
Infact your result is correct.So what is the issue?
0
 
LVL 14

Assisted Solution

by:pteranodon72
pteranodon72 earned 100 total points
ID: 24119112
spprivate is right:
32813 + 8000 = 42813

You might expect
32813 + 80000 = 112813

I think you just have a typo in your constant.
A rollover issue would have given you a negative result.

pT

0
 

Author Closing Comment

by:bawalker
ID: 31569022
OMG - guess that's what I get for staring at code for too long - LOL - after changing from CINT to CLNG, I had fixed the problem and didn't even realize it - you are all right I accidentally thought it should be 112813 - what a difference a zero can make :-)  Thx to all of you - great teamwork!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now