populating an MSFlexgrid
Posted on 2003-12-03
Take a look at the following code, basically all I'm doing is getting a session variable from another page and converting it to a standard variable. Then creating an array to populate an MSFlexGrid.
When I try to run the code as the page loads I get an error message Object Required G was not handled, (G is the name of my MSFlexGrid)
However, if I place this code in a sub, the page loads first and then I execute the code and it works fine - presumably because my MSFlexGrid (G) exists on the page, where as it doesn't in the earlier scenario.
How can I populate this grid when the page loads and remove the need for a click event.
Looking forward to your help.
Dim max ' max number of elements
SessConv = "<%=session("ses_search")%>"
ReDim a(<%=session("ses_FirstDimUBound")%>, <%=session("ses_SecondDimUBound")%>)
max = (UBound(a, 1) - LBound(a, 1) + 1) * (UBound(a, 2) - LBound(a, 2) + 1)
count = 0
For I = LBound(a, 2) To UBound(a, 2)
' Process 2nd dimension element for each 1st dimension values
For J = LBound(a, 1) To UBound(a, 1)
count = count + 1
If count > max Then
pos = InStr(SessConv, "#")
if pos = 0 then
a(J, I) = ""
a(J, I) = Left(SessConv, pos - 1)
SessConv = Mid(SessConv, pos + 1)
If count > max Then Exit For
retVar = a 'at this point retvar contains all the required data in an array
g.Rows = UBound(retVar, 2) + 1 ' code fails here on the 1st ref to g
g.Cols = UBound(retVar, 1) + 1
for z=0 to g.Cols - 1
g.TextMatrix(0, z) = "Column #" & z
g.ColAlignment(z) = flexAlignRightCenter
g.ColWidth(z) = 2000
'g.width = g.ColWidth(0) + g.ColWidth(1) + g.ColWidth(2) + g.ColWidth(3) + g.ColWidth(4) + g.ColWidth(5)
for z = g.FixedRows to g.Rows - 1
for w = g.FixedCols to g.Cols - 1
g.TextMatrix(z, w) = retVar(w, z)