|
-
Nov 9th, 2000, 02:48 PM
#1
Thread Starter
Hyperactive Member
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?
-
Nov 9th, 2000, 02:54 PM
#2
transcendental analytic
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.
-
Nov 9th, 2000, 03:00 PM
#3
Fanatic Member
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 
-
Nov 9th, 2000, 03:08 PM
#4
Thread Starter
Hyperactive Member
Thanks you 2.
Kedaman's code worked!
-
Nov 9th, 2000, 03:14 PM
#5
Frenzied Member
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]
-
Nov 9th, 2000, 04:24 PM
#6
Fanatic Member
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.
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
|