-
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
-
<?>
Dim strString As String, intLen As Integer
strString = Text1.Text
intLen = Len(strString)
strString = Left(strString, (intLen - 3))
strString = strString & "doc"
Text1.Text = strString
-
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]
-
<?>
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