Results 1 to 12 of 12

Thread: [RESOLVED] Saving textbox.text to file as written

Threaded View

  1. #1

    Thread Starter
    Lively Member VisualBrian's Avatar
    Join Date
    Nov 2019
    Location
    North America
    Posts
    72

    Resolved [RESOLVED] Saving textbox.text to file as written

    I have a routine that saves multiple vars to a file...

    Code:
        Friend Sub SaveMap()
            Try
                For Each ctrl In Me.Controls.Cast(Of Control)().ToArray()
                    If ctrl.Tag = "room" Then
                        FileOpen(3, MapDir & ctrl.Name & ".room", OpenMode.Input)
                        RoomName = LineInput(3)
                        RoomTag = LineInput(3)
                        RoomSize = LineInput(3)
                        RoomLeft = LineInput(3)
                        RoomTop = LineInput(3)
                        RoomWidth = LineInput(3)
                        RoomHeight = LineInput(3)
                        RoomImage = LineInput(3)
                        RoomText = LineInput(3)
                        FileClose(3)
                        FileOpen(3, MapDir & ctrl.Name & ".room", OpenMode.Output)
                        ' name, tag, RoomSize, left, top, width, height, RoomImage, RoomText
                        ' get room size
                        Select Case ctrl.Width
                            Case Is = GridSize
                                If ctrl.Height = GridSize Then
                                    RoomSize = "small"
                                Else
                                    RoomSize = "tall"
                                End If
                            Case Is = GridSize * 2
                                If ctrl.Height = GridSize Then
                                    RoomSize = "wide"
                                Else
                                    RoomSize = "large"
                                End If
                        End Select
                        Print(3, RoomName & vbNewLine & RoomTag & vbNewLine & RoomSize & vbNewLine & ctrl.Left & vbNewLine & ctrl.Top & _
                         vbNewLine & ctrl.Width & vbNewLine & ctrl.Height & vbNewLine & RoomImage & vbNewLine & RoomText)
                        FileClose(3)
                    End If
                Next
                ' save MapFile
                FileOpen(3, MapFile, OpenMode.Output)
                Print(3, MapTemplate)
                FileClose(3)
            Catch ex As Exception
                MsgBox("While SaveMap()..." & vbNewLine & ex.Message)
            End Try
        End Sub
    My thought was to use Do Until EOF(3) to read all the "RoomText" at the end of the file, but RoomText does not get printed to the file as written. Only the first paragraph.

    The problem is that with "RoomText", only the first line of text is saved to the file. Anything after a 'return' in the TextBox is ignored, so I can only save one (the first) paragraph. The textbox is set to accept returns. I have tried this with a normal text box and a richtextbox. Other than using File.WriteAllText to a dedicated file for the text alone, I have not found a way to save the text, or read it back, as written to the Mapfile, with the other vars.

    What am I missing? How do I save and recover the text as written in the textbox?
    Last edited by VisualBrian; Dec 1st, 2023 at 10:46 PM.
    I may not know anything, but I know it well!

Tags for this Thread

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