comparing content of arrays

G

Gerrit Kiers

Hi

I have an array A of strings. I made two new arrays (B and C) and some
code put the strings from array A either in array B or in array C or
is disregarded it altogether.

Now I want to add an extra field to array A in whinch I want to store
the numerical value 0 if the string was disregarded, 1 if found in
array B and 2 if found in array C.

Could you help? I'm lost while trying to nest this in for .. next and
if statements.

I am primarely lost in multi-dimensional arrays. Please point me to
any good reference on the Web on this topic. I mean problems like
assigning values, reading out, defining LBound, etc. in
multidimensions

Gerrit
 
G

Gerrit Kiers

I am primarely lost in multi-dimensional arrays. Please point me to
any good reference on the Web on this topic. I mean problems like
assigning values, reading out, defining LBound, etc. in
multidimensions

You see, I just don't seem to get it. If I have to define my LBound in
such a manner:

intIndexofFirstCol = LBound(StateData,1)

then (AFAIKS) using the multdimensional array forces me to define
array for the different single dimensions. That was just the step I
wanted to skip altother. So where is the gain?

Thanks again, Gerrit
 
T

Tushar Mehta

This is a case where a data structure more appropriate to the task at
hand would be very beneficial. Instead of a multi-dimensional array,
use an array of a user defined type

Option Explicit

Type SrcData
DataVal As Long
RecipientID As Long
End Type
Sub testIt()
Dim ArrA(1 To 1000) As SrcData, ArrB() As Long, ArrC() As Long, _
i As Long
ReDim ArrB(LBound(ArrA) To UBound(ArrA))
ReDim ArrC(LBound(ArrA) To UBound(ArrA))
For i = LBound(ArrA) To UBound(ArrA)
ArrA(i).DataVal = i
Next i
For i = LBound(ArrA) To UBound(ArrA)
With ArrA(i)
Select Case i Mod 3
Case 0: .RecipientID = 0
Case 1: ArrB(i) = .DataVal: .RecipientID = 1
Case 2: ArrC(i) = .DataVal: .RecipientID = 2
End Select
End With
Next i
End Sub

--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
G

Gerrit Kiers

I have an array A of strings. I made two new arrays (B and C) and some
code put the strings from array A either in array B or in array C or
is disregarded it altogether.

Now I want to add an extra field to array A in whinch I want to store
the numerical value 0 if the string was disregarded, 1 if found in
array B and 2 if found in array C.

Could you help? I'm lost while trying to nest this in for .. next and
if statements.

Hope someone is reading ;-)

Solved it, not a beaty, couldn't use LBound or UBound, had to go
through all arrays far to many times. Luckely dealing with very small
arrays.

giSeries is number of strings in garSeriesLbl(1, i)
These strings are either deleted or distributed over 2 listboxes:
lbYAxis1 and lbYAxis2

garSeriesLbl(1, i) is the new array.

For i = 1 To giSeries ' options base 1
garSeriesCht(1, i) = garSeriesLbl(1, i)
j = 0
Do Until j > lbYAxis1.ListCount - 1
If garSeriesLbl(1, i) = lbYAxis1.List(j) Then
garSeriesCht(2, i) = 1
Exit Do
Else
j = j + 1
End If
Loop
j = 0
Do Until j > lbYAxis2.ListCount - 1
If garSeriesLbl(1, i) = lbYAxis2.List(j) Then
garSeriesCht(1, i) = garSeriesLbl(1, i)
garSeriesCht(2, i) = 2
Exit Do
Else
j = j + 1
End If
Loop
If garSeriesCht(2, i) = "" Then garSeriesCht(2, i) = 0
Next i
 
G

Gerrit Kiers

This is a case where a data structure more appropriate to the task at
hand would be very beneficial. Instead of a multi-dimensional array,
use an array of a user defined type

Option Explicit

Type SrcData
DataVal As Long
RecipientID As Long
End Type
Sub testIt()
Dim ArrA(1 To 1000) As SrcData, ArrB() As Long, ArrC() As Long, _
i As Long
ReDim ArrB(LBound(ArrA) To UBound(ArrA))
ReDim ArrC(LBound(ArrA) To UBound(ArrA))
For i = LBound(ArrA) To UBound(ArrA)
ArrA(i).DataVal = i
Next i
For i = LBound(ArrA) To UBound(ArrA)
With ArrA(i)
Select Case i Mod 3
Case 0: .RecipientID = 0
Case 1: ArrB(i) = .DataVal: .RecipientID = 1
Case 2: ArrC(i) = .DataVal: .RecipientID = 2
End Select
End With
Next i
End Sub


Wow, how do you do that? ;-)
Thanks!! I will study it and apply it.
 

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