Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Problem

Status
Not open for further replies.
May 31, 2007
31
0
0
AE
Hi All,

I am reading a text file in to an array. the text file has 264 lines. The word REF, appears evey 66 lines (set to Jinf1)

What I am trying to do is read the array element index so i find the first appearence of the word REF. Should I remove the message box alert, the word REF is only picked up from the second occurance. Is there a reason for this?

I am unable to find the reason why it skips the first occurance and only works from the second appreance of the word. I am new to scripting and a bit stuck.. Any help would be sppreciated.



Dim arrSearchThis()

i = 0

Do While (l_textInput.AtEndOfStream <> True)

ReDim Preserve arrSearchThis(i)
arrSearchThis(i) = l_textInput.readline
If InStr(arrSearchThis(i), JInf1) Then
x = i
msgbox (x) ----------> this picks up the first REF occurance
End If
i = i +1
Loop



endline = UBound(arrSearchThis)
tmpline = ""
For newlines = x To endline -----------> Works only from the second occurance of the word REF
tmp = arrSearchThis(newlines) & vbNewLine
tmpline = tmpline & tmp
Next
msgbox (tmpline)
 
For newlines = x To endline

What is the value of x at this point?? If it isn't 0 then that's why you're not seeing the first occurrence.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Hi dm4ever,

i made a mistake, its only working on the last occurance of the word REF. Due to the script looping, i think the value of x is set from the line with the last occurance of the word REF,

For newlines = x To endline -----------> Works only from the last occurance of the word REF

how can i pass the array elememt index (of the first appearence of the word REF) to a variable outside of the first loop?

i think this is where the problem is.

thanks
 
Have you tried...

For newlines = 0 To endline

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
How about this;

Dim arrSearchThis()
i = 0
Dim FirstOccurrence, bFound
FirstOccurrence = 0
bFound = False


Do While (l_textInput.AtEndOfStream <> True)

ReDim Preserve arrSearchThis(i)
arrSearchThis(i) = l_textInput.readline
If InStr(arrSearchThis(i), JInf1) Then
If Not bFound Then
FirstOccurrence = i
bFound = True
End If

End If
i = i +1
Loop

endline = UBound(arrSearchThis)
tmpline = ""
For newlines = FirstOccurrence To endline
tmp = arrSearchThis(newlines) & vbNewLine
tmpline = tmpline & tmp
Next
msgbox (tmpline)
 
Hi guitarzan,

Thanks for the help, exactly what I neeeded.

Much appreciated


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top