Loading everything, before comparison, makes the "search" unbearably slow.
(that referres, to the current code ...)
Below a "simple" and therefore "fast" search Function returning simply found/
NOT found (all other processing, if it returns TRUE only | error otherwise):
Code: Select all
' since, Freefile returns a Long (parameter = Long)
Function SearchProduct( _
ByVal ProductFileNumber As Long, _
ByVal BarcodeNumber As String _
) As Boolean ' TRUE = found | FALSE = NOT found
' assuming ProductFileNumber is already "open", by caller ...
While Not EOF(ProductFileNumber)
Input #ProductFileNumber, Product_barcodenumber ' that's all we need for comparison!
If Trim(BarcodeNumber) = Trim(Product_barcodenumber) Then Return TRUE
Wend
Return FALSE
End Function
Alternative: returning line number (found) or null (NOT found):
Code: Select all
' since, Freefile returns a Long (parameter = Long)
Function SearchProduct( _
ByVal ProductFileNumber As Long, _
ByVal BarcodeNumber As String _
) As ULong ' > 0 = line number | 0 = NOT found
' assuming ProductFileNumber is already "open"
Dim As ULong cnt = 1
While Not EOF(ProductFileNumber)
Input #ProductFileNumber, Product_barcodenumber ' that's all we need for comparison!
If Trim(BarcodeNumber) = Trim(Product_barcodenumber) Then Return cnt
cnt += 1 ' increment line counter
Wend
Return 0 ' indicate error "NOT found"
End Function
That's all, as far as I'm wanting to get involved, in your code.
(I'm not about to lie, saying "I've no time" or similar, I've no interest, to get any
further involved.)