-
In a text file which I am loading for commentary in a game, I have a line with "P# passes to R#." In the game, before this text file loads, I already set P# and R# as variables, except under the names T1P1 (as string) and T1R1 (ditto).
How do I make it so that P# = T1P1 and R# = T1R1 when the text file loads? I am already using this code to load the file, so I'd be grateful if u could copy it and add in the code for doing what I want...
Private Sub Form_Load()
Randomize
Dim i As Integer, intCount As Integer, o As Integer
i = FreeFile
Open "C:\WINDOWS\Profiles\Michael's Desktop\My Documents\comment.txt" For Input As #i
Input #1, intCount
For o = 1 To intCount
Line Input #i, strEntranceOne(o)
Next o
End Sub
Cheers...
-
If you have VB6 you can use the Replace function (not sure about the exact syntax as I have VB5, so you may have to fool around with it)...
Code:
strEntrance(0) = Replace(strEntance(0), "P#", T1P1)
strEntrance(0) = Replace(strEntrance(0), "R#", T1R1)
-
when i run this, the debug highlights "replace" and says sub or function not defined
any ideas?
(i'm using VB5E)
-
There is no Replace function for VB5, but here is a substitute I found on this message board on this thread.
Drop this in your project and try the code again....
Code:
' function originally written by Stevie
Public Function Replace(ByVal strSource As String, _
ByVal strWhat As String, _
ByVal strWith As String) As String
'***************************************************************************
'Purpose: Replaces all occurances of one string with another string.
'Parameters: strSource - String to be changed.
' strWhat - What needs replacing.
' strWith - What it should be replaced with.
'Returns: String - The changed string.
'***************************************************************************
Dim intstrWhatLength As Integer
Dim intReplaceLength As Integer
Dim intStart As Integer
intstrWhatLength = Len(strWhat)
If intstrWhatLength = 0 Then
Replace = strSource
Exit Function
End If
intReplaceLength = Len(strWith)
intStart = InStr(1, strSource, strWhat)
Do While intStart > 0
strSource = Left(strSource, intStart - 1) + strWith + Right(strSource, Len(strSource) - (intStart + intstrWhatLength - 1))
intStart = InStr(intStart + intReplaceLength, strSource, strWhat)
Loop
Replace = strSource
End Function