PDA

View Full Version : Type Mismatch in array...


parallon
09-09-2008, 04:08 AM
Hello all. I have 3 queries in which I am trying to populate 3 different arrays with. One to get the High Level ID, and the other two get Labor and Material costs for each of the High Level IDs. When I do the just the Labor and Materials, it works fine, but once I include the third query, I get the Type Mismatch error on the line where it is creating the array. The funny thing is that it seems to loop through the first time just fine, it is on the second record when this error happens.

Here is the code: (Error is line 86 which is Dim LaborArray(200,2))


<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/mmm.asp" -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>


<%
Dim rsPackages
Dim rsPackages_cmd
Dim rsPackages_numRows

Set rsPackages_cmd = Server.CreateObject ("ADODB.Command")
rsPackages_cmd.ActiveConnection = MM_mmm_STRING
rsPackages_cmd.CommandText = "SELECT Equipment, EquipmentDesc FROM Equipment WHERE ParentId IS NULL ORDER BY Equipment ASC"
rsPackages_cmd.Prepared = true

Set rsPackages = rsPackages_cmd.Execute
rsPackages_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
rsPackages_numRows = Recordset1_numRows + Repeat1__numRows
%>


<%
Dim PackagesArray(200,2) ' Array for Graph XML data.
m=0 ' For Array Craft Label - Set array location to 0
vLaborGT = 0
vMaterialsGT = 0

Dim strHeading9 ' strHeading will be populated with Craft Codes
strHeading9 = rsPackages("Equipment").value
vEquipment = strHeading9
' ********************** FM should be $7275.00 ***************************

While ((Repeat1__numRows <> 0) AND (NOT rsPackages.EOF))
If strHeading9 <> (rsPackages("Equipment").value) Then ' If this is a NEW Craft Code, then ...
%>

<%
m=m+1
'd=d+1

PackagesArray(m,1) = strHeading9
PackagesArray(m,2) = GrandTotal

GrandTotal = 0

End If
%>

<%
' ****************** Get list of ALL Labor for current package ****************

Dim rsLabor
Dim rsLabor_cmd
Dim rsLabor_numRows

Set rsLabor_cmd = Server.CreateObject ("ADODB.Command")
rsLabor_cmd.ActiveConnection = MM_mmm_STRING

rsLabor_cmd.CommandText = "SELECT WOLabour.TotalCost AS SumOfTotalLabor, WorkOrder.Equipment, WOLabour.TransDate FROM WOLabour RIGHT JOIN WorkOrder ON WOLabour.WoNum = WorkOrder.WoNum WHERE (((WorkOrder.Equipment) LIKE '" & vEquipment & "%') AND ((WOLabour.TransDate) Between #1/1/2008# And #12/1/2008#)) ORDER BY WorkOrder.Equipment"

rsLabor_cmd.Prepared = true

Set rsLabor = rsLabor_cmd.Execute
'rsLabor_numRows = 0

Dim Repeat2__numRows
Dim Repeat2__index

Repeat2__numRows = -1
Repeat2__index = 0
rsLabor_numRows = Recordset2_numRows + Repeat2__numRows

If NOT (rsLabor.BOF AND rsLabor.EOF) Then
Dim LaborArray(200,2) ' Array for Graph XML data.
a=0 ' For Array Craft Label - Set array location to 0
'b=0 ' For Array Total Value - Set array location to 0

vLaborTotal = 0

Dim strHeading2 ' strHeading will be populated with Craft Codes
'strHeading = ""
strHeading2 = vEquipment
response.Write("strHeading2 is " & strHeading2 & "<BR>")

While ((Repeat2__numRows <> 0) AND (NOT rsLabor.EOF))

If strHeading2 <> vEquipment Then ' If this is a NEW Craft Code, then ...

response.Write(strHeading2 & " Total is " & vLaborTotal & "<BR>") ' For Testing...

