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

type mismatch when declaring array

Status
Not open for further replies.

cleavitt

Programmer
Jun 25, 2002
3
CA
Hi, I am getting a type mismatch error when declaring an array, the line is:

dim total_tons(7)

I need it to hold 7 floats/doubles. I have checked that I am not already using that name, and have tried renaming it too.

Can anyone help!?

Thanks
 
dim total_tons(7)
is fine except it has 8 entries (arrays are 0 based). Show the code where the type mismatch occurs. It should not be occurring on the Dim. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
It's pretty ugly, but here it is...I am still working on other parts of it so it isn't complete. The error is showing up on line 196, which is right below the dim total_tons(7) (it's at about the middle of the code, I *'d it for easier finding)

sub display_Data (fromdate, todate)

dim s, category(100), category_count, j, category_maxsub(100), colno, maxsub_for_all, k
category_count = 0
maxsub_for_all = -1
if fromdate = "" then
fromdate = formatDateTime(now(), vbShortDate)
end if
if todate = "" then
todate = formatDateTime(dateadd("d",14, now()), vbShortDate)
end if


'get number of categorys that we are going to be working with
s = ""
s = "select distinct wogrouprouting.category, Category.WKCDESC, Category.LINE, "
s = s & " Category.DAILYCAP, space(5 - len(wogrouprouting.category)) + wogrouprouting.category "
s = s & " from wogrouprouting , workCentre Category, workOrder "
s = s & " where wogrouprouting.wohno = WorkOrder.wohno and "
s = s & " wogrouprouting.category = Category.wkcntr and "
s = s & " wogrouprouting.category not in ('11','12','08') and "
's = s + " wogrouprouting.wkcntr in ('01A','01B') and "
s = s & " isnull(calcstartdate, getdate()) >= '" & fromdate & "' and "
s = s & &quot; isnull(calcstartdate,getdate()) <= '&quot; & todate & &quot;'&quot;
s = s & &quot; order by wogrouprouting.category , space(5 - len(wogrouprouting.category)) + &quot;
s = s & &quot; wogrouprouting.category &quot;
'Response.Write s & &quot;<br>&quot;

dbconnect connectString_corpdb, s

category_count = -1
Response.Write &quot;<table width=100% border=1 cellpadding=1 > &quot;
Response.Write(&quot;<tr align=bottom><td> </td>&quot;)


dim daily_cap(7) 'array to hold the daily capacity of each of the categories

while not oRS.eof
category_count = category_count + 1
category(category_count) = oRS(0).value

daily_cap(category_count) = formatNumber(oRS(3).value, 1)

category_maxsub(category_count) = -1
'Response.Write category(category_count) + &quot;<br>&quot;

Response.Write &quot;<td wrap ><font size=2>&quot; & oRS(0).value & &quot; &quot; & oRS(1).value & &quot; &quot; & oRS(2).value & &quot; &quot; & formatnumber(oRS(3).value, 1) & &quot;</font></td>&quot;
oRS.movenext
Wend
Response.Write(&quot;</tr>&quot;)


'ok fire up the select
s = &quot;&quot;
s = s & &quot;select wogrouprouting.category, Category.wkcdesc, Category.line, Category.dailyCap, &quot;
s = s & &quot; rtrim(mandb100.envymgr.wohrec.prtno) prtno, &quot;
s = s & &quot; mandb100.envymgr.prtrec.prtdesc, rtrim(WorkOrder.wohno) wohno, WorkOrder.wopriority, &quot;
s = s & &quot; isnull(WorkOrder.calcStartDate, dateadd(day,-1, getdate())) calcstartdate, &quot;
s = s & &quot; cast ((mandb100.envymgr.wohrec.wohoqty - mandb100.envymgr.wohrec.wohcqty) * &quot;
s = s & &quot; mandb100.envymgr.prtrec.prtwgt / 2000 as decimal(13,3)) WO_Weight, &quot;

s = s & &quot; convert(datetime, cast(case mandb100.envymgr.wohrec.wohmrp when 0 then 19000101 &quot;
s = s & &quot; when 99999999 then 20991231 else mandb100.envymgr.wohrec.wohmrp end as char), 112) wohmrp, &quot;
s = s & &quot; mandb100.envymgr.wohrec.wohoqty, mandb100.envymgr.wohrec.wohcqty, &quot;
s = s & &quot; convert(datetime, cast(case mandb100.envymgr.wohrec.wohoddat when 0 then 19000101 when 99999999 &quot;
s = s & &quot; then 20991231 else mandb100.envymgr.wohrec.wohoddat end as char), 112) wohoddat &quot;

