Find all our projects in development below.
All source code is GNU General Public License (GPL)
Browsing MainMod.bas (2.74 KB)
Attribute VB_Name = "MainMod"
Public Function CreateRandomFile(Optional FileExtension As String = "tmp", Optional FileLength As Integer = 8, Optional ExtensionLength As Integer = 3, Optional bIncludeNumbers As Boolean = True, Optional bIncludeLetters As Boolean = True) As String
Dim sTempFile As String
Dim i As Integer
Randomize Timer
If bIncludeNumbers = False And bIncludeLetters = False Then Exit Function
For i = 1 To FileLength + ExtensionLength
If Int(Rnd * 2) Then
If bIncludeNumbers Then
sTempFile = sTempFile & Int(Rnd * 10)
Else
i = i - 1
End If
Else
If bIncludeLetters Then
sTempFile = sTempFile + Chr(Int((122 - 65) * Rnd) + 65)
Else
i = i - 1
End If
End If
If i = FileLength Then
If ExtensionLength > 0 Then sTempFile = sTempFile + "."
If FileExtension <> "" Then
sTempFile = sTempFile + FileExtension
Exit For
End If
End If
Next i
CreateRandomFile = sTempFile
End Function
Public Function GetCmdLineValue(Str As String, Cmd As String) As String
Dim Str2 As String
Dim bCmdFound As Boolean
Dim i As Integer
Dim i2 As Integer
i = 0
i2 = 1
Str2 = LCase(Str)
bCmdFound = False
GetCmdLineValue = ""
If InStr(Str2, Cmd) = 0 Then i2 = 0
Do Until i2 = 0
If Mid(Str2, i + 1, Len(Cmd)) = Cmd Then bCmdFound = True: Exit Do
i = InStr(i + 1, Str2, " ")
i2 = i
Loop
If bCmdFound Then
i = i + Len(Cmd) + 1
Str2 = Mid(Str, i)
If Left(Str2, 1) = Chr(34) And InStr(2, Str2, Chr(34)) > 0 Then Str2 = Mid(Str2, 2, InStr(2, Str2, Chr(34)) - 2)
GetCmdLineValue = Str2
End If
End Function
Public Sub RebuildFile(inFile As String, Optional outFile As String, Optional ByVal StrIn As String, Optional ByVal StrOut As String)
On Error GoTo OpenErr
Dim nFile1 As Integer
Dim nFile2 As Integer
Dim sRandomFile As String
nFile1 = FreeFile
nFile2 = FreeFile + 1
sRandomFile = CreateRandomFile
If StrIn = "" Then StrIn = Chr(10)
If StrOut = "" Then StrOut = vbCrLf
Open inFile For Input As #nFile1
If outFile <> "" Then
Open outFile For Output As #nFile2
Else
Open sRandomFile For Output As #nFile2
End If
Print #nFile2, Replace(Input(LOF(nFile1), nFile1), StrIn, StrOut);
Close #nFile1
Close #nFile2
If outFile = "" Then
Kill inFile
Name sRandomFile As inFile
End If
Exit Sub
OpenErr:
Close
MsgBox "Unexpected Error (Error #" & Err & "): " + Err.Description
End Sub