Code: (Select All)
Screen _NewImage(1024, 720, 32)
Const Num_Words = 176049
Const Seperator = Chr$(34) + "," + Chr$(34)
Const File$ = "Z:\Dict(CSV).txt"
Type Dict_Type
word As String
type As String
definition As String
End Type
Dim Dict(1 To Num_Words) As Dict_Type
Open File$ For Input As #1
t# = Timer
For i = 1 To Num_Words / 100
Input #1, Dict(i).word, Dict(i).type, Dict(i).definition
Next
Close
Open File$ For Binary As #1
t1# = Timer
For i = 1 To Num_Words
Line Input #1, text$
l = InStr(text$, Seperator)
r = InStr(l + 3, text$, Seperator)
Dict(i).word = _Trim$(Mid$(text$, 2, l - 2))
Dict(i).type = Mid$(text$, l + 3, r - l - 3)
Dict(i).definition = Mid$(text$, r + 3, Len(text$) - r - 3)
Next
Close
t2# = Timer
Print Using "###.### seconds"; (t1# - t#) * 100
Print Using "###.### seconds"; t2# - t1#
Sleep
For i = 1 To 10
Print Dict(i).word, Dict(i).type, Dict(i).definition
Next
Sleep
For i = Num_Words To Num_Words - 10 Step -1
Print Dict(i).word, Dict(i).type, Dict(i).definition
Next
Note this uses the file here: https://qb64phoenix.com/forum/showthread.php?tid=3648
This just shows that INPUT alone is sufficient to read our data file as it exists, but that it's sloooow. If the time involved isn't an issue for you, feel free to just use INPUT to read the CSV file and work with it.
This also shows how to read the file FOR BINARY and parse it, which is about 50 times faster and drops speed from 48 seconds on my machine to less than 1 second.
Note that you can also simply read the file in one go with _READFILE$, then parse it in a similar manner as above, and it'd be even faster for you. In this case, the 1 second load time is fine for anything I might use it with, so I thought I'd share and highlight the difference in input speed for us, for those folks who are always asking, "How can I make this run faster".
NOTE 2: EDIT THE FILE PATH TO THE FILE ON YOUR SYSTEM.