s = s & &quot; from wogrouprouting , workCentre Category, workOrder , mandb100.envymgr.prtrec , &quot;
s = s & &quot; mandb100.envymgr.wohrec &quot;
s = s & &quot; where wogrouprouting.wohno = WorkOrder.wohno and &quot;
s = s & &quot; WorkOrder.wohno = mandb100.envymgr.wohrec.wohno and mandb100.envymgr.wohrec.prtno = &quot;
s = s & &quot; mandb100.envymgr.prtrec.prtno and Category.wkcntr = wogrouprouting.category and &quot;
s = s & &quot; mandb100.envymgr.wohrec.wohoqty > mandb100.envymgr.wohrec.wohcqty and &quot;
s = s & &quot; mandb100.envymgr.wohrec.wohstat < 3 and &quot;
s = s & &quot; isnull(calcstartdate, getdate()) >= '&quot; & fromdate & &quot;' and &quot;
s = s & &quot; isnull(calcstartdate,getdate()) <= '&quot; & todate & &quot;' and &quot;
's = s & &quot; AND wogrouprouting.wkcntr in ('01A','01B') and &quot;
s = s & &quot; wogrouprouting.category not in ('11','12','08') &quot;

s = s + &quot; order by convert(char, isnull(WorkOrder.calcStartDate, &quot;
s = s & &quot; dateadd(day,-1, getdate())),20), Category.wkcntr, WorkOrder.wopriority desc,&quot;
s = s + &quot; (mandb100.envymgr.wohrec.wohoqty - mandb100.envymgr.wohrec.wohcqty) * &quot;
s = s & &quot; prtwgt / 2000 , WorkOrder.wohno&quot;
'Response.Write (s & &quot;<br>&quot;)

dbconnect connectString_corpdb, s

dim a(2000,100), lastdate, curdate, datearray(2000)
lastdate = &quot;&quot;

'Response.Write (&quot;</table>&quot;)
while not oRS.eof
' what is the current date
'Response.Write (oRS(&quot;wohno&quot;).value & &quot; &quot; & formatDateTime(oRS(8).value, vbShortDate) & &quot;<br>&quot;)
curdate = formatDateTime(oRS(8).value, vbShortDate)
if curdate <> lastdate then
'ok its a new day, all subscripts get set to current maximum
for j = 0 to category_count
category_maxsub(j) = maxsub_for_all
next
lastdate = curdate
end if


'figure out column of this category
colno = -1
for j = 0 to category_count
if category(j) = oRS(0).value then
colno = j
j = category_count+1
'Response.Write category(j) + &quot; &quot; + &quot; &quot; + oRS(0).value + &quot;<br>&quot;
end if
next
if colno < 0 then
Response.Write (&quot;couldnt find category --&quot; + oRS(0).value + &quot;<br>&quot;)
end if

'ok now we have colno as a subscript to the column
category_maxsub(colno) = category_maxsub(colno) + 1
if category_maxsub(colno) > maxsub_for_all then
maxsub_for_all = category_maxsub(colno)
end if



if category_maxsub(colno) > maxsub_for_all then
maxsub_for_all = category_maxsub(colno)
end if
s = &quot;&quot;
's = s & &quot;<a href=display_schedule_update.asp?&quot; & oRS(&quot;wohno&quot;).value

s = s & &quot;<a href=display_schedule_update2.asp?&quot; & oRS(&quot;wohno&quot;).value

