This is my code, (it can save 1000 strings in 5 milliseconds WOOT!). Anyway that's all and good but i was just wondering if there was a better way of doing it? or a way to optimize it faster? any changes? its not quite finished yet...
You can also select which pieces of data from the file to load into memory.
Save a piece of data without having to save the whole file all over again.
Code:
ttime1 = GetTickCount()
Call SaveEditBin("bakekitsune", "data", "IAMDATA", 1000)
ttime2 = GetTickCount()
Call SaveEditBin("bakekitsune", "time", CStr(ttime2 - ttime1))
MsgBox LoadEditbin("bakekitsune", "data", 543)
Code:
Sub SaveEditBin(Name As String, Var As String, Val As String, Optional ByRef ArraySize As Long, Optional ByRef nFileNum As Byte)
Dim i As Long, dbpos As Long
If nFileNum = 0 Then
nFileNum = FreeFile
If ArraySize = 0 Then
Open App.Path & "\" & Name & ".txt" For Binary Access Write Lock Read Write As #nFileNum
Put #nFileNum, AscW(Var) * MAX_CHARS, sC & Var & "=" & Val
Close #nFileNum
Else
dbpos = AscW(Var) + 255
Open App.Path & "\" & Name & ".txt" For Binary Access Write Lock Read Write As #nFileNum
For i = 0 To ArraySize
Put #nFileNum, (dbpos + i) * MAX_CHARS, sC & Var & i & "=" & Val
Next i
Close #nFileNum
End If
End If
End Sub
Function LoadEditbin(Name As String, Var As String, Optional ByRef ArrayNum As Long) As String
Dim nFileNum As Byte, dbcompile As String, dbArray() As String
If ArrayNum = 0 Then
nFileNum = FreeFile
Open App.Path & "\" & Name & ".txt" For Binary Access Read Lock Read Write As #nFileNum
dbcompile = Space$(MAX_CHARS)
Get #nFileNum, AscW(Var) * MAX_CHARS, dbcompile
Close #nFileNum
Else
nFileNum = FreeFile
Open App.Path & "\" & Name & ".txt" For Binary Access Read Lock Read Write As #nFileNum
dbcompile = Space$(MAX_CHARS)
Get #nFileNum, (AscW(Var) + ArrayNum + 255) * MAX_CHARS, dbcompile
Close #nFileNum
End If
dbArray() = Split(dbcompile, "=", MAX_CHARS, vbBinaryCompare)
LoadEditbin = dbArray(1)
End Function
Result: Text file with (you can edit with Notepad and it will come up with the right result)
Code:
time=05
data0=IAMDATA
data1=IAMDATA
data2=IAMDATA
data3=IAMDATA
etc...x1000
In this case data543=IAMDATA if i change data543=OH!YEAH in notepad, then if you ask for data543 then you get OH!YEAH .
>>> PS: Props to Sepiroth for giving me my first lesson in binary ( Yes i optimized it with NO dope! or NOdoze... i always get confused between the two

EDIT: oh yeh kids don't take drugs its NOT cool)