Variant Array Length?

G

Guest

Basically:
Shortly, I need a function that will return the number of items in the
variant array.


The Long Story:

I passed a number of arguments between two forms via a variant array (I
think). In Form1, the following code is run when the "Export" button is
clicked:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub cmdExport_Click()
MyArgs = Me!name & ";" & Me!address1 & " " & Me!address2 & ";" & Me!city
& ";" & Me!state & ";" & Me!zip & ";" & Me!phone & ";" & Me!email
DoCmd.Close acForm, Me.name
DoCmd.OpenForm "contacts", , , , , , MyArgs
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Basically, the MyArgs = "Name;Address;City;State;Zip;Phone;Email"

When Form2 is opened, it splits the arguments into an array (I think) with
the following code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Form_Open(Cancel As Integer)
Dim Args1 As Variant, args2 As Variant
If Not IsNull(Me.OpenArgs) Then
DoCmd.GoToRecord , , acNewRec
Args1 = Split(Me.OpenArgs, ";")
args2 = Split(Args1(0), " ")
..............
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All in all, Args1(0) = Name, Args1(1) = Address, Args1(2) = City, and so on.

Args2 is what concerns me though. The code parses Args1(0) by spaces and
puts it into Args2 without a hitch. The problem is that the length of Args2
is variable, and I need to put the values into different fields depending on
what format the name is in. For example, the name could be "George
Washington" or "Terry Tate Jr" or "Sam and Sue Smith".

Simply put, I need a function that will return the number of items in the
variant array. I did a good deal of searching, and I couldn't find one. The
Len() function came close though.

Thanks,

Nick
 
D

David Lloyd

The UBound function returns the largest available subscript of an array. If
your array is zero based, then you would add one to the UBound value to
determine the count. If your array is one based then UBound returns the
count of items in the array. Other bases would have to be adjusted
accordingly.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Basically:
Shortly, I need a function that will return the number of items in the
variant array.


The Long Story:

I passed a number of arguments between two forms via a variant array (I
think). In Form1, the following code is run when the "Export" button is
clicked:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub cmdExport_Click()
MyArgs = Me!name & ";" & Me!address1 & " " & Me!address2 & ";" & Me!city
& ";" & Me!state & ";" & Me!zip & ";" & Me!phone & ";" & Me!email
DoCmd.Close acForm, Me.name
DoCmd.OpenForm "contacts", , , , , , MyArgs
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Basically, the MyArgs = "Name;Address;City;State;Zip;Phone;Email"

When Form2 is opened, it splits the arguments into an array (I think) with
the following code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Form_Open(Cancel As Integer)
Dim Args1 As Variant, args2 As Variant
If Not IsNull(Me.OpenArgs) Then
DoCmd.GoToRecord , , acNewRec
Args1 = Split(Me.OpenArgs, ";")
args2 = Split(Args1(0), " ")
..............
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All in all, Args1(0) = Name, Args1(1) = Address, Args1(2) = City, and so on.

Args2 is what concerns me though. The code parses Args1(0) by spaces and
puts it into Args2 without a hitch. The problem is that the length of Args2
is variable, and I need to put the values into different fields depending on
what format the name is in. For example, the name could be "George
Washington" or "Terry Tate Jr" or "Sam and Sue Smith".

Simply put, I need a function that will return the number of items in the
variant array. I did a good deal of searching, and I couldn't find one.
The
Len() function came close though.

Thanks,

Nick
 
T

Tim Ferguson

Shortly, I need a function that will return the number of items in the
variant array.

NumOfItems = UBound(varMyArray) - LBound(varMyArray) + 1


Isn't this in the help files somewhere?

Tim F
 
G

Guest

EVERYTHING is in the help files Somewhere. And hopefully that's the first
place anyone looks when they have a question. Followed by searching the
forums. And then poke around on a general search engine. And when that
doesn't work, heaven forbid, someone might decide to make a post on a
Microsoft forum which was, strangely enough, designed to help out the stupid
Access users such as myself that can't ever figure things out on their own.

That aside... the UBound function worked perfectly! Thanks! :-D

Nick
 
G

Guest

EVERYTHING is in the help files Somewhere.
Should be chisled in stone. There are two issues here. It is often that if
you don't know exactly what you are looking for, you can't find it in help.
But, the more you use Help, the more it starts to make sense. ...and thats
the part that scares me :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top