[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Passing an Array Dimension to Sub

Posted on 2013-11-06
4
Medium Priority
?
300 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 668 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 668 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 664 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

650 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