Solved

Passing an Array Dimension to Sub

Posted on 2013-11-06
4
297 Views
Last Modified: 2013-11-07
I want to pass an array dimension via a parameter.  I want a single sub to work with calls in which the array dimension will change.  I get a "constant expression required" error when I try to call this:
rivate Sub SingleRcrd(ByRef iArrayBound As Integer, ByVal ThisSql As String)
    'On Error GoTo ErrorHandler
    
    Dim rs As ADODB.Recordset
    Dim i As Integer
    Dim UploadArr(iArrayBound)
    
    Set rs = New ADODB.Recordset
    rs.Open ThisSql, conn, 1, 2
    For i = 0 To iArrayBound
        UploadArr(i) = rs(i).Value
    Next i
    rs.Close
    Set rs = Nothing
    
    Set rs = New ADODB.Recordset
    rs.Open ThisSql, srvr_conn, 1, 2
    For i = 0 To iArrayBound
        rs(i).Value = UploadArr(i)
    Next i
    rs.Update
    rs.Close
    Set rs = Nothing
    
    Exit Sub
ErrorHandler:
    Beep
    ErrorHandler
End Sub

Open in new window


with this:
    sql = "SELECT EventName, EventDate, Club, Website, Weather, Comments, FeeIncrDate, TimingMethod, EventDirID, ShowOnline, "
    sql = sql & "OnlineReg, WhenShutdown, FeeIncrDate FROM Events WHERE EventID = " & lEventID
    Call SingleRcrd(12, sql)

Open in new window


What am I doing wrong?
0
Comment
Question by:Bob Schneider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 167 total points
ID: 39629102
I suspect it is because you are passing the parameter byref and then using it to try and define an array which I suspect is where the error is occurring. Can't see why you need to pass byref so do you get the same error if you pass the parameter byval.
0
 
LVL 10

Accepted Solution

by:
Banthor earned 167 total points
ID: 39629125
use REDIM instead of DIM for the array, this tells the compiler that the dimension can be altered.

Another option is to use an xml object
0
 
LVL 5

Assisted Solution

by:advfinance
advfinance earned 166 total points
ID: 39629780
Like Banthor says, use Dim, then ReDim. Change line 6 from

Dim UploadArr(iArrayBound)

Open in new window


to

Dim UploadArr()
ReDim UploadArr(iArrayBound)

Open in new window


--
Chris
0
 

Author Closing Comment

by:Bob Schneider
ID: 39629797
Thanks a bunch!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question