Global variable error

Global variable error

Post by Bryant Salu » Sat, 09 Mar 2002 04:07:51



I have a simple bit of code that uses a Glabal variable
and a Lookup to get a maximum value for a field from the
table and increment the field as records are run through
the process. I set a default value of 0 for the first
record of each run so the first record executes the
lookup. I get an error when I test it that doesn't make
sense to me.

The error is "Variable uses an Automation type not
supported in VBScript". The line number it gives is the IF
statement below. Any ideas?

Here is the code:
if DTSGlobalVariables("MaxRequestNo").Value = 0 then
  sMaxRequestNo = DTSLookups("MaxRequestNo").Execute(0) + 1
else
  sMaxRequestNo = DTSGlobalVariables("MaxRequestNo").Value
+ 1
end if

 
 
 

Global variable error

Post by Bryant Salu » Sat, 09 Mar 2002 08:10:34


I found a work around, but I don't understand why this
works...

I used CLng around the Global Variable in the IF
statement. Interestingly CInt caused an overflow error.
Any idea what is going on?

Thanks,
BKS

Quote:>-----Original Message-----
>I have a simple bit of code that uses a Glabal variable
>and a Lookup to get a maximum value for a field from the
>table and increment the field as records are run through
>the process. I set a default value of 0 for the first
>record of each run so the first record executes the
>lookup. I get an error when I test it that doesn't make
>sense to me.

>The error is "Variable uses an Automation type not
>supported in VBScript". The line number it gives is the
IF
>statement below. Any ideas?

>Here is the code:
>if DTSGlobalVariables("MaxRequestNo").Value = 0 then
>  sMaxRequestNo = DTSLookups("MaxRequestNo").Execute(0) +
1
>else
>  sMaxRequestNo = DTSGlobalVariables

("MaxRequestNo").Value

- Show quoted text -

Quote:>+ 1
>end if
>.


 
 
 

Global variable error

Post by Darren Gree » Sun, 10 Mar 2002 20:04:18




Quote:>I found a work around, but I don't understand why this
>works...

>I used CLng around the Global Variable in the IF
>statement. Interestingly CInt caused an overflow error.
>Any idea what is going on?

>Thanks,
>BKS

The VBScript sub-type integer has a smaller range than the SQL int data
type. As you have found the SQL int is equivalent to the VBScript long.

 From the MSDN library, Microsoft Office 2000/Visual Basic Programmer's
Guide, The Integer Data Types-
"The Integer and Long data types can both hold positive or negative
values. The difference between them is their size: Integer variables can
hold values between -32,768 and 32,767, while Long variables can range
from -2,147,483,648 to 2,147,483,647. "

 From SQL Server Books Online, int, bigint, smallint, and tinyint-

bigint

Integer (whole number) data from -2^63 (-9223372036854775808) through
2^63-1 (9223372036854775807). Storage size is 8 bytes.

int

Integer (whole number) data from -2^31 (-2,147,483,648) through 2^31 - 1
(2,147,483,647). Storage size is 4 bytes. The SQL-92 synonym for int is
integer.

smallint

Integer data from -2^15 (-32,768) through 2^15 - 1 (32,767). Storage
size is 2 bytes.

tinyint

Integer data from 0 through 255. Storage size is 1 byte.

--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com