[RESOLVED] Removing part of a line in a textbox
Currently in my program, i have a textbox which, after the click of command one, displays the selected file in the filebox, file1. My problem is, i need to remove part of the file name. The file names are all different lengths, but are all the same "*.set". What i need the button to do is remove the first part of the filename up to the underscore, and then the .set and put the rest of the file name into the textbox. For example "XRT_fe3_wr.set" becomes "fe3_wr" in the textbox. The main problem is that the files will have anywhere from 3 to 9 or 10 before the first underscore. Any ideas on how to do this?
Re: Removing part of a line in a textbox
The problem is that there's also an underscore in the part you want to keep. Assuming they were all like that, then you'd want to get stuff from the end of the 2nd-to-last underscore. Which is easy.
Do all file names have have an underscore in the part you want to keep? If not then it's a little different.
Re: Removing part of a line in a textbox
some will and some will not. Its hard to tell because it will be user determined.
Re: Removing part of a line in a textbox
Well, I guess you can just get everything after XRT_. Try this:
Code:
Private Sub Form_Load()
Dim strName As String
strName = "XRT_fe3_wr.set"
'fe3_wr
Dim intStart As Integer, intEnd As Integer
Dim strKeep As String
intStart = InStr(1, strName, "XRT_", vbTextCompare)
If intStart > 0 Then
intStart = intStart + 4 'Length of XRT_
intEnd = InStr(intStart, strName, ".set", vbTextCompare)
If intEnd > 0 Then
strKeep = Mid$(strName, intStart, intEnd - intStart)
MsgBox strName & vbCrLf & "becomes" & vbCrLf & strKeep
'List1.AddItem strKeep
End If
End If
End Sub
Re: Removing part of a line in a textbox
Thanks, ill see what i can do with it.
Re: Removing part of a line in a textbox
Is there any way i can make the strName = a varible? because the filenames will not be the same. If i can make the strName a varible, then i know how to get the rest to work.
Re: Removing part of a line in a textbox
yes, ofcourse you can make the strName = a variable...but instead of writing your code in the Form_Load event write into a separate function and then call it
Re: Removing part of a line in a textbox
Quote:
Originally Posted by stevevb6
Currently in my program, i have a textbox which, after the click of command one, displays the selected file in the filebox, file1. My problem is, i need to remove part of the file name. The file names are all different lengths, but are all the same "*.set". What i need the button to do is remove the first part of the filename up to the underscore, and then the .set and put the rest of the file name into the textbox. For example "XRT_fe3_wr.set" becomes "fe3_wr" in the textbox. The main problem is that the files will have anywhere from 3 to 9 or 10 before the first underscore. Any ideas on how to do this?
Code:
Dim bgStr as Integer
bgStr = Instr(textBox,"_")
bgStr = bgStr + 1
textBox =Mid$(textBox,bgStr, Len(textBox) -bgStr - 3)
Re: Removing part of a line in a textbox
I still cant get the varible strName to work. Any examples?
Re: Removing part of a line in a textbox
Instead of
strName = "XRT_fe3_wr.set"
use
strName = Text1.Text
or whatever the name of your text box is.
Re: Removing part of a line in a textbox
i have it working now, thanks!