Results 1 to 14 of 14

Thread: Almost There!!!

  1. #1

    Thread Starter
    Addicted Member scotty85_2000's Avatar
    Join Date
    Feb 2001
    Posts
    198

    Talking

    Hey, I'm almost there with the commentary thing, I can now load the text file and generate it randomly using arrays (i'm learning fast lol), I now have just one problem:

    In the text file, all the commentary follows the line of:
    P# passes the ball to R#
    P# being passer, R# being receiver.
    However, in the program, P# is already set as T1P1 (as string) and R# as T1R1 (ditto).

    How do I make it so that when P# and R# are loaded, the program says that T1P1 = P# and the name of the player is put in place of it?

    Thanks in advance...

    (I'm almost done once I know how to do this )

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    hmmm this looks familar. Check out your other thread.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3

    Thread Starter
    Addicted Member scotty85_2000's Avatar
    Join Date
    Feb 2001
    Posts
    198

    Unhappy

    i did already and that script wouldn't work, it wouldn't let me put P# as the thing to be replaced, I dunno what was wrong with it...
    anyone have any alternatives?

  4. #4
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    It worked perfectly for me scotty, if you post some code I can probably get it working for you.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  5. #5

    Thread Starter
    Addicted Member scotty85_2000's Avatar
    Join Date
    Feb 2001
    Posts
    198

    Smile

    Right, I'm using the code you gave me. The variables are as follows:

    P# = Passer in Text File
    R# = Receiver in Text File
    T1P1 = Passer in VB Program
    T1R1 = Receiver in VB program

    Do I have to declare P# and R# as variables in the text file? If so, I haven't done it... How do I do it?

    Cheers...

    CODE:

    strSingles(0) = Replace(strSingles(0), "P#", T1P1)
    strSingles(0) = Replace(strSingles(0), "R#", T1R1)
    ' I'm using this code in the Form_Load Sub

    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
    ' This is the replace function

  6. #6
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Well... hum... can you pleas elaborate a bit more on what you're trying to do? Is it a program that takes a text file with comments on a game and replaces the players' name or something?

    If you have an array with all the comments and the replace function, just do this.
    You use players names in the text file in this form: T[team number - 1 or 2]P[player number - between 1 and 11]
    Example: T2P7 passes to T2P3

    Code:
    Dim Comments()
    Dim PlayersT1(1 to 11) As String 'The names of the players of team 1
    Dim PlayersT2(1 to 11) As String 'The names of the players of team 2
    
    PlayersT1(1) = "Name of player 1 of team 1"
    PlayersT1(2) = "Name of player 2 of team 1"
    PlayersT1(3) = "Name of player 3 of team 1"
    '...
    PlayersT2(1) = "Name of player 1 of team 2"
    PlayersT2(2) = "Name of player 2 of team 2"
    PlayersT2(3) = "Name of player 3 of team 2"
    
    '...
    'load each line of the file to Comments(), don't forget to ReDim it first with the number of players and that it starts at element 0
    '...
    
    For i = 0 to UBound(Comments) 'Loop trough all comments
      For j = 1 to 11 'Loop trough all players
        Comments(i) = Replace(Comments(i), "T1P" & j, PlayersT1(j)) 'Replace team 1 names
        Comments(i) = Replace(Comments(i), "T2P" & j, PlayersT2(j)) 'Replace team 2 names
      Next j
    Next i
    Hope that helps!
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  7. #7
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    In order for the code that I sent you to work your text file should look like this.

    "P# Passes to R#"
    P# Throws a Hailmary to R#"
    Etc.....

    and with the Replace function used as shown above P# will be replace with whatever name is held in the T1P1 variable and R# will be replaced with whatever name is held in the R# variable.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  8. #8

    Thread Starter
    Addicted Member scotty85_2000's Avatar
    Join Date
    Feb 2001
    Posts
    198

    Unhappy

    When I run the game, the debug highlights this line:

    -> strSingles(0) = Replace(strSingles(0), "P#", T1P1)
    strSingles(0) = Replace(strSingles(0), "R#", T1R1)

    and says that the subscript is out of range?

    What's going on? I did all of the stuff you told me...

  9. #9
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    That means that you are trying to access an element in the strSingles array that does not exist, how did you declare strSingles?
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  10. #10

    Thread Starter
    Addicted Member scotty85_2000's Avatar
    Join Date
    Feb 2001
    Posts
    198
    Option Explicit
    Dim strSingles(1 to 74) As String

    However, when I change the code to:

    strSingles(1 to 74) = Replace(strSingles(1 to 74), "P#", T1P1)
    strSingles(1 to 74) = Replace(strSingles(1 to 74), "R#", T1R1)

    It highlights the "=" sign and says "Expected End of Statement"

    Any ideas now?

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Replace acts on strings, not arrays. You'll need to loop through doing it to every element.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    To illustrate parksie's point...

    [code]

    Dim i as Integer

    For i = 1 to 74

    strSingles(i) = Replace(strSingles(i), "P#", T1P1)
    strSingles(i) = Replace(strSingles(i), "R#", T1R1)

    Next i
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  13. #13
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Hey, that''s what I did!

    My idea was to replace the names of the players of each team, but it can be easily chenged to "P" or "R". Like this:

    Code:
    Dim strSingles()
    Dim Players(1 to 23) As String 'The names of the players
    'Change it to the number of players: Team 1 + Team 2
    'Example: Players 1-11 (11 players) are from team 1, players 12-23 (11 players) are from team 2
    
    Players(1) = "Name of player 1"
    Players(2) = "Name of player 2"
    Players(3) = "Name of player 3"
    '...
    'Repeat for all the players - it's easier to keep them in an array than to have a lot of variables like "T1P1", "T1P2", "T1P3"...
    
    Open App.Path & "Report.txt" For Input As #1 'Or any other file
    
    i = 0
    
    'Loop trough all the lines of the file...
    
    Do While Not EOF(1)
      'Redim the array to have 1 more element
      i = i + 1
      Redim Preserve strSingles(i)
      
      'Fill the new element with the next line from the file
      Line Input #1, strSingles(i)
      
      'Loop trough all players
      For j = 1 to 11
        'Replace the names (so "P#6" would become the real name of the player 6)
        strSingles(i) = Replace(strSingles(i), "P#" & j, Players(j))
        'Same thing, for "R#"
        strSingles(i) = Replace(strSingles(i), "R#" & j, Players(j))
      Next j
    Next i
    
    Close #1
    Don't forget his "Replace" function. You have to include it too! Try this, it should work.

    If you want to keep the players in separate arrays or load the names of the players from a different file, just tell me.
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  14. #14

    Thread Starter
    Addicted Member scotty85_2000's Avatar
    Join Date
    Feb 2001
    Posts
    198

    Thumbs up

    Thanks to everyone who helped, I finally got it working! Cheers people!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width