?
Solved

Show only part of a filename in a label vb6

Posted on 2014-03-06
6
Medium Priority
?
201 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 52

Accepted Solution

by:
Rgonzo1971 earned 1200 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 400 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 46

Assisted Solution

by:aikimark
aikimark earned 400 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
Technology Partners: 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 46

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

762 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