Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Show only part of a filename in a label vb6

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

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
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 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
Suggested Courses

618 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