Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Passing an array


Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2004, 12:19 PM
JorgeJ JorgeJ is offline
Newcomer
 
Join Date: May 2004
Posts: 2
Question Passing an array


Hello. I'm new to this forum, so If I mess up in posting and have to post a few times please excuse me.

I am using VBA with Excel 97. I am trying to pass an array as a parameter to a subroutine. It doesn't compile. I keep getting an error. It occurs to me that I may be doing something wrong, or maybe VBA with Excel 97 doesn't have the capability to do what I want.

Option Explicit
Dim A() As Double

Sub test2(v() As Double)
v(1) = 17
End Sub




Sub test1()
ReDim A(9) As Double
test2 (A)
End Sub

By the way, is it possible to upload files in this forum?

Thank you.
Reply With Quote
  #2  
Old 05-19-2004, 12:47 PM
Csharp's Avatar
Csharp Csharp is offline
Senior Contributor

* Expert *
 
Join Date: Jul 2003
Location: Ashby, Leicestershire.
Posts: 967
Default

you need to remove the brackets from test2 (A) , it should be test2 A
eg:
Code:
Dim A() As Double Sub test2(v() As Double) v(1) = 17 MsgBox v(1) End Sub Sub test1() ReDim A(9) As Double test2 A '/// notice the brackets removed from A End Sub Private Sub Command1_Click() test1 End Sub
__________________
~~ please don't PM me regarding code, I only reply to personnal messages ~~
Reply With Quote
  #3  
Old 05-19-2004, 03:01 PM
JorgeJ JorgeJ is offline
Newcomer
 
Join Date: May 2004
Posts: 2
Default

Thank you very much. That works. Do you know if it is possible in VB/Excel97 to have a function return an array. The following declaration doesn't work. What should I be doing?

Option Explicit

Dim A() As Double


Function VectorSum(v1() As Double, v2() As Double) As Double()
'no code yet
End Function
Reply With Quote
  #4  
Old 05-19-2004, 04:33 PM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

Works for me... what error are you getting?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Array passing AFterlife .NET General 3 03-04-2004 07:13 PM
Passing an array of pointers as a parameter? cobwebs Miscellaneous Languages 6 02-29-2004 02:32 PM
Passing an array to a function. vbNEMESIS General 4 06-10-2003 11:25 AM
Passing array of checkboxes problem medsolution General 5 01-27-2003 02:52 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->