Dears,
Lets suppose I have the following database:
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.
Thank you so much
Best regards
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
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
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: