Results 1 to 11 of 11

Thread: [RESOLVED] Removing part of a line in a textbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    Resolved [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?

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    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.

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    Re: Removing part of a line in a textbox

    Thanks, ill see what i can do with it.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    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.

  7. #7
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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.


  8. #8
    Lively Member
    Join Date
    Feb 2007
    Posts
    99

    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)

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    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.

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    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
  •  



Click Here to Expand Forum to Full Width