s = s & &quot; target=_blank>&quot; & oRS(&quot;wohno&quot;).value & &quot;</a>, &quot;
S = S & oRS(&quot;wohoqty&quot;).value & &quot; - Qty&quot;
if ors(&quot;wohcqty&quot;).value <> 0 then
s = s & &quot;[&quot; & ors(&quot;wohcqty&quot;).value & &quot;] - rec&quot;
end if
s = s & &quot;, &quot;
s = s & &quot;<a name=&quot;&quot;&quot; & ors(&quot;prtno&quot;).value & &quot;&quot;&quot; href=&quot;&quot;../PRTREC_dETAIL.ASP?&quot; & oRS(&quot;prtno&quot;).value & &quot;&quot;&quot;&quot;
s = s & &quot; target=_blank>&quot; & oRS(&quot;prtno&quot;).value & &quot;</a>, &quot;
s = s & &quot;p&quot; & oRS(&quot;wopriority&quot;).value & &quot;, &quot;
s = s & formatNumber(oRS(&quot;wo_weight&quot;).value,1) & &quot;T &quot;
's = s & formatdatetime(oRS(&quot;calcstartdate&quot;).value, vbshortdate) & &quot; &quot;
if oRS(&quot;wohmrp&quot;).value <= datevalue(curdate) then
s = s & &quot;<font color=#ff0000>&quot; & &quot;*&quot; & formatdatetime(oRS(&quot;wohmrp&quot;).value, vbshortdate) & &quot;</font>&quot;
else
s = s & formatdatetime(oRS(&quot;wohmrp&quot;).value, vbshortdate)
end if
s = s & &quot; - MRP &quot;
s = s & &quot;[&quot; & formatdatetime(oRS(&quot;wohoddat&quot;).value, vbshortdate) & &quot;]&quot;


'***************************HERE IS WHERE THE TYPE MISMATCH ERROR IS OCCURING***************************
dim total_tons(7) 'array to hold the daily category tonnage
dim date_flag 'variable to indicate day that is currently being looked at


datearray(maxsub_for_all) = curdate

date_flag = &quot;&quot;
dim i, diff, new_weight

'if formatDateTime(oRS(&quot;calcstartdate&quot;.value), vbShortDate) < formatDateTime(now(), vbShortDate) then
'do nothing with these workorders (old)

'else if ors(0).value = &quot;99&quot; then
'do nothing with these workorders (unknown)

'else
'otherwise, it's current, so we'll deal with it

'if it's a new day (records sorted 1st by date)
if curdate <> date_flag then
for i = 0 to 7
'reset the daily category tonnage counters for the new day
total_tons(i) = 0.0
next
end if

'set the date_flag to the current day
date_flag = curdate

'find the right daily category tonnage counter to add to
for i = 0 to 7
if category(i) = oRS(0).value then
total_tons(i) = total_tons(i) + formatNumber(oRS(&quot;wo_weight&quot;).value,1)

'if it's over the daily capacity, move to next day(s)
if total_tons(i) > daily_cap(i) then
'so take it off this day's total
total_tons(i) = total_tons(i) - formatNumber(oRS(&quot;wo_weight&quot;).value, 1) 'and subtract it from the day's total
diff = daily_cap(i) - total_tons(i)

if diff = 0 then
'move the whole wo to next day

s = &quot;&quot;

s = s & &quot;<a href=display_schedule_update2.asp?&quot; & oRS(&quot;wohno&quot;).value
s = s & &quot; target=_blank>&quot; & oRS(&quot;wohno&quot;).value & &quot;</a>, &quot;
S = S & oRS(&quot;wohoqty&quot;).value & &quot; - Qty&quot;
if ors(&quot;wohcqty&quot;).value <> 0 then
s = s & &quot;[&quot; & ors(&quot;wohcqty&quot;).value & &quot;] - rec&quot;
end if
s = s & &quot;, &quot;
s = s & &quot;<a name=&quot;&quot;&quot; & ors(&quot;prtno&quot;).value & &quot;&quot;&quot; href=&quot;&quot;../PRTREC_dETAIL.ASP?&quot; & oRS(&quot;prtno&quot;).value & &quot;&quot;&quot;&quot;
s = s & &quot; target=_blank>&quot; & oRS(&quot;prtno&quot;).value & &quot;</a>, &quot;
s = s & &quot;p&quot; & oRS(&quot;wopriority&quot;).value & &quot;, &quot;
s = s & formatNumber(oRS(&quot;wo_weight&quot;).value,1) & &quot;T &quot;
if oRS(&quot;wohmrp&quot;).value <= datevalue(curdate) then
s = s & &quot;<font color=#ff0000>&quot; & &quot;*&quot; & formatdatetime(oRS(&quot;wohmrp&quot;).value, vbshortdate) & &quot;</font>&quot;
else
s = s & formatdatetime(oRS(&quot;wohmrp&quot;).value, vbshortdate)
end if
s = s & &quot; - MRP &quot;
s = s & &quot;[&quot; & formatdatetime(oRS(&quot;wohoddat&quot;).value, vbshortdate) & &quot;]&quot;

formatDateTime(oRS(&quot;calcstartdate&quot;).value, vbShortDate) = formatDateTime(dateadd(&quot;d&quot;,1,oRS(&quot;calcstartdate&quot;).value), vbShortDate)

else
while diff > 0

wend

'else if diff < daily_cap then
'split wo over 2 days

'else if diff > daily_cap then
'split wo over multiple days

end if
end if

Exit For
end if
next

'end if


a(category_maxsub(colno), colno) = s
'Response.Write &quot;row = &quot; & category_maxsub(colno) & &quot; col = &quot; & colno & &quot; wo &quot; & oRS(6).value & &quot;<br>&quot;

oRS.movenext
Wend

'Response.Write &quot;<table border=1 cellpadding=2 width=100> &quot;
'Response.Write(&quot;<tr align=bottom><td> </td>&quot;)

Response.Write(&quot;</tr>&quot;)
lastdate = &quot;&quot;
for j = 0 to maxsub_for_all
Response.Write &quot;<tr>&quot;
if datearray(j) <> lastdate then
dim x
x = datevalue(datearray(j))
s = &quot;&quot;
s = weekdayName( weekday(x),true)
s = s + &quot; &quot; & Month(x) & &quot;/&quot; & day(x)
else
s = &quot; &quot;
end if
lastdate = datearray(j)
Response.Write(&quot;<td wrap><font size=2>&quot; & s & &quot;</font></td>&quot;)
for k = 0 to category_count
Response.Write(&quot;<td><font size=2>&quot; & a(j,k) & &quot; &quot;& &quot;</font></td>&quot;)
next
Response.Write (&quot;</tr>&quot;)
next
response.write &quot;</table>&quot;
'end if
end sub

'******************************************************************
dim fromdate, todate
'determine default dates if there aren't any
fromdate = Request.Form(&quot;fromdate&quot;)
if fromdate = &quot;&quot; then
fromdate = formatDateTime(dateadd(&quot;d&quot;,-5, now()), vbShortDate)
end if
todate = Request.Form(&quot;todate&quot;)
if todate = &quot;&quot; then
todate = formatDateTime(dateadd(&quot;d&quot;,365, now()), vbShortDate)
end if

if not isdate(fromdate) then
Response.Write (&quot;From date (&quot; & fromdate & &quot;) is not valid. Use format of mm/dd/yyyy<br>&quot;)
end if
if not isdate(todate) then
Response.Write (&quot;To date (&quot; & todate & &quot;) is not valid. Use format of mm/dd/yyyy<br>&quot;)
end if


%>
<form action=&quot;display_schedule2.asp&quot; id=&quot;form1&quot; method=&quot;post&quot; name=&quot;form1&quot;>
<meta content=&quot;Microsoft FrontPage 4.0&quot; name=&quot;GENERATOR&quot;>


</head>
<body>
<font size=&quot;1&quot;>
From Date (mm/dd/yyyy):  <input name=&quot;fromdate&quot; size=&quot;10&quot; value=&quot;<%=fromdate%>&quot;>
  To Date:  <input name=&quot;todate&quot; size=&quot;10&quot; value=&quot;<%=todate%>&quot;> 
Recalculate:  <input name=&quot;recalculate&quot; type=&quot;checkbox&quot;> 
<input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;submitbutton&quot;>
</font>
</form>
<%
Response.Flush

if isdate(fromdate) and isdate(todate) then
if Request.form(&quot;recalculate&quot;) <> &quot;&quot; then
Response.Write(&quot;Starting Recalculate...&quot;)
Response.Flush

set oConn = server.CreateObject(&quot;ADODB.connection&quot;)
set oCmd = server.CreateObject(&quot;adodb.command&quot;)
oConn.open connectString_corpdb
set oCmd.activeConnection=oConn
oCmd.commandtext = &quot;execute dbo.WORKoRDERsCHEDULECALCULATEg2&quot;
oCMD.commandtype = adCmdtext
oCmd.execute
Response.Write(&quot;Finished.<br>&quot;)
Response.Flush
end if

display_data fromdate, todate
Response.Flush
end if
%>
</body></html>
 
I don't see an obvious error. Use the VARTYPE function to display the Data Type that is in a Variant. You will get an error if you moved a date to a variable then tried to set it to a string. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top