Results 1 to 4 of 4

Thread: [RESOLVED] simple change... help me plz

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Resolved [RESOLVED] simple change... help me plz

    Hello every one

    i have a button to load two .txt files
    if user select a file to load for example (test.txt)
    automatically another file with the same name followed by the word first should be loaded which well be (testfirst.txt)in this case
    THIS FILE SHOULD BE IN THE SAME DIRECTORY


    this is my code:
    VB Code:
    1. With CommonDialog1
    2.         .CancelError = True
    3.         .Filter = "Text files (*.txt)|*.txt"
    4.         .DialogTitle = "Save the file..."
    5.         .ShowSave
    6.             If .filename <> "" Then
    7.               Form1.RichTextBox1.LoadFile .filename, rtfText
    8.               RichTextBox2.LoadFile Left(.filename, Len(.filename) - 4) & "first.txt", rtfText
    9.              txtFileText.Text = RichTextBox2.Text
    10.             End If
    11.     End With


    what i need is that if user selected a file that don't have a partner an error message should appaer

    how can do this?
    i mean if user select file test.txt and the file testfirst.txt is not there then display error message

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: simple change... help me plz

    I want to ask a question, why are you Loading textfiles using ShowSave method??

    Anyways, just try out this:
    VB Code:
    1. Dim fso As Object
    2.  
    3. Private Sub Command1_Click()
    4.  
    5. On Error GoTo errhand
    6. With CommonDialog1
    7.         .CancelError = True
    8.         .Filter = "Text files (*.txt)|*.txt"
    9.         .DialogTitle = "Save the file..."
    10.         .ShowSave
    11.             If .FileName <> "" Then
    12.               If fso.fileexists(Left(.FileName, Len(.FileName) - 4) & "first.txt") Then
    13.                 Form1.RichTextBox1.LoadFile .FileName, rtfText
    14.                 RichTextBox2.LoadFile Left(.FileName, Len(.FileName) - 4) & "first.txt", rtfText
    15.                 'txtFileText.Text = RichTextBox2.Text
    16.               Else
    17.                 MsgBox "Partner File not present"
    18.                 Exit Sub
    19.               End If
    20.             End If
    21.     End With
    22.  
    23. errhand:
    24. If Err.Number = 32755 Then _
    25.     MsgBox "Cancel was selected"
    26.    
    27. End Sub
    28.  
    29. Private Sub Form_Load()
    30.  
    31.     Set fso = CreateObject("Scripting.FileSystemObject")
    32.  
    33. End Sub
    Show Appreciation. Rate Posts.

  3. #3
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Re: simple change... help me plz

    Why you use a RichTextBox then sending it the textbox , you can load data to it directly
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: simple change... help me plz

    thanks Harsh Gupta
    that is what i was looking for

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