Solved

Show only part of a filename in a label vb6

Posted on 2014-03-06
6
192 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
6 Comments
 
LVL 48

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 142

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VBA to format 3 80
Problem to delete range 4 55
Excel object stays open 19 65
passing parameter in sql procedure 9 50
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now