Store some TXT values into an Array - New Type of Question

blelli

Board Regular
Joined
Jul 21, 2013
Messages
63
Dears,

Lets suppose I have the following database:
P|GEKU1A|15|KOSVO|0|7​
S|BUVBA|-25594833|-49101500|CPN|CF|0|15400|18870|23460|500|260|0|0|0|0|0|0|0​
S|GEKUD|-25523178|-49023769| |TF|0|0|0|0|0|260|0|0|0|0|0|0|0​
S|GEKUD|-25523178|-49023769| |IF|0|0|0|0|0|260|0|0|0|0|0|0|0​
S|CT062|-25459864|-49042603| |TF|0|0|0|0|0|0|1|8000|0|0|0|0|0​
S|CT063|-25316097|-49085289| |TF|0|0|0|0|0|0|1|11000|0|0|0|0|0​
S|MULKU|-25069961|-49166711| |TF|0|0|0|0|0|0|0|0|0|0|0|0|0​
S|KOSVO|-24972014|-49166511| |TF|0|0|0|0|0|0|0|0|0|0|0|0|0

P|GEKU1A|15|KOXAG|0|11
S|BUVBA|-25594833|-49101500|CPN|CF|0|15400|18870|23460|500|260|0|0|0|0|0|0|0
S|GEKUD|-25523178|-49023769| |TF|0|0|0|0|0|260|0|0|0|0|0|0|0
S|GEKUD|-25523178|-49023769| |IF|0|0|0|0|0|260|0|0|0|0|0|0|0
S|UTPOP|-25503747|-48866350| |TF|0|0|0|0|0|0|1|10000|0|0|0|0|0
S|ANKEX|-25485658|-48768717| |TF|0|0|0|0|0|0|2|14000|0|0|0|0|0
S|TEKES|-25468533|-48676664| |TF|0|0|0|0|0|0|2|16000|0|0|0|0|0
S|CT026|-25445506|-48553461| |TF|0|0|0|0|0|0|1|18000|0|0|0|0|0
S|RODEB|-25402997|-48327733| |TF|0|0|0|0|0|0|0|0|0|0|0|0|0
S|EDVEB|-25325158|-47978967| |TF|0|0|0|0|0|0|2|24000|0|0|0|0|0
S|ERODU|-25239447|-47503094| |TF|0|0|0|0|0|0|0|0|0|0|0|0|0
S|KOXAG|-25143117|-46978917| |TF|0|0|0|0|0|0|0|0|0|0|0|0|0

P|GEKU1B|15|EDVEB|0|9
S|BUVBA|-25594833|-49101500|CTB|CF|0|15400|520|15630|500|240|0|0|0|0|0|0|0
S|GEKUD|-25523178|-49023769| |TF|0|0|0|0|0|240|0|0|0|0|0|0|0
S|GEKUD|-25523178|-49023769| |IF|0|0|0|0|0|240|0|0|0|0|0|0|0
S|UTPOP|-25503747|-48866350| |TF|0|0|0|0|0|240|0|0|0|0|0|0|0
S|ANKEX|-25485658|-48768717| |TF|0|0|0|0|0|0|0|0|0|0|0|0|0
S|TEKES|-25468533|-48676664| |TF|0|0|0|0|0|0|0|0|0|0|0|0|0
S|CT026|-25445506|-48553461| |TF|0|0|0|0|0|0|0|0|0|0|0|0|0
S|RODEB|-25402997|-48327733| |TF|0|0|0|0|0|0|2|11000|0|0|0|0|0
S|EDVEB|-25325158|-47978967| |TF|0|0|0|0|0|0|0|0|0|0|0|0|0


And I want to find the following line: P|GEKU1A|15|KOXAG|0|11

When it's found I, how can I store all the 11 lines starting with "S|" and the 19 columns (the red selected text above) into an Array called SID? I believe it should be a Multidimensional Array, right?

I'm currently working with the following code but it's not working.

Code:
Sub FindAirportDep()

    Dim fn As String, txt As String, delim As String, SidInfo() As String, coluna As String
    Dim i As Long, ii As Long, iii As Long, n As Long, X, y
    fn = "C:\Users\bruno\Desktop\SBCT.txt"      'Mude aqui (Caminho do aquivo)
    delim = "|"                                     'Mude aqui (Delimitador)
    temp = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll
    X = Split(temp, vbCrLf)
    
    RW = "15"
    SID = "GEKU1A"
    TRANS = "KOXAG"
    
    ItemProcurado = SID & "|" & RW & "|" & TRANS
     coluna = 0
    
    ReDim y(1 To 10, 0 To 18)
    For i = 0 To UBound(X)
        If InStr(1, X(i), ItemProcurado, 1) > 0 Then
           
            contador = 0
            Do While InStr(1, X(i + 1), "S|", 1) > 0
            contador = contador + 1
            i = i + 1
            Loop
        
            i = i - contador
            'ReDim SidInfo(2 To contador + 1, 1 To 19)
            ReDim SidInfo(0 To 1000, 0 To 18)
            Do While InStr(1, X(i + 1), "S|", 1) > 0
    
                n = n + 1:
                y = Split(X(i + 1), delim)
                
                
                ' I believe that here is the problem. Because the code is finding everything properly, but I can't store it.
                For ii = 0 To UBound(y)
                    SidInfo(i, coluna) = y(ii)
                Next
                coluna = coluna + 1
                
            i = i + 1
            
            Loop
            
        End If
    Next
    




'Clear everything from memory
temp = Empty: M = Empty: contador = Empty: X = Empty: y = Empty: Lin = Empty: pistas = Empty
i = Empty: ii = Empty: iii = Empty: n = Empty: delim = Empty: fn = Empty: txt = Empty


End Sub
Thank you so much
Best regards
 
Last edited:

blelli

Board Regular
Joined
Jul 21, 2013
Messages
63
Dears,

I think it's working now...
Thank you

Sub FindAirportDep()


Dim fn As String, txt As String, delim As String, SidInfo() As String, SidRange() As String
Dim i As Long, ii As Long, iii As Long, n As Long, X, y
fn = "C:\Users\bruno\Desktop\SBCT.txt" 'Mude aqui (Caminho do aquivo)
delim = "|" 'Mude aqui (Delimitador)
temp = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll
X = Split(temp, vbCrLf)

RW = "15"
SID = "GEKU1A"
TRANS = "KOXAG"

ItemProcurado = SID & "|" & RW & "|" & TRANS

'Define the array range SidRange
ReDim SidRange(1 To UBound(X) + 1, 0 To 18)


For i = 0 To UBound(X)
'Search for ItemProcurado
If InStr(1, X(i), ItemProcurado, 1) > 0 Then

'When found, slipt the line to collect the number of lines ahead with "S|"
y = Split(X(i), delim)
Elementos = y(5)

ReDim SidInfo(0 To Elementos - 1, 0 To 18)
For j = 0 To Elementos - 1
y = Split(X(i + 1), delim)
For k = 0 To 18

SidInfo(j, k) = y(k)

Next k
i = i + 1
Next j

End If

Next i


End Sub
 

Forum statistics

Threads
1,082,176
Messages
5,363,577
Members
400,751
Latest member
wheddingsjr

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top