Results 1 to 6 of 6

Thread: load file gives unknown characters

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    182

    Question load file gives unknown characters

    i have a save a load procedure in my app in this case i am using text box1. so the problem starts when i load a file.

    i.e. if i enter data in textbox1 and click save the file saves successfully and if i exit the app and reopen it and click select load and load the file just saved it loads with two mysterious and unknown characters at the end. but if i select property of text box 1 and click multi line to true then the characters will not be displayed.

    Code:
    Private Sub Cmdsave_Click()
        cdlg.ShowSave
        SaveText Text1, cdlg.FileName
    End Sub
    
    Private Sub Cmdload_Click()
        cdlg.ShowOpen
        Text1 = LoadText(cdlg.FileName)
    End Sub
    module code

    Code:
    Option Explicit
    Public Function LoadText(FromFile As String) As String
    On Error GoTo Handle
    'Checking if the file currently exists
    If FileExists(FromFile) = False Then MsgBox "File not found. Check if the file is Currently exists.", vbCritical, "Sorry": Exit Function
    Dim sTemp As String
        Open FromFile For Input As #1   'Open the file to read
            sTemp = Input(LOF(1), 1)    'Getting the text
        Close #1                        'Closing the file
        LoadText = sTemp
    Exit Function
    Handle:
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description, vbCritical, "Error"
    End Function
    Public Function SaveText(Text As String, FileName As String) As Boolean
    On Error GoTo Handle
    Dim sTemp As String
        sTemp = Text
    Dim FF As Integer
        FF = FreeFile
        Open FileName For Output As #FF  'Opening the file to SaveText
            Print #FF, sTemp             'Printing  the text to the file
        Close #FF                        'Closing
        If FileExists(FileName) = False Then    'Check whether the file created
            MsgBox "Unexpectd error occured. File could not be saved", vbCritical, "Sorry"
            SaveText = False    'Returns 'False'
        Else
            SaveText = True     'Returns 'True'
        End If
    Exit Function
    Handle:
        SaveText = False
        MsgBox "Error " & Err.Number & vbCrLf & Err.Description, vbCritical, "Error"
    End Function
    Public Function FileExists(FileName As String) As Boolean
    'This function checks the existance of a file
    On Error GoTo Handle
        If FileLen(FileName) >= 0 Then: FileExists = True: Exit Function
    Handle:
        FileExists = False
    End Function
    Last edited by adam786; Jul 17th, 2008 at 03:15 PM.

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