Solved

Show only part of a filename in a label vb6

Posted on 2014-03-06
6
200 Views
Last Modified: 2014-03-07
How do i get the last part of  a filename after the last backslash and leave off the extension
Typical file name:
C:\Documents and Settings\All Users.WINDOWS\Documents\Real20CardKeno\KingKeno\SavedKingKenoGames\10 spot top row bet 10 cents.cle
Example: What i need
lblFilename = "10 spot top row bet 10 cents"
this part could be any length
0
Comment
Question by:isnoend2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 300 total points
ID: 39911684
HI,

pls try
strFileName = "C:\Documents and Settings\All Users.WINDOWS\Documents\Real20CardKeno\KingKeno\SavedKingKenoGames\10 spot top row bet 10 cents.cle"
arrFilename = Split(strFileName, "\")
lblName = Split(arrFilename(UBound(arrFilename)), ".")(0)

Open in new window

Regards
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 total points
ID: 39911855
if you had used the FileSystemObject, you can use the basename method of the file object:
http://msdn.microsoft.com/en-us/library/aa265288%28v=vs.60%29.aspx

apart from that, the above method shall work
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 100 total points
ID: 39912190
I agree with a3 about the FSO being the preferred method of getting the data you want.

If you want to hone your VB skills, you can play with different parsing methods.
* (already shown) SPLIT()
* InstrRev(), Mid(), Left()
* using a vbscript.regexp object -- the pattern I used is ".*\\(.*)\..*?"
* looping (For...Next or Do...Loop) structures
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:isnoend2001
ID: 39912528
Thanks
Got this from another forum:
Public Function GetBaseName(ByRef Path As String) As String
    Dim StartPos As Long, EndPos As Long
    StartPos = InStrRev(Path, "\") + 1&
    EndPos = InStrRev(Path, ".")
    GetBaseName = Mid$(Path, StartPos, EndPos - StartPos)
End Function
it seems to work fine
hate using the fso as a dependency needs adding to setups
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39912701
hate using the fso as a dependency needs adding to setups
No.  You can instantiate this dynamically without having to worry about dependencies.  FSO is on all currently supported Windows versions.
Example:
Dim oFS As Object
Set oFS = CreateObject("scripting.filesystemobject")

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 39912876
Thanks
Few yrs ago i had problem with fso dependencies. No longer a problem, but i can do without
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question