?
Solved

Array Handling

Posted on 2003-03-16
13
Medium Priority
?
140 Views
Last Modified: 2010-04-07
Hi,

Hi ,
  I just want to ask how to pass an array into a procedure:
 
Dim strText() As String
 
ReDim strText(FIELD_NUM)
For i = 0 To FIELD_NUM - 1
    strText(i) = Text(i).Text  ' Text(i).Text is the text box in the form
Next

loadOptionCatalogs (strText)   <------------Typ mismatched occurs

where

Sub loadOptionCatalogs(strText() As String)
....
....
End sub

Could anyone tell me the correct method and give some explanation ?

Thanks!
0
Comment
Question by:cyyam
[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
  • 3
  • 2
  • 2
  • +6
13 Comments
 
LVL 1

Expert Comment

by:GERTJAN
ID: 8146509
I think it must be :

Sub loadOptionCatalogs(strText As String)


0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8146617
use
call loadOptionCatalogs (strText)
or
loadOptionCatalogs strText
0
 

Expert Comment

by:junkeira
ID: 8146619
it should be:

Sub loadOptionCatalogs(strText As Variant)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
Jacamar earned 80 total points
ID: 8146969
Call loadOptionCatalogs(strText())

then

Private sub loadOptionCatalogs(strText() as String)

Then you can use it in the sub procedure.
0
 
LVL 3

Expert Comment

by:QJohnson
ID: 8147334
Only Jacamar's is correct.  The others will only handle single values - not an array variable.
0
 
LVL 11

Expert Comment

by:supunr
ID: 8148479
your code worked fine in my machine.  

Private sub Command1_Click()
Dim i as long
Dim strText() As String

ReDim strText(FIELD_NUM)
For i = 0 To FIELD_NUM - 1
   strText(i) = Text(i).Text  ' Text(i).Text is the text box in the form
Next

loadOptionCatalogs  strText  ' <------------Typ mismatched occurs
End Sub


Sub loadOptionCatalogs(strText() As String)
....
....
End sub

actually get rid of the brackets around strText in the marked line....

Good Luck!
0
 
LVL 11

Expert Comment

by:supunr
ID: 8148502
you only put brackets around a function call, not for a call to a subroutine (i.e. functions that returns nothing)

e.g.

retVal = FunctionName(parameter)

SubRoutName parameter
' or
call SubRoutName(parameter)
0
 
LVL 3

Expert Comment

by:QJohnson
ID: 8148916
It looks as if the overriding concern is the use of the brackets in the called routine's declaration.  Actually calling the routine can be done with or without brackets.

I was surprised to see this, but this code convinced me.  Just drop in in the code window of a new standard exe project:

Private Sub Form_Load()
   Dim astr(2) As String

   astr(0) = "a"
   astr(1) = "b"
   astr(2) = "c"
   MsgBox "Present order is:" & vbCrLf & _
       astr(0) & vbCrLf & astr(1) & vbCrLf & astr(2)
   
   Call SwapAB(astr)     '  <<---- key line of code here
   
   MsgBox "New order is: " & vbCrLf & _
       astr(0) & vbCrLf & astr(1) & vbCrLf & astr(2)
   
End Sub

Private Sub SwapAB(astr() As String)
   Dim stemp As String
   stemp = astr(0)
   astr(0) = astr(2)
   astr(2) = stemp
End Sub

you'll see that you can change that "key line of code" to either use astr() or astr and the code works the same.  I had always believed you had to use the parens in the call and in the routine declararation.  Always happy to learn that ancient suppositions are wrong.  (Maybe this was right back in VB3??? <g>)

QJ

0
 

Author Comment

by:cyyam
ID: 8150220
Thanks for all of your responds, and esp. QJohnson and Jacamar.

May I further a little bit in Array handling.
How can I assign an array to another array?

Dim arstr1 () as string
Dim arstr2() as string

Redim arstr2 ( n )
... do operation in arstr2

arstr1 = arstr2  <---- It does not work

How can I assign it without assigning the array elements one by one ?

Thanks!
0
 
LVL 3

Expert Comment

by:QJohnson
ID: 8151536
I pasted your code into VB6 and it worked fine as soon as I change 'n' to a number.  I used 3.  After the assignment statement executes, ubound(astr1) and ubound(astr2) are both 3.
0
 

Expert Comment

by:CleanupPing
ID: 8532264
Hi cyyam,
This old question (QID 20552510) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8956451
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-->Split between QJohnson and Jacamar

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GPrentice00
EE Cleanup Volunteer
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8957004
sorry - 20 pts, cant be split.

--> accept answer by Jacamar
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 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