Hello VB friends,
I have the following usual lines of code written to open a database in the text format. The database has 5 columns but for me are useful only two (col1 and col 3, which contain cities). My goal is to join these two columns in a single string (bigCities). I used the Input method because I have considered it is fast enough for my needs and a two dimensional array (myArr).
The issue is that I don't now how to avoid to load other 3 unuseful columns as long as I need only 2...I wonder if there are other more suitable aproach.
After that, I had to extract the useful columns (1 and 3) in this way:Code:Dim fnum As Integer, i As Long Dim myArr() As String, bigArray As String Dim bigCities As String ReDim myArr(1 To 5, 10000) fnum = FreeFile Open "myFile" For Input As #fnum i = 0 Do While Not EOF(fnum) Input #fnum, myArr(1, i), myArr(2, i), myArr(3, i), myArr(4, i), myArr(5, i) i = i + 1 Loop Close #fnum
And, finally, we will have:Code:ReDim bigArray(1 To UBound(myArr, 2)) For i = 1 To UBound(myArr, 2) bigArray(i) = myArr(1, i) & " " & myArr(3, i) & " " Next i
Even the result is ok I feel the right approach should be other, a simpler one...Code:bigCities = Join(bigArray)
For example, I think the last next-for looping could be, in a way, avoided. But how?Thank you in advance.
Daniel


Thank you in advance.
Reply With Quote

