www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] VBScript Array Help!

  1. #1
    Join Date
    Jul 2010
    Location
    UK
    Posts
    28

    resolved [RESOLVED] VBScript Array Help!

    Hi All

    I've had a good look through the old posts and i cant find anything which helps me with this (probably newbie) probelm... any advise or links of use would be appreciated.

    I have a recordset, and used it to dim an array, but i'm struggling to get the array to display as the recordset does (like when you look at it in sql). Array's aren't my favourite atm

    Code:
    If request("subbut")="Search" then
      sSql="myStoredProc '"&session("selclient")&"', "&session("srch")
      set rsmTmp=Server.CreateObject("ADODB.Recordset")
      rsmTmp.Open sSql, connSub()
    
      If not rsmTmp.EOF then
        Set oFso=Server.CreateObject("Scripting.FileSystemObject") 
    [i use this fso later]
    
        arrResult = rsmTmp.getrows()
        If isarray(arrResult) then
          response.write "<table>"
          response.write "<tr>"
          for x = 0 to Ubound(arrResult)
            for y = 0 to Ubound(arrResult,2)
              response.write "<td>"              
              response.write arrResult(x,y)
              response.write "</td>"
            next
              response.write "</tr>"
          next
        End If
      Else
        response.write "<p>No Results</p>"
      End If
    End If
    This does display all the data, but the axis' are the wrong way round, E.g.

    row1 cell1, row2 cell1, row3 cell1 etc.
    row1 cell2, row2 cell2, row3 cell2 etc.

    Thanks

  2. #2
    Join Date
    Jul 2010
    Location
    UK
    Posts
    28
    Just changed it to this:
    Code:
      If not rsmTmp.EOF then
        Set oFso=Server.CreateObject("Scripting.FileSystemObject")
        'Set oFile = oFso.OpenTextFile(Server.MapPath("Excel Files\"&sFname), 2, True)
        arrResult = rsmTmp.getrows()
        If isarray(arrResult) then
          response.write "<table>"
          response.write "<tr>"
          for x = 0 to Ubound(arrResult)
              response.write "<td>"              
              response.write arrResult(x,Ubound(arrResult,2))
              response.write "</td>"
          next
          response.write "</tr>"
        End If
        response.write "</table>"
      Else
        response.write "<p>No Results</p>"
      End If
    But now i only get the last row as a result

  3. #3
    Join Date
    Jul 2010
    Location
    UK
    Posts
    28
    Sorted it, for reference if people want:
    Code:
      If not rsmTmp.EOF then
        Set oFso=Server.CreateObject("Scripting.FileSystemObject")
        'Set oFile = oFso.OpenTextFile(Server.MapPath("Excel Files\"&sFname), 2, True)
        arrResult = rsmTmp.getrows()
        If isarray(arrResult) then
          response.write "<table>"
          for x = 0 to Ubound(arrResult,2)
            response.write "<tr>"
            for y = 0 to Ubound(arrResult,1)
              response.write "<td>"              
              response.write arrResult(y,x)
              response.write "</td>"
            next
              response.write "</tr>"
          next
        End If
        response.write "</table>"
      Else
        response.write "<p>No Results</p>"
      End If
    I was only referencing the last record in the response above. And the original code was looking at the wrong axis' in sql. I'd taken it as golden from another online tutorial that that ubound(myArray,2) will always look at columns

    nevermind!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles