Results 1 to 17 of 17

Thread: Textfiles

  1. #1

    Thread Starter
    Junior Member MrNick's Avatar
    Join Date
    Mar 2002
    Posts
    28

    Question Textfiles

    Ok, here's something that's stumping me (a novice), and I wonder if any of you experts can help.

    I have a textbox which a user can type into and save the contents, but if they put quotes in:

    He said "I don't think so" as he moved forward

    VB throws a wobbler when loading the text back in and displays only up to the first lot of quotes:

    He said

    I'm using Write #1, to save the text. How do I allow for anything to be typed in and for VB to read it back ok?

    Thanks in advance.
    PHP Code:
    On Error GoTo Hell 
    :¬) MrNick

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Sample that seem to work just fine

    VB Code:
    1. Private Sub Command1_Click()
    2.     'Save the text
    3.     Open "C:\TEST.TXT" For Output As #1
    4.         Write #1, Text1.Text
    5.     Close #1
    6. End Sub
    7.  
    8. Private Sub Command2_Click()
    9.     'Load the text
    10.     Open "C:\TEST.TXT" For Input As #1
    11.         Text1.Text = Input(LOF(1), 1)
    12.     Close #1
    13. End Sub

    if u have to use Write, show us how u do it.
    -= a peet post =-

  3. #3

    Thread Starter
    Junior Member MrNick's Avatar
    Join Date
    Mar 2002
    Posts
    28
    I have many textboxes and everything is saved as one textfile, this is how i'm using it:


    CommonDialog1.InitDir = App.Path 'Initial folder to show
    CommonDialog1.Flags = cdlOFNOverwritePrompt
    CommonDialog1.Filter = "Review Files (*.rvw)|*.rvw|All Files (*.*)|*.*" 'The file types it recognises

    CommonDialog1.DialogTitle = "Plese select the Filename to Save." 'Title

    CommonDialog1.ShowSave 'Show file requester
    Open CommonDialog1.FileName For Output As #1

    Write #1, txtGameTitle.Text
    Write #1, txtReviewer.Text
    Write #1, txtAuthor.Text
    Write #1, cmbGameType.Text
    ..
    ..
    ..


    I'm not exactly sure what you mean by: Text1.Text = Input(LOF(1), 1) peet, as i'm almost a complete novice!
    PHP Code:
    On Error GoTo Hell 
    :¬) MrNick

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Instead of Write
    use
    Print

  5. #5

    Thread Starter
    Junior Member MrNick's Avatar
    Join Date
    Mar 2002
    Posts
    28
    Done that mendhak, but there are also commas in the textfile and when loading it back, it throws a wobbler at the first comma .

    I need to be able to read and extract lines from a textfile no matter what the text is (commas, quotes, sysmbols, whatever).

    any suggestions?
    PHP Code:
    On Error GoTo Hell 
    :¬) MrNick

  6. #6
    Junior Member
    Join Date
    Apr 2002
    Posts
    24
    Hi MrNick

    My Text was like this a,b'c@#$%^&*

    Private Sub Command1_Click()
    'Save the text
    Open "C:\TEST.TXT" For Output As #1
    Print #1, CStr(Text1.Text)
    Close #1
    End Sub

    Private Sub Command2_Click()
    'Load the text
    Open "C:\TEST.TXT" For Input As #1
    ' Text1.Text = Input(LOF(1) - 2, 1)
    Do While Not EOF(1) - 1 ' Loop until end of file.
    Text1.Text = Text1.Text & Input(1, #1) ' Get one character.
    Loop

    Close #1
    End Sub

    This one works fine...
    It's nothing but what Peet and Mendhak has suggested u...


  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    I believe the only problem occurs at double quotes "

  8. #8
    Junior Member
    Join Date
    Apr 2002
    Posts
    24
    Yes Mendhak u r correct

  9. #9

    Thread Starter
    Junior Member MrNick's Avatar
    Join Date
    Mar 2002
    Posts
    28
    I've no doubt that your solution works Padma and i'm greatful, but I haven't a clue what it means . Especially the Input(LOF(1) - 2, 1)!

    It seems that you're reading one char at a time and putting it in a textbox yes?

    I have 10 richtextboxes and I wish to place each line in a seperate richtextbox. Here is my entire save routine:

    Private Sub mnusave_Click()

    CommonDialog1.InitDir = App.Path 'Initial folder to show
    CommonDialog1.Flags = cdlOFNOverwritePrompt
    CommonDialog1.Filter = "Review Files (*.rvw)|*.rvw|All Files (*.*)|*.*" 'The file types it recognises
    CommonDialog1.DialogTitle = "Plese select the Filename to Save." 'Title
    CommonDialog1.ShowSave 'Show file requester

    Open CommonDialog1.FileName For Output As #1

    Write #1, txtGameTitle.Text
    Write #1, txtReviewer.Text
    Write #1, txtAuthor.Text
    Write #1, cmbGameType.Text

    Write #1, cmbGenre1.Text
    Write #1, cmbGenre2.Text
    Write #1, txtOtherGenre.Text

    Write #1, hsrInterface.Value
    Write #1, txtInterface.Text

    Write #1, hsrStory.Value
    Write #1, txtStory.Text

    Write #1, hsrCommands.Value
    Write #1, txtCommands.Text

    Write #1, hsrProblems.Value
    Write #1, txtProblems.Text

    Write #1, hsrLogic.Value
    Write #1, txtLogic.Text

    Write #1, hsrDescription.Value
    Write #1, txtDescription.Text

    Write #1, hsrConversation.Value
    Write #1, txtConversation.Text

    Write #1, hsrWriting.Value
    Write #1, txtWriting.Text

    Write #1, hsrFeatures.Value
    Write #1, txtFeatures.Text

    Write #1, hsrBonus.Value
    Write #1, txtBonus.Text

    Write #1, hsrSupport.Value
    Write #1, txtSupport.Text

    Write #1, txtPros.Text
    Write #1, txtCons.Text

    Write #1, lblscore.Caption

    Write #1, txtAdvice.Text
    errorhandler:
    Close #1
    End Sub


    and the entire LOAD routine:

    Private Sub mnuload_Click() 'Load the Review (text file)

    Dim Temp As String
    CommonDialog1.Filter = "Review Files (*.rvw)|*.rvw|All Files (*.*)|*.*"
    CommonDialog1.DialogTitle = "Plese select the Character to open." 'Title
    CommonDialog1.ShowOpen 'Show file requester
    Open CommonDialog1.FileName For Input As #1 'Use the selected file

    Input #1, Temp
    txtGameTitle.Text = Temp
    Input #1, Temp
    txtReviewer.Text = Temp
    Input #1, Temp
    txtAuthor.Text = Temp
    Input #1, Temp
    cmbGameType.Text = Temp

    Input #1, Temp
    cmbGenre1.Text = Temp
    Input #1, Temp
    If Temp = "(None)" Then Temp = "None"
    cmbGenre2.Text = Temp
    Input #1, Temp
    txtOtherGenre.Text = Temp

    'Interface
    Input #1, Temp
    hsrInterface.Value = Temp
    Input #1, Temp
    txtInterface.Text = Temp

    'The Story
    Input #1, Temp
    hsrStory.Value = Temp
    Input #1, Temp
    txtStory.Text = Temp

    'Commands
    Input #1, Temp
    hsrCommands.Value = Temp
    Input #1, Temp
    txtCommands.Text = Temp

    'Problems
    Input #1, Temp
    hsrProblems.Value = Temp
    Input #1, Temp
    txtProblems.Text = Temp

    'The Logic
    Input #1, Temp
    hsrLogic.Value = Temp
    Input #1, Temp
    txtLogic.Text = Temp

    'RoomDescriptions
    Input #1, Temp
    hsrDescription.Value = Temp
    Input #1, Temp
    txtDescription.Text = Temp

    'Conversation
    Input #1, Temp
    hsrConversation.Value = Temp
    Input #1, Temp
    txtConversation.Text = Temp

    'Writing Style
    Input #1, Temp
    hsrWriting.Value = Temp
    Input #1, Temp
    txtWriting.Text = Temp

    'Extra Features
    Input #1, Temp
    hsrFeatures.Value = Temp
    Input #1, Temp
    txtFeatures.Text = Temp

    'Bonus Points
    Input #1, Temp
    hsrBonus.Value = Temp
    lblBonus.Caption = Temp
    Input #1, Temp
    txtBonus.Text = Temp

    Input #1, Temp
    hsrSupport.Value = Temp
    Input #1, Temp
    txtSupport.Text = Temp

    Input #1, Temp
    txtPros.Text = Temp
    Input #1, Temp
    txtCons.Text = Temp

    Input #1, Temp
    lblscore.Caption = Temp

    Input #1, Temp
    txtAdvice.Text = Temp

    Close #1
    End Sub


    and here's the actual textfile:

    House of the Damned
    davidw
    Sam McCall
    Finished
    Fantasy
    None

    5
    Fairly standard font (Arial, 12) with no fancy use of bold or italics to heighten the effect.
    7
    Fairly interesting idea. Your car breaks down and you end up running through the woods to a haunted house (the House of the Damned of the title) being chased by wolves. Nothing else is known which is a shame because it would have been nice to know a little more about what you are expected to do in the house after your arrival.
    5
    A mixed bunch. Some of the commands were fairly straightforward and logical, others took quite a bit of figuring out (and some I only discovered after looking in the generator). "Use ladder with window" was a confusing one that took some guess-the-verbing and would have been a lot less hassle as "use ladder"' or maybe allowing the player to drop the ladder and then 'climb' it.
    10

    5
    For the most part the puzzles were reasonably logical to figure out but there were a few ("'mix fish with whiskey", "hit tile with hammer" and particularly "use ladder with window") that could have been handled better.
    7
    Above average for the most part - the graveyard was genuinely creepy and there were more than a few locations in the house itself which were well written, although there were also a few that felt a bit flat. But then, how many interesting ways can there be to describe a simple room?
    6
    Only four - two can't be questioned but the other two have quite interesting things to say (if you can figure out what to ask them!)
    7
    Well written for the most part although some of the locations were perhaps a little basic. The graveyard was atmospherically done (the eerie crow being a nice touch). There was also good use of events to indicate the wind howling, a grandfather clock chiming, etc. Character dialogue was interesting without ever really becoming a must-have.
    5
    No advanced features that I could see but the game plays fairly well without and so this isn't a hindrance in any way.
    7
    No hints or walkthrough available but a character who can answer quite a lot of questions makes the game more interesting. Also some quite amusing tasks ('kiss eggbert' and 'drink from toilet') added a little comic element to the proceedings.
    5
    No real instructions or background info (you have no idea who the character is or why he/she is running through the woods at the start of the adventure following their car breaking down). That said, the introduction was well written and the lack of instructions or background isn't a problem that affects playing the game.
    Well written, atmospheric, and more than interesting enough to keep you playing again and again until you finish it.
    Nothing really bad to say about it but the guess-the-verb usage was a little frustrating at times.
    65
    You've created a decient game but it could be improved a lot.



    Could you explain a bit simpler for us VB thickies
    PHP Code:
    On Error GoTo Hell 
    :¬) MrNick

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    no Padma, YOU are correct, because I just tested yours and uhm... everything works.

    even commas.

    Can you try this: asf","dfksl';,as;"

  11. #11
    Junior Member
    Join Date
    Apr 2002
    Posts
    24
    Hi Mendhak,
    Try this by filling text as """" and try to retrieve ...

  12. #12

    Thread Starter
    Junior Member MrNick's Avatar
    Join Date
    Mar 2002
    Posts
    28
    Can anyone help with a simpler solution (I'm only a newbie!)

    Pretty Please
    PHP Code:
    On Error GoTo Hell 
    :¬) MrNick

  13. #13

    Thread Starter
    Junior Member MrNick's Avatar
    Join Date
    Mar 2002
    Posts
    28
    Oops! Made a bit of an error in one of my postings here, they are not richtext boxes, just normal textboxes.
    PHP Code:
    On Error GoTo Hell 
    :¬) MrNick

  14. #14

    Thread Starter
    Junior Member MrNick's Avatar
    Join Date
    Mar 2002
    Posts
    28
    Can anyone help with a simpler solution (I'm only a newbie!)

    Pretty Please?
    PHP Code:
    On Error GoTo Hell 
    :¬) MrNick

  15. #15
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Mr Nick, this is a way to save and load all textboxes and checkboxes using an ini file

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetPrivateProfileString _
    4. Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal _
    5. lpApplicationName As String, ByVal lpKeyName As String, _
    6. ByVal lpDefault As String, ByVal lpReturnedString As _
    7. String, ByVal nSize As Long, ByVal lpFileName As String) As _
    8. Long
    9.  
    10. Private Declare Function WritePrivateProfileString _
    11. Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal _
    12. lpApplicationName As String, ByVal lpKeyName As Any, ByVal _
    13. lpString As Any, ByVal lpFileName As String) As Long
    14.  
    15. Private Function ReadINI(strsection As String, strkey As String, strfullpath As String) As String
    16.    Dim strbuffer As String
    17.    Let strbuffer$ = String$(750, Chr$(0&))
    18.    Let ReadINI$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$))
    19. End Function
    20.  
    21. Private Sub WriteINI(strsection As String, strkey As String, strkeyvalue As String, strfullpath As String)
    22.     Call WritePrivateProfileString(strsection$, UCase$(strkey$), strkeyvalue$, strfullpath$)
    23. End Sub
    24.  
    25. Private Sub cmdLoad_Click()
    26.     Dim sFileName As String
    27.     Dim c As Control
    28.     'Load data from Ini File
    29.     sFileName = App.Path & "\" & Me.Name & ".INI"
    30.     For Each c In Me
    31.         If TypeOf c Is TextBox Then c.Text = ReadINI("DATA_TextBox", c.Name, sFileName)
    32.         If TypeOf c Is CheckBox Then c.Value = Val(ReadINI("DATA_CheckBox", c.Name, sFileName))
    33.     Next c
    34. End Sub
    35.  
    36. Private Sub cmdSave_Click()
    37.     Dim sFileName As String
    38.     Dim c As Control
    39.     'Save data to ini file
    40.     sFileName = App.Path & "\" & Me.Name & ".INI"
    41.     For Each c In Me
    42.         If TypeOf c Is TextBox Then WriteINI "DATA_TextBox", c.Name, c.Text, sFileName
    43.         If TypeOf c Is CheckBox Then WriteINI "DATA_CheckBox", c.Name, c.Value, sFileName
    44.     Next c
    45. End Sub

    I made this for someone else on this forum, (don't remember who )
    Anyway, this is easy to expand in order to cover other controls aswell..

    Mendhak : WHAT THE H*** happened to u'r avatar ??? ... cool
    -= a peet post =-

  16. #16
    vshammas
    Guest
    VB throws a wobbler when loading the text
    what kind of thing "throws a wobbler"?

  17. #17

    Thread Starter
    Junior Member MrNick's Avatar
    Join Date
    Mar 2002
    Posts
    28
    Thanks to all who've helped I've now solved the problem quite simply; instead of reading the textfile with Input #1,<whatever>, i used Line Input #1,<whatever>.

    Thanks again.
    PHP Code:
    On Error GoTo Hell 
    :¬) MrNick

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