Array

Array

Anonymous
Not applicable
916 Views
8 Replies
Message 1 of 9

Array

Anonymous
Not applicable
Dim la_Bords()


If I have code in a loop to redim this array as criteria meets, and populate
the array, how can I tell if the array has never been redimensioned. IE: it
has never been populated with a first element.

Dale

Ubound won't work.
0 Likes
917 Views
8 Replies
Replies (8)
Message 2 of 9

Ed__Jobe
Mentor
Mentor
IsArray

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 9

Anonymous
Not applicable
Here is a function I use to test if an array has any elements.


Function HasElements(ByVal ArrayToCheck As Variant) As Boolean
On Error Resume Next
HasElements = (LBound(ArrayToCheck) <= UBound(ArrayToCheck))
Err.Clear
End Function


--
R. Robert Bell, MCSE
www.AcadX.com


"Dale Levesque" wrote in message
news:[email protected]...
| Dim la_Bords()
|
|
| If I have code in a loop to redim this array as criteria meets, and
populate
| the array, how can I tell if the array has never been redimensioned. IE:
it
| has never been populated with a first element.
|
| Dale
|
| Ubound won't work.
|
|
0 Likes
Message 4 of 9

Anonymous
Not applicable
I have a few sub's and after searching on the internet, in this NG and in
the help I came to the conclusion that an array is what I'm looking for.

For example in the next sub::

Sub Select()
Dim sstype(1) As Integer: Dim ssdata(1)
Dim I As Integer
Dim removeObjects as Acadentity
sstype(0) = 0: ssdata(0) = "Line"
sstype(1) = 8: ssdata(1) = "Test"
Dim sstest As AcadSelectionSet
Set sstest = ThisDrawing.PickfirstSelectionSet
sstest.Clear
sstest.Select acSelectionSetAll, , , sstype, ssdata
For I = 0 To sstest.Count - 1
If Not sstest(I).Color = "acBlue" Then
'On this position I need to fill an array (removeObjects) with the
object that doesn't apply to the If function above
End If
Next I
sstest.RemoveItems removeObjects
SendCommand "(sssetfirst nil (ssget " & Chr(34) & "_P" & Chr(34) & ")) "
sstest.Delete

End Sub

I also have a sub where I want to fill an array with strings and sort those
strings alphabatic, but I don't know how?
I hope anybody can help me with this and can explain a little about array's?
Thanks
Frank
0 Likes
Message 5 of 9

Anonymous
Not applicable
"Frank Jan Koole" wrote in message
news:[email protected]...
> I have a few sub's and after searching on the internet, in this NG and in
> the help I came to the conclusion that an array is what I'm looking for.

> I also have a sub where I want to fill an array with strings and sort
those
> strings alphabatic, but I don't know how?
> I hope anybody can help me with this and can explain a little about
array's?

I found it on the web somewhere during many searches for sorting algorithms
I don't remember which one should get credit for this version...sorry....

I think this will work for your string array
Sub SHELLSORTtxt(arr)
Dim gappos As Integer
Dim swapped As Boolean
Dim tmp As Long
Dim tmpstr As String

gappos = UBound(arr) \ 2
Do While gappos <> 0
Do
swapped = False
For tmp = 0 To UBound(arr) - gappos
If (StrComp(arr(tmp + gappos), arr(tmp), vbTextCompare) = -1) Then
tmpstr = arr(tmp + gappos)
arr(tmp + gappos) = arr(tmp)
arr(tmp) = tmpstr
swapped = True
End If
Next tmp
Loop Until Not swapped
gappos = gappos \ 2
Loop
End Sub

Ive also found some here
' Chris Rae's VBA Code Archive - http://chrisrae.com/vba

do a google search on sorting and you'll find many information

basically an array you have to create the size you need it
Dim myArray(3) as String
will hold 4 strings

then you have to fill it one by one, each element

myArray(0)= "A"
myArray(1)="B"
etc
and also read it one by one
For i = 0 to 3
debug.print myarray(i)
next

hth
Mark
0 Likes
Message 6 of 9

Anonymous
Not applicable
Good answer Mark, but remember that the shellsort is on of the slowest sorts
for large numbers of items (1000+). Do a search for a mergesort and vb. The
mergesort is the fastest sort for more than 15 entities. The general
strategy would be to use mergesort to break down the list into sub lists of
15 items, then shellsort the small list, and do the recursive merge back up
the tree. I have used this often, and it is fast for large lists 60k-100k
items.

HTH

//chris
"Mark Propst" wrote in message
news:[email protected]...
>
> "Frank Jan Koole" wrote in message
> news:[email protected]...
> > I have a few sub's and after searching on the internet, in this NG and
in
> > the help I came to the conclusion that an array is what I'm looking for.
>
> > I also have a sub where I want to fill an array with strings and sort
> those
> > strings alphabatic, but I don't know how?
> > I hope anybody can help me with this and can explain a little about
> array's?
>
> I found it on the web somewhere during many searches for sorting
algorithms
> I don't remember which one should get credit for this version...sorry....
>
> I think this will work for your string array
> Sub SHELLSORTtxt(arr)
> Dim gappos As Integer
> Dim swapped As Boolean
> Dim tmp As Long
> Dim tmpstr As String
>
> gappos = UBound(arr) \ 2
> Do While gappos <> 0
> Do
> swapped = False
> For tmp = 0 To UBound(arr) - gappos
> If (StrComp(arr(tmp + gappos), arr(tmp), vbTextCompare) = -1) Then
> tmpstr = arr(tmp + gappos)
> arr(tmp + gappos) = arr(tmp)
> arr(tmp) = tmpstr
> swapped = True
> End If
> Next tmp
> Loop Until Not swapped
> gappos = gappos \ 2
> Loop
> End Sub
>
> Ive also found some here
> ' Chris Rae's VBA Code Archive - http://chrisrae.com/vba
>
> do a google search on sorting and you'll find many information
>
> basically an array you have to create the size you need it
> Dim myArray(3) as String
> will hold 4 strings
>
> then you have to fill it one by one, each element
>
> myArray(0)= "A"
> myArray(1)="B"
> etc
> and also read it one by one
> For i = 0 to 3
> debug.print myarray(i)
> next
>
> hth
> Mark
>
>
0 Likes
Message 7 of 9

Anonymous
Not applicable
Thats good to know,
Thanks

Mark

"Chris Tryon" wrote in message
news:[email protected]...
> Good answer Mark, but remember that the shellsort is on of the slowest
sorts
> for large numbers of items (1000+). Do a search for a mergesort and vb.
The
> mergesort is the fastest sort for more than 15 entities. The general
> strategy would be to use mergesort to break down the list into sub lists
of
> 15 items, then shellsort the small list, and do the recursive merge back
up
> the tree. I have used this often, and it is fast for large lists 60k-100k
> items.
>
> HTH
>
> //chris
> "Mark Propst" wrote in message
>
0 Likes
Message 8 of 9

Anonymous
Not applicable
Here is a good comparison of various sorting algorithms

http://www.vb2themax.com/HtmlDoc.asp?Table=Articles&ID=640

The links to VB/VBA source code for each is provided at the end of the
article.
0 Likes
Message 9 of 9

Anonymous
Not applicable
Thanks Mark,

Works great, but there is one thing left. This is all new to me so that's
why these questions.
The sorting works if I define the number of elements that are in the string
array, but for every drawing this number is different so I want to be able
to make it a variable. But when I do so an error occurs: Constant expression
required.
How can I solve this?

Thanks anyway,
Frank

"Mark Propst" wrote in message
news:[email protected]...
>
> "Frank Jan Koole" wrote in message
> news:[email protected]...
> > I have a few sub's and after searching on the internet, in this NG and
in
> > the help I came to the conclusion that an array is what I'm looking for.
>
> > I also have a sub where I want to fill an array with strings and sort
> those
> > strings alphabatic, but I don't know how?
> > I hope anybody can help me with this and can explain a little about
> array's?
>
> I found it on the web somewhere during many searches for sorting
algorithms
> I don't remember which one should get credit for this version...sorry....
>
> I think this will work for your string array
> Sub SHELLSORTtxt(arr)
> Dim gappos As Integer
> Dim swapped As Boolean
> Dim tmp As Long
> Dim tmpstr As String
>
> gappos = UBound(arr) \ 2
> Do While gappos <> 0
> Do
> swapped = False
> For tmp = 0 To UBound(arr) - gappos
> If (StrComp(arr(tmp + gappos), arr(tmp), vbTextCompare) = -1) Then
> tmpstr = arr(tmp + gappos)
> arr(tmp + gappos) = arr(tmp)
> arr(tmp) = tmpstr
> swapped = True
> End If
> Next tmp
> Loop Until Not swapped
> gappos = gappos \ 2
> Loop
> End Sub
>
> Ive also found some here
> ' Chris Rae's VBA Code Archive - http://chrisrae.com/vba
>
> do a google search on sorting and you'll find many information
>
> basically an array you have to create the size you need it
> Dim myArray(3) as String
> will hold 4 strings
>
> then you have to fill it one by one, each element
>
> myArray(0)= "A"
> myArray(1)="B"
> etc
> and also read it one by one
> For i = 0 to 3
> debug.print myarray(i)
> next
>
> hth
> Mark
>
>
0 Likes