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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error: type mismatch UBound

Status
Not open for further replies.

NeedHelpProgrammer

Programmer
Feb 17, 2004
9
US
I have looked over my global.asp and my add.asp.
I keep getting this same type mismatch error.

Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'UBound'
/aspApp/add.asp, line 5


This is the area of code that I keep fumbling on.

Depts = Application("Depts")
For i = 0 to UBound(Depts,2)
If cStr(Depts(0,i)) = Request.Form("DepartmentID") Then
strDept = Depts(1,i)
End IF



Isn't UBound an integer because it determines the highest possible subscript for the second dimension of the Depts array? Thus i = 0 to UBound(Dept,2) the same datatype?

I would so appreciate some ideas.

Thank you


-----------------------------------------------
Here is the whole code of global.asa

<SCRIPT LANGUAGE="VBS" RUNAT="Server">

Sub Application_OnStart()

Dim Depts()

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("employee")

sql = "SELECT ID, Department FROM Departments"
Set rsRecords = Conn.Execute(sql)

i = 0

do while not rsRecords.EOF
Redim Preserve Depts(2,i)
Depts(0, i) = rsRecords("ID")
Depts(1, i) = rsRecords("Department")
i = i + 1
rsRecords.MoveNext
loop

Application("Depts") = Depts

rsRecords.Close
Conn.Close
Set Conn = Nothing

End Sub

Sub Application_OnEnd()
Application("Message") = "Done!"

End Sub

Sub Session_OnStart()

End Sub

Sub Session_OnEnd()

End Sub

</SCRIPT>

-------------------------------------------
here is the whole section of that code in add.asp


<%
Depts = Application("Depts")
For i = 0 to UBound(Depts,2)
If cStr(Depts(0,i)) = Request.Form("DepartmentID") Then
strDept = Depts(1,i)
End IF
Next

On Error Resume Next
Dim Conn, name, dept, homePhone, ext, sql
If Request.Form("Name") <> "" Then
name = Replace(Request.Form("Name"), "'", "&#39;")
dept = Request.Form("DepartmentID")
homePhone = Request.Form("Home_Phone")
ext = Request.Form("Extension")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("employee")

sql = "INSERT INTO employee (Name, DepartmentID, Home_Phone, Extension) VALUES ("
sql = sql & "'" & name & "','" & dept & "','" & homePhone & "','"
sql = sql & ext & "')"

Conn.Execute(sql)

'Debug
'Response.Write(sql)
%>
 
Hi...
Is Department Field of table Departments and integer or String ?

----
Harsh words break no bones but they do break hearts.
E.T.
 
If Departments table is empty, global.asa code never loops through Do While stuff, Depts remains non-dimensional and UBound(Depts,2) crashes. Is that the case here?

 
Also, instead of writing your own loop to pull th data from the recordset, why not use the GetRows() method from the recordset? :)

And I agree with the others, I think the type mismatch is being caused by the Debts() variable, not the result of the UBound. maybe if you add a bolean variable to your application that would define whether or not there was any info in the Debts recordset/table.

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Hello NeedHelpProgrammer,

[1] Make sure vartype of application("depts") be 8204=8192+12, array of variant. This may be but not very likely the cause of the ubound mismatch.

[2] Could you change the runat= line and the script lines that follow to be enclosed by <% %> tag? That thing will compile last and may cause timing problem---application("depts") not being recognized before being assign to a variable of array type? Check it out.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top