|
-
Apr 19th, 2007, 10:37 PM
#1
Thread Starter
Lively Member
[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?
-
Apr 19th, 2007, 10:41 PM
#2
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.
-
Apr 19th, 2007, 10:43 PM
#3
Thread Starter
Lively Member
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.
-
Apr 19th, 2007, 10:48 PM
#4
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
-
Apr 19th, 2007, 10:51 PM
#5
Thread Starter
Lively Member
Re: Removing part of a line in a textbox
Thanks, ill see what i can do with it.
-
Apr 19th, 2007, 11:16 PM
#6
Thread Starter
Lively Member
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.
-
Apr 19th, 2007, 11:23 PM
#7
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
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Apr 20th, 2007, 01:47 AM
#8
Lively Member
Re: Removing part of a line in a textbox
 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)
-
Apr 20th, 2007, 08:56 AM
#9
Thread Starter
Lively Member
Re: Removing part of a line in a textbox
I still cant get the varible strName to work. Any examples?
Last edited by stevevb6; Apr 20th, 2007 at 09:08 AM.
-
Apr 20th, 2007, 09:59 AM
#10
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.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Apr 20th, 2007, 12:56 PM
#11
Thread Starter
Lively Member
Re: Removing part of a line in a textbox
i have it working now, thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|