This one is not the best implementation (your specifications does ot need keys, just indices)
Much slower(*), consummes memory and requires a library (viewtopic.php?f=8&t=26533), BETA state.
Depending on what you expect to do you might appreciate using it (if only for 'short' syntax).
(on previous versions of the compiler, I could load bigger string if string type not in an array when loading lots of strings)
(*) : In most of user cases user will not notice.
Code: Select all
#Include once "D:\Basic\LZLE.bi"
Dim MyList As List
Dim As String file_name, text, StrNumLigne
Dim As Integer file_num, indice=0
file_name = "D:\Basic\Filename.ext"
file_num = FreeFile( )
If( Open( file_name For Input As #file_num ) ) Then
Print file_name & " not opened"
Else
Do Until EOF( file_num ) '' loop until we have reached the end of the file
Line Input #file_num, text '' read a line of text ...
MyList.HashTag(Str(indice)) : MyList.Val(text)
indice+=1
Loop
Close #file_num
End If
Randomize , 1
StrNumLigne=Str(Int(Rnd * indice))
MyList.HashTag( StrNumLigne )
Print "Line " & StrNumLigne & " = " & MyList.Val
Sleep
System
Code: Select all
'Persistent parameters (need to be set one time)
MyList.NFRecursive(1) 'Optional : forces dynamic reuse of obsolete index entries (automatic only when NodeFlat is in a loop)
MyList.NFmethod(-1) 'Indicates destination for NodeFlat (GarbageCollector)
'For each element you want to delete/substract
MyList.HashTag( ValidKey ) : MyList.NodeFlat 'If key is not valid a empty element will be created then send to "GarbageCollector"
' Or
If MyList.HasKey( ValidKey ? ) Then : MyList.NodeFlat : End If ' (slower) (Check NFmethod and AutoCursor)
PS : Welcome to FreeBasic :-)