Results 1 to 6 of 6

Thread: Deleting several chr's...

  1. #1

    Thread Starter
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335
    I have a FileListBox (I've been on this for too long!).
    I want to do that when I click on one item in the FileListBox, to show the filename in the Me.Caption.
    I know, this is too easy:
    Code:
    Me.Caption = File1.filename
    But the thing is that it shows the extension too. I don't want that...
    Any ideas?
    Asaf Sagi

    ICQ: 61917199
    E-Mail: sagiasaf@netvision.net.il

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    Function Extensionlesspart(filepath)
        For n = Len(filepath) To 1 Step -1
            If Mid(filepath, n, 1) = "." Then Extensionlesspart = Left(filepath, n - 1): Exit Function
        Next n
        Extensionlesspart = filepath
    End Function
    
    
    'to use
    
    Me.Caption = Extensionlesspart(File1.filename)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Just parse it out using Left().
    Code:
    Me.Caption = Left(File1.FileName, Len(File1.FileName) - _
    InStrRev(File1.FileName, "."))
    Though Kedaman's way will work fine, this kills the loop
    -Excalibur

  4. #4

    Thread Starter
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335
    Thanks you 2.
    Kedaman's code worked!
    Asaf Sagi

    ICQ: 61917199
    E-Mail: sagiasaf@netvision.net.il

  5. #5
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    There's a logic error in ExcalibursZone's code

    Two things...

    1. You don't need to do Len(File1) - InStrRev... Just InStrRev by itself (minus one) returns the length of the string to dispay.

    2. One small note, I've read that VB runs faster when you don't explicitly state a default property of a control when you reference it.

    So the above code would actually run faster (and more accurately) if typed as:
    Code:
    Me.Caption = Left$(File1, InStrRev(File1, ".") - 1)
    since FileName is the default property of a FileListBox.

    [Edited by seaweed on 11-09-2000 at 03:19 PM]
    ~seaweed

  6. #6
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    hey, thanks for the scoop. I keep forgetting that InStrRev gives the actual position +1 that you're looking for.

    I did not know that using the default property actually sped up the code ... I'll have to keep that in mind.
    -Excalibur

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