Results 1 to 4 of 4

Thread: Text Box Question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Location
    Tucson, AZ, USA
    Posts
    95
    Hopefully this will be an easy one for all you VB Gurus out there.

    I Have a textbox with the text like
    c:\bob.txt and in another textbox I want it to show
    c:\bob.doc

    But I am getting the file name with a common dialog so I can't type that in for the text.. I hope this makes sense, I need to simply change the extention of the whatever is listed in textbox1.

    Ed Farias

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>


    Dim strString As String, intLen As Integer
    strString = Text1.Text
    intLen = Len(strString)

    strString = Left(strString, (intLen - 3))
    strString = strString & "doc"
    Text1.Text = strString
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Guest
    you mean like this??

    Code:
    Text1 = Left(Text1, Len(Text1) - 4)) & ".doc"

    that will change the extenstion to .doc, but if it doesnt have an extension, it will add a doc extension(it will also take away four letters of the name).

    [Edited by denniswrenn on 08-29-2000 at 05:55 PM]

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    'guess my first answer was off the cuff and too hasty
    
    'if you want to error code it it would work like this
    
    Private Sub Command1_Click()
    
        Dim SearchString, SearchChar, MyPos
        SearchString = Text1.Text
        SearchChar = "."
         
    
        MyPos = InStr(1, SearchString, SearchChar, 1)
    
    'if found MyPos will be > 0
        If MyPos > 0 Then
           Text1.Text = Left(Text1, MyPos) & "doc"
        Else
        'your error code goes here
           MsgBox "There seems to be no extension"
           Exit Sub
           
        End If
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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