Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable uses an Automation type not supported in VBScript 1

Status
Not open for further replies.

TwoOdd

Programmer
Sep 10, 2003
196
CL
I'm getting the Error Message (see subject) on this function when varNumber actually equals an integer.

Can someone help me on this?

Here is my Function:
Code:
Function CheckInt(varNumber)
	On Error Resume Next
	Response.Write "Number To Check:" & varNumber & "<br>"
	If Err.Number <> 0 Then
		Response.Write "Error Before Check<br>"
	Else
		Response.Write "No Error Before Check<br>"
	End If
	
	CInt(varNumber)
	
	If Err.Number <> 0 Then
		Response.Write "Error After Check<br>"
		CheckInt = "No"
	Else
		Response.Write "No Error After Check<br>"
		CheckInt = "Yes"
	End If
	Response.Write "Error Desc: " & Err.Description & "<br>"
End Function

TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
>CInt(varNumber)
The "C" stands for conversion or convert-to. Its work is not "checking" the variable type.

[1] If you want to convert, then you put up a container (a variable) to hold the result of the conversion.
[tt] dim n
n=CInt(varNumber)[/tt]

[2] If you want to checking integer type, use typename().
[tt] dim r
r=typename(varNumber) 'for number, r be Integer, Double etc[/tt]
 
Thank you.

I realized what I was doing about the time you answered the question.

I was about to do a search on how to check the value type, but you answered that as well - thus a star for you! Saved me another half hour of searching.

Thanks again.

TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
Well, I couldn't get the typename function to give any other value than 'IStringType'.

So, I figured out a way to check if the submitted value is an integer:

Code:
Function CheckInt(varNumber)
	Dim x
	If IsNumeric(varNumber) Then
		x = varNumber - Cint(varNumber)
	Else
		x = 1
	End If
	
	If x <> 0 Then
		CheckInt = "No"
	Else
		CheckInt = "Yes"
	End If
End Function

I need to check for a numeric value first. Then subtract the integer value of the number submitted from the number itself - if the number is anything but an integer, the result(x) will NOT equal zero.

I then just check if x = 0 or not. If x = 0, then the value is an integer.

Note: if the value submitted was not numeric, I set the value of x = 1 and thus it is not an integer.

Hope this helps someone else.

TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top