ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

(Train Wreck) Multidimensional Dynamic Array in ASP

(1/2) > >>

Stoic Joker:
Greetings
    I'm currently (trying not to scream...) working on an office project that was done in ASP ... I've come to enjoy ASP about as much as I enjoy being repeetedly stabbed with miscellanous randomly sharpened objects.

Anyhow...

Part ordering interface, takes parts from multiple vendors, and compiles them into seperate orders for each vendor. Hence the need for a multidimensional array - which has to be dynamic, because the parts list is ever changing.

I cannot for the life of me find a tutorial on working with multidimensional dynamic arrays that makes any sense/works/doesn't try to trivialize the insane amount of dificulty there (apparently) is in doing this with ASP. Christ, if I was working in C++ I'd have been done with this hours ago.

Here is a stripped down (non-working) example of what I'm trying to do. It currently is just trying to dump the array(s)(s) back into the page via response.write to avoid listing the SQL query stuff and keep the example simple:
--- Code: ASP ---<%Dim ar_LAPN, iCountDim ar_vCode(), ar_vFName(), ar_vActive(), iVendsar_LAPN = Split(Request.Form("LAPN"), ",")iCount  = Request.Form("iCount") Dim ar_nVend00(10, 1000), ar_pVend00(10, 1000) Dim MyConn, MyQuery, mRS '-----> SQL Query Variablesset MyConn = Server.CreateObject("ADODB.Connection")        MyConn.Open(MySQL) MyQuery = "SELECT VendorCode, VendorFName, Active, BorderColor, FontClass FROM VendorNames"Set mRS = MyConn.Execute(MyQuery)If mRS.BOF And mRS.EOF Then    Response.Write("MySQL Query Failed! " & MyQuery)    Response.EndElse        iVends = 0        mRS.MoveFirst        WHILE NOT mRS.EOF                ReDim Preserve ar_vCode(iVends + 1)                ReDim Preserve ar_vFName(iVends + 1)                ar_vCode(iVends)        = mRS("VendorCode")                ar_vFName(iVends)       = mRS("VendorFName")                ar_vActive(iVends)      = mRS("Active") '--+++--> Add Column for Vendor X Only if They're Active                                if ar_vActive(iVends) Then '--------------------------------------+++-->'                       ReDim Preserve ar_nVend00(iVends + 1)'                       ReDim Preserve ar_pVend00(iVends + 1)                        ar_nVend00(iVends, 0) = Split(Request.Form("nVend00" & iVends), ",")                        ar_pVend00(iVends, 0) = Split(Request.Form("pVend00" & iVends), ",")                end if                                iVends = iVends + 1                mRS.MoveNext        WEND        iVends = iVends - 1End If   for i=0 to iCount        response.write("LAPN: " & ar_LAPN(i) & " ")        for iV=0 to iVends                response.write(" Qty: " & ar_nVend00(iVends, iCount) & " * Price: " & ar_pVend00(iVends, iCount) & " | ")        next        response.write("Vends-break;<br>")next
While (this version of) the code runs without error there are no values output when run even tho all data pulled from the previous page is correct.

Note: this was a working production system before I started working on making it a bit more flexible/robust - I'm trying to get away from hardcoding the vendors.

Yes, I am working on (torching...) a Lab Clone of the production system.


Edit: reworked output code to make more sense out of what I'm doing - It was rather cryptic in retrospect.

timns:
Shouldn't these 2 lines use iCount too?
(You're indexing using iCount later on)
         ar_nVend00(iVends, 0) = Split(Request.Form("nVend00" & iVends), ",")
         ar_pVend00(iVends, 0) = Split(Request.Form("pVend00" & iVends), ",")

Also, your loops are one step too big - shouldn't they stop at iCount-1 and iVends-1?

for i=0 to iCount-1
for iV=0 to iVends-1
response.write(ar_nVend00(iVends, iCount) & "Vend ->")
next
response.write("br<br>")

Stoic Joker:
Shouldn't these 2 lines use iCount too?
(You're indexing using iCount later on)
         ar_nVend00(iVends, 0) = Split(Request.Form("nVend00" & iVends), ",")
         ar_pVend00(iVends, 0) = Split(Request.Form("pVend00" & iVends), ",")-timns (December 06, 2010, 04:40 PM)
--- End quote ---

You would think wouldn't you (I did), but it seems that Split(...) creates the "array" part of the array auto-magically. So a single dimension array is declared as just a plain dim (i.e. Dim myArray) and then the split does the rest.

myArray - Split(...)

Now it's used normally as myArray(x) ... This I've used elsewhere in the code so I know it works. One of the tutorials I ran across said... that to populate a multidimensional array you use myArray(x, 0) because Split would then begin populating dimension 2 from position zero. *Shrug* ...I couldn't find a hole in the reasoning ... So I gave it a shot.

I tried using iCount there just now and it results in a type mismatch error. :(

Also, your loops are one step too big - shouldn't they stop at iCount-1 and iVends-1?

for i=0 to iCount-1
for iV=0 to iVends-1
response.write(ar_nVend00(iVends, iCount) & "Vend ->")
next
response.write("br<br>")
-timns (December 06, 2010, 04:40 PM)
--- End quote ---

It does appear that way, but iVends is decremented accordingly at the end of the while loop and iCount gets the same treatment on the previous page before being handed to this one.

Correction: iVends would have been correct if I was incrementing it on the right side of the if statement...  :wallbash: ...Fixed now, rest of code still broken :) (..shit)

I touched up the code above so the output string makes a bit more sense of what I'm doing (It was a might cryptic)


Thank you! (I'm willing to try anything at this point)

timns:
So you only have a maximum of 10 vendors? Those arrays (10,1000) may be the wrong way around? (1000,10)?

Stoic Joker:
Actually there are currently 6 vendors and about 400 parts (I'm trying to leave room for expansion), we're dealing with a lot of different parts that only a few people handle.

The array defined as (10, 1000) is actually a static array that is known to be large enough (6/400) for the current data set. I'd hoped to go fully dynamic but (only the right most dimension of the array can be redefined) as usual ASP sucks to much to do anything fancy with. So I'm resigning myself to using static arrays (unless a cheat can be found).

Christ, I'd rather be gargling battery acid...

On a brighter note, one the tutorials I came across listed a work-around for ASP's short-comings, in the process of explaining why what I'd wanted to do was friggin impossible. So... Now I have a semi working 2dim array - and by working I mean it runs with out errors or crashing. Unfortunately it also runs without any valid output ... It just iterates garbage. *Joy*

So here is the new and "improved" still totally borked code:
--- Code: ASP ---<!--#include virtual="inc/dbConn.inc"--><%Response.Buffer = False '--+++--> HOLY SHIT!!! (that helped) Dim ar_LAPN, iCountDim ar_vCode(10), ar_vFName(10), ar_vActive(10), iVendsar_LAPN = Split(Request.Form("LAPN"), ",")iCount  = Request.Form("iCount") Dim ar_nVend00, ar_pVend00ReDim ar_nVend00(10)ReDim ar_pVend00(10) Dim MyConn, MyQuery, mRS '-----> SQL Query Variablesset MyConn = Server.CreateObject("ADODB.Connection")        MyConn.Open(MySQL) MyQuery = "SELECT VendorCode, VendorFName, Active, BorderColor, FontClass FROM VendorNames"Set mRS = MyConn.Execute(MyQuery)If mRS.BOF And mRS.EOF Then    Response.Write("MySQL Query Failed! " & MyQuery)    Response.EndElse        iVends = 0        mRS.MoveFirst        WHILE NOT mRS.EOF                ar_vActive(iVends)      = mRS("Active") '--+++--> Add Column for Vendor X Only if They're Active                ar_vCode(iVends)        = mRS("VendorCode")                ar_vFName(iVends)       = mRS("VendorFName")                if ar_vActive(iVends) Then '--------------------------------------+++-->                        response.write("Vendor: " & ar_vFName(iVends) & " Is Active: " & ar_vActive(iVends) & "<br>")'                       ar_nVend00(iVends, 0) = Split(Request.Form("nVend00" & iVends), ",")'                       ar_pVend00(iVends, 0) = Split(Request.Form("pVend00" & iVends), ",")                        ar_nVend00(iVends) = Request.Form("nVend00" & iVends)                        ar_pVend00(iVends) = Request.Form("pVend00" & iVends)                        '                       response.write(ar_nVend00(iVends) & "<br>")'                       response.write(ar_pVend00(iVends) & "<br>")                else                        response.write(ar_vFName(iVends) & " Vendor Number: " & iVends & " is NOT Active!<br>")                end if                iVends = iVends + 1 '--+++--> This MUST be Here so the Vend00x Number Matches the db Info.                mRS.MoveNext        WEND'       ReDim Preserve ar_vActive(iVends)'       ReDim Preserve ar_vFName(iVends)'       ReDim Preserve ar_vCode(iVends)        iVends = iVends - 1End If response.write("<br><br>") for i=0 to iCount                          MyQuery = "SELECT Printer, Description FROM Inventory WHERE LAPN = '" & ar_LAPN(i) & "'"                        Set mRS = MyConn.Execute(MyQuery)                        Printer = mRS("Printer")                        Description = mRS("Description")          response.write("LAPN: " & ar_LAPN(i) & " :-: " & Description & "<br>")        for iV=0 to iVends                Dim ar_nV, ar_pV                                if ar_vActive(iV) Then '--------------------------------------+++-->'                       response.write("<br>==========================================================================================<br>")'                       response.write(ar_nVend00(iV) & "<br>")'                       response.write(ar_pVend00(iV) & "<br>")'                       response.write("==========================================================================================<br>")                ar_nV = Split(ar_nVend00(iV), ",")                ar_pV = Split(ar_pVend00(iV), ",")'               response.write(" Qty: " & ar_nVend00(iVends, iCount) & " * Price: " & ar_pVend00(iVends, iCount) & " | ")                response.write("Vendor: " & ar_vFName(iV) & " Qty: " & ar_nV(iCount) & " * Price: " & ar_pV(iCount) & "<br>")                else                        response.write("==========================================================================================<br>")                        response.write("Vendor: " & ar_vFName(iV) & " - IS NOT ACTIVE!!!")                        response.write("<br>==========================================================================================<br>")                end if        next        response.write("End of LAPN: " & ar_LAPN(i) & " Vends-break;<br><br>")next%>
Thank you!

Navigation

[0] Message Index

[#] Next page

Go to full version