How can you make a FreeBASIC file read from a text file.
Basically how it works:
When executed, the binary will read from a text file then find a text in that text file then execute a function.
How can i make a FB file find something from a text file?
Re: How can i make a FB file find something from a text file?
Simple example
Code: Select all
Function load(file As String) As String
Dim As Long f=Freefile
If Open (file For Binary Access Read As #f)=0 Then
Dim As String text
If Lof(f) > 0 Then
text = String(Lof(f), 0)
Get #f, , text
End If
Close #f
Return text
Else
Print "Unable to load " + file:Sleep:End
End If
End Function
Sub save(filename As String,p As String)
Dim As Integer n
n=Freefile
If Open (filename For Binary Access Write As #n)=0 Then
Put #n,,p
Close
Else
Print "Unable to save " + filename:Sleep:End
End If
End Sub
save("tester.txt","notepad " + chr(34)+ rtrim(command(0),"exe")+"bas"+chr(34))
dim as string L=load("tester.txt")
print L
shell L
Sleep
Kill "tester.txt"
Re: How can i make a FB file find something from a text file?
Function that searches for a sub-string in a text file:
- If the sub-string is found, the function returns the corresponding line of text from the file (the first line where the sub-string is found).
- Otherwise (including file not found), a null string is returned.
- If the sub-string is found, the function returns the corresponding line of text from the file (the first line where the sub-string is found).
- Otherwise (including file not found), a null string is returned.
Code: Select all
Function searchInFile(Byref file As String, Byref search As String) As String
Dim As Long f = Freefile
Function = ""
If Open (file For Input As #f) = 0 Then
Dim As String text
Do While Not EOF(f)
Line Input #f, text
If Instr(text, search) > 0 Then
Function = Text
Exit Do
End If
Loop
Close #f
End If
End Function