a=a+1 ' Advance Array location for Craft Codes by 1
b=b+1 ' Advance Array location for Labor Cost by 1
'v=Cstr("v"&i)
LaborArray(a,1) = strHeading2 'Add current Equipment code to Array
LaborArray(a,2) = vLaborTotal ' Add Labor Cost for current Craft to Array.

vLaborTotal = 0 ' Reset Labor Cost back to '0' after populating array.

End If

vLaborTotal = round(vLaborTotal + rsLabor("SumOfTotalLabor"),2) ' Total cost for ALL labor of this Craft Code
strHeading2 = vEquipment
Response.Write(vLaborTotal & "<BR>") ' For testing individual totals
Repeat2__index=Repeat2__index+1
Repeat2__numRows=Repeat2__numRows-1
rsLabor.MoveNext()


Wend

a=a+1 ' Advance Array location for Last Craft Codes by 1
LaborArray(a,1) = strHeading2 'Add Last Craft code to Array
LaborArray(a,2) = vLaborTotal ' Add Labor Cost for Last Craft to Array.
response.Write(strHeading2 & " Labor Total is " & vLaborTotal & "<BR>") ' For Testing...

End If

%>


<%
' ' ****************** Get list of ALL Materials for current package ****************
'
Dim rsMaterials
Dim rsMaterials_cmd
Dim rsMaterials_numRows

Set rsMaterials_cmd = Server.CreateObject ("ADODB.Command")
rsMaterials_cmd.ActiveConnection = MM_mmm_STRING
rsMaterials_cmd.CommandText = "SELECT WorkOrder.Equipment, Sum(WOMaterial.Quantity*WOMaterial.UnitPrice) AS SumOfCost FROM WorkOrder LEFT JOIN WOMaterial ON WorkOrder.WoNum = WOMaterial.WoNum GROUP BY WorkOrder.Equipment, WOMaterial.UnitPrice, WOMaterial.Quantity, WOMaterial.TransDate HAVING (((WorkOrder.Equipment) Like '" & vEquipment & "%') AND ((WOMaterial.Quantity)<>0) AND ((WOMaterial.TransDate) Between #1/1/2008# And #12/31/2008#))"
rsMaterials_cmd.Prepared = true

Set rsMaterials = rsMaterials_cmd.Execute
' rsPackages_numRows = 0
'
Dim Repeat3__numRows
Dim Repeat3__index

Repeat3__numRows = -1
Repeat3__index = 0
rsMaterials_numRows = Recordset3_numRows + Repeat3__numRows

If NOT (rsMaterials.BOF AND rsMaterials.EOF) Then
Dim MaterialsArray(200,2) ' Array for Graph XML data.
x=0 ' For Array Craft Label - Set array location to 0
'y=0 ' For Array Total Value - Set array location to 0

vMaterialsTotal = 0



Dim strHeading3 ' strHeading2 will be populated with Craft Codes
'strHeading2 = ""
strHeading3 = vEquipment
response.Write("strHeading3 is " & strHeading3 & "<BR>")

While ((Repeat3__numRows <> 0) AND (NOT rsMaterials.EOF))

If strHeading3 <> vEquipment Then ' If this is a NEW Craft Code, then ...

response.Write(strHeading3 & " Total is " & vMaterialsTotal & "<BR>") ' For Testing...

x=x+1 ' Advance Array location for Craft Codes by 1
'y=y+1 ' Advance Array location for Labor Cost by 1
'v=Cstr("v"&i)
MaterialsArray(x,1) = strHeading3 'Add current Equipment code to Array
MaterialsArray(x,2) = vMaterialsTotal ' Add Labor Cost for current Craft to Array.

vMaterialsTotal = 0 ' Reset Labor Cost back to '0' after populating array.

End If


vMaterialsTotal = round(vMaterialsTotal + rsMaterials("SumOfCost"),2) ' Total cost for ALL labor of this Craft Code
strHeading3 = vEquipment
Response.Write(vMaterialsTotal & "<BR>") ' For testing individual totals
Repeat3__index=Repeat3__index+1
Repeat3__numRows=Repeat3__numRows-1
rsMaterials.MoveNext()


Wend

x=x+1 ' Advance Array location for Last Craft Codes by 1
MaterialsArray(x,1) = strHeading3 'Add Last Craft code to Array
MaterialsArray(x,2) = vMaterialsTotal ' Add Labor Cost for Last Craft to Array.
response.Write(strHeading3 & " Materials Total is " & vMaterialsTotal & "<BR>") ' For Testing...

End If

SubTotal = (vLaborTotal + vMaterialsTotal)
%>


<%
GrandTotal = round(GrandTotal + SubTotal,2) ' Total cost for ALL labor of this Craft Code
strHeading9 = rsPackages("Equipment").value
'Response.Write(vTotal & "<BR>") ' For testing individual totals

Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsPackages.MoveNext()


Wend

m=m+1 ' Advance Array location for Last Craft Codes by 1
MaterialsArray(m,1) = strHeading9 'Add Last Craft code to Array
MaterialsArray(m,2) = GrandTotal ' Add Labor Cost for Last Craft to Array.
response.Write(strHeading9 & " GrandTotal is " & GrandTotal & "<BR>") ' For Testing...
%>


</head>






<body>

<%
' XML string for the graph.

xmlStr = "<chart caption='"& vTitle & "' subCaption='" & vEquip & " | "& vWeek &"' enableRotation='1' pieYScale='60' startingAngle='345' pieSliceDepth='25' formatNumberScale='0' formatNumber='1' decimals='2' forceDecimals='1' labelSepChar=' - ' showPercentageValues='1' animation='1' showLabels='1' showValues='1' >" & vbcrlf & vbcrlf
'If Not rsLabor.EOF Then
For i=0 to UBound(LaborArray)-1
xmlStr = xmlStr & "<set label='" & LaborArray(i,1) & "' value='" & LaborArray(i,2) & "' hoverText='" & LaborArray(i,2) & "' isSliced='1' />" & vbcrlf
Next
'End If
'xmlStr = xmlStr & "<set label='Labor' value='"& vTotal &"' isSliced='1' />" & vbcrlf

xmlStr = xmlStr & "</chart>" & vbcrlf
%>

<p>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="650" HEIGHT="400" id="FusionCharts" ALIGN="">
<PARAM NAME=movie VALUE="Charts/Pie3d.swf?noCache=1&chartWidth=650&chartHeight=400">
<PARAM NAME="FlashVars" VALUE="&dataXML=<%=xmlStr%>">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<EMBED src="Charts/Pie3d.swf" FlashVars="&dataXML=<%=xmlStr%>&chartWidth=300&chartHeight=400" quality=high bgcolor=#FFFFFF WIDTH="650" HEIGHT="400" NAME="FusionCharts" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT>
</p>


<p>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="300" HEIGHT="200" ALIGN="">
<PARAM NAME=movie VALUE="Charts/SSGrid.swf?noCache=2&chartWidth=300&chartHeight=400">
<PARAM NAME="FlashVars" VALUE="&dataXML=<%=xmlStr%>">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<EMBED src="Charts/SSGrid.swf" FlashVars="&dataXML=<%=xmlStr%>&chartWidth=650&chartHeight=400" quality=high bgcolor=#FFFFFF WIDTH="300" HEIGHT="400" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT>
</p>

</body>
</html>
<%
rsPackages.Close()
Set rsPackages = Nothing
%>
<%
rsLabor.Close()
Set rsLabor = Nothing
%>
<%
rsMaterials.Close()
Set rsMaterials = Nothing
%>

Thanks,

Parallon

brazenskies
09-09-2008, 08:29 AM
have you check the data?

a typical scenario for this happening would be when you are trying to enter a textual value into a numerical equation

parallon
09-10-2008, 05:00 PM
Thanks. Actually I found that I was declaring the Array within my loop. ;o) Put it outside and all worked fine (that section at least). Now I am having a different problem. Could you check it out?

http://codingforums.com/showthread.php?p=732481#post732481

Thanks,

Parallon

parallon
09-10-2008, 05:45 PM
Never mind. Got it!

Parallon