I read line by line a text file.
during the loop i fill My_var with a value.
And My_var can assume the value similar:
AAA
AAA
BBB
CCC
CCC
CCC
...
I need to store into bidimensional array in matrce1 the name of My_var and matrice2 the summ of repetition of same value in this case:
matrice1 matrice2
AAA 2
BBB 1
CCC 3
i hope understand my:-)
other way to store value and uor repettion are welcome
fill array bidimensional
-
- Administrator
- Posts: 78574
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
Re: fill array bidimensional
I get the value of My_var similar:HansV wrote:Is the text file sorted on the value of My_var?
sFileName = " C:\A.txt"
Open sFileName For Input As #1
Do Until EOF(1)
Input#1, sFirststring
If Mid(sFirststring, 1, 5) = "Hello" Then
My_var=Mid(myline, 4,4)...
End If
Loop
ecc....
-
- Administrator
- Posts: 78574
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: fill array bidimensional
So presumably the values of My_var do not occur in ascending order.
I'd enter each value in a new row in a worksheet, and at the end create a pivot table.
Or enter each value in a new record in an Access table and run a totals query to return the unique values with the number of occurrences.
I'd enter each value in a new row in a worksheet, and at the end create a pivot table.
Or enter each value in a new record in an Access table and run a totals query to return the unique values with the number of occurrences.
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 196
- Joined: 31 Mar 2011, 03:41
- Location: Perth, Western Australia
Re: fill array bidimensional
Here is a way of doing it without reference to "external" data structures. If the case of the names is important, then change vbTextCompare to vbBinaryCompare. After loop then can examine aNames in a FOR loop
Code: Select all
'outside loop
'declare vars
Dim sStore As String
Dim sIndex As String
Dim iPos As Integer
Dim iCount As Integer
Dim aNames() As Variant
'initialise stores, counter
iCount = 0
sIndex = ""
sStore = ";"
'inside if test
iPos = InStr(1, sStore, vbTab & my_var & vbTab, vbBinaryCompare)
If iPos = 0 Then
'position in store
sIndex = sIndex & Format(Len(sStore), "00000") & vbTab
'add to store
sStore = sStore & my_var & vbTab
'add to array
ReDim Preserve aNames(1, iCount)
aNames(0, iCount) = my_var
aNames(1, iCount) = 1
'increment counter
iCount = iCount + 1
Else 'already found
iPos = (InStr(1, sIndex, Format(iPos, "00000") & vbTab) - 1) / 6
aNames(1, iPos) = aNames(1, iPos) + 1
End If
-
- Administrator
- Posts: 78574
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: fill array bidimensional
That's clever!
But shouldn't sStore be initialized to
sStore = vbTab
since you use vbTab as delimiter?
But shouldn't sStore be initialized to
sStore = vbTab
since you use vbTab as delimiter?
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 196
- Joined: 31 Mar 2011, 03:41
- Location: Perth, Western Australia
Re: fill array bidimensional
Oops - originally it was, but I changed it to semi-colon then back again but forgot to change that one
If the result had to be alphabetical order then there are a couple of extra steps
If the result had to be alphabetical order then there are a couple of extra steps