Results 1 to 9 of 9

Thread: Large text files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118
    I am writing an interactive story program, and need to insert the users name and a friends name into the story. I don't have to write the story in a module to get the program to insert "strUser" and "strFriend" into the story do I? Can I put the story in the same directory as the program. The main problem is there will be a lot of different stories and one story in a module is hard enough to proof.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Canada
    Posts
    264

    Cool

    Your question is a bit unclear to me, Can't you use text files ? you can create text files from a VB program..
    In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.

    - Douglas Adams
    The Hitchhiker's Guide to the Galaxy

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118
    I want to have different stories already written. Maybe one about a train ride, one about a hot air balloon ride, and so on. The user can choose an adventure with option buttons, enter his name and a friends name in an input box and click a cmdButton to load his story into a large txtBox with his name and a friends name as the characters of the story. I can do this by writting the story in a module, but I would like to be able to Call the story from the cmdButton, and have the names entered in the strUser and strFriend locations in the story. How can I do this.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118
    I want to have different stories already written. Maybe one about a train ride, one about a hot air balloon ride, and so on. The user can choose an adventure with option buttons, enter his name and a friends name in an input box and click a cmdButton to load his story into a large txtBox with his name and a friends name as the characters of the story. I can do this by writting the story in a module, but I would like to be able to Call the story from the cmdButton, and have the names entered in the strUser and strFriend locations in the story. How can I do this.

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Well, If I were going to write it I would write the stories first in text files and save them with the same extention (eg .sty) then the program checks what text files are in the local or "Story" directory and puts their titles in a list box to be opened.

    I'm not really sure how interactive these stories are so I'll have to guess but in the text file you put tags #Friend1# #Friend2# etc then using the replace() function swap in the names.

    You might want to put a header in the story for extra info when you load it like
    TITLE:"TRAIN RIDE"
    FRIENDS:4
    so you can have info for the reader when they choose from the text box. In fact a header scheme could block the story so it could work like a choose your own adventure! Sorry, getting a bit carried away

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    simple version

    This is a simplified version of how I do it now.
    Option Explicit
    Dim strUser As String
    Dim strFriend As String
    Dim strStory As String

    Private Sub TrainStory()
    strStory = strFriend & " and " & strUser & " when for a train ride."
    End Sub

    Private Sub Command1_Click()
    If optTrainStory = True Then
    strFriend = InputBox("Enter a friends name")
    strUser = InputBox("Enter your name")
    TrainStory
    End If
    Text1.Text = strStory
    End Sub

    I tried to open a text file from my program, but all I got in the textbox was the path. How do I open it so I can get my variable in it? Syntax anyone.

  7. #7
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    ????

    -Use the Open command to load a text file to a string
    -OR, take a short cut and use a richtextbox control, it hold more text and has a load file method.

    eg

    Code:
    RTFBox.Visible = False 'Hide the tacky variables in the text from the reader
    RFTBox.Loadfile ("C:\story1.txt")
    RTFBox.text = Replace(RTFBox.Text, "Friend1", Username)
    RTFBox.Visible = True
    ' if you have a lot of usernames to add and the story is very long
    ' you will get better perfomance by dumping the rtfbox text to a string and running the replace commands against that.
    [Edited by Paul282 on 04-13-2000 at 09:39 PM]

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    Thank you Paul282

    Thanks, it is just what I needed. I took a while to figure out you named three RTF's and one RFTBox. See why I needed the help?

  9. #9
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Just remember if you're you doing a lot of text editing and you don't need the RTF stuff (colour etc) work with a string variable, the difference is huge,

    so use

    Code:
    Dim MyStr as String
    Dim FindLoop as long
    
    MyStr = RTFBox.Text
    
    For FindLoop = 1 to 1000
        Instr(1,"Hello",MyStr
    Next
    
    RTFBox.text = MyStr
    NOT

    Code:
    Dim MyStr as String
    Dim FindLoop as long
    
    For FindLoop = 1 to 1000
        RTFBox.Find(1,"Hello", MyStr)
    Next
    I didn't test the code so I don't know if the function vars are in the right order but the difference in performance is HUGE, where possible don't work directly with RTFbox.text

    Have a good one

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