the file contains thousands of records, items from a warehouse, with vb6 I can manage them well, I am new to B4A, I have not studied enough yet, you never study enough. excuse me
now I study the suggestions
You were given all the necessary advices in post #4 and you did not follow a single one of them. By the way, for code tags, see post#4 again on how you need to do it to post code properly.with 155000 it stops and does not give the result.
It helps that the file is sorted - it means you can abandon the search as soon as you reach a product code greater than the code you're looking for.
There should be no problem with doing a linear search, other than it taking a while. If speed is an issue, then I'd just construct a file of 32-bit pointers to the lines of the file (only needs to be done once, on first access to a modified file) and then just do a binary search, = around 26 disk accesses per lookup for your 10000 record file, or 34 disk access per lookup for your 144000 record file (or half as many if you keep the line-start-pointer file in memory, given that 144000 records x 4 bytes/pointer = 576 kB ie < 1 MB)
Maybe later when you feel comfortable with the forum, your file will be most suitable for SQLite database as Peter suggested because of the large number of records. However, if you want to use it as a text file, I recommend parsing it using StringUtils LoadCSV since you have several records with empty fields, it is easier to parse with StringUtils than with RegEx. Here is a snippet, but I can post an entire project if you so desire and are not overwhelmed. Even if there is no interest now, you get the point that there are sometimes more than one way:I'm learning and that's okay, that's what I want to get to
MyList =su.LoadCSV(File.DirAssets, "anaiper10000.txt", ",") 'add the file to the files folder
Private Sub Button1_Click
l_codice.Text=""
l_descrizione.Text=""
l_prezzo.Text=""
Dim t1 As Long =DateTime.Now
For i=0 To MyList.Size-1
Dim row() As String= MyList.Get(i)
If t_codice.Text= row(0) Then
l_codice.Text =row(0)
l_descrizione.Text =row(1)
l_prezzo.Text = row(2)
Exit
End If
Next
If i = MyList.Size Then
Log("not found")
Else
Dim t2 As Long =DateTime.Now
Log($"Rec no:${i+1} ${CRLF} Took: ${t2-t1} millisec"$)
End If
End Sub
Thanks for the encouragement, I'm learning and that's okay, that's what I want to get to, the file is sorted, but I don't know how to create the pointer, how to say go to the middle of the file and if bigger go to the middle between this and the last, or smaller, you go halfway between this and the first ... I don't know I can be clear
Sub cmdByLine_Click
..
Do While bolFound = False
OneRow = MyList.Get(Half)
If txtSearch.Text > OneRow.PNum Then
If Half = MyList.Size - 1 Then
bolFound = False
Exit
End If
Lower = Half
Half = (Half + Upper) /2
Else If txtSearch.Text < OneRow.PNum Then
If Half = 0 Then
bolFound = False
Exit
End If
Upper = Half
Half = (Half + Lower)/2
Else
bolFound = True
intFound = Half
Exit
End If
Loop
End Sub
While you're on a roll, I've got two words for you: interpolation search. ?Then you just chop the list in half down the middle, left or right until you get your answer - it is STUPID fast on this 10,000 list.
While you're on a roll, I've got two words for you: interpolation search. ?
(also one word - hashing - but given that the original data was sorted, plus that it might later be advantageous to be able to search using an incomplete product key, binary search seemed the better choice)
If you have a Google Email (Gmail) then you can upload it to your Google Drive and make it (anybody with link can access) public.would like to attach the 160k file but it's too big (900k). how can I do to send it?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?