You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

fallon416

Beginner

  • "fallon416" started this thread

Posts: 28

Date of registration: Mar 26th 2010

  • Send private message

1

Saturday, March 27th 2010, 5:17am

trimming a path to file name from a listbox

Hi,

I'm attempting to trim off the path of a file in a listbox so that I just end up with the file name. In vb I can use

Dim k As Long

k = InStrRev(lstPlaylist.List(lstPlaylist.ListIndex),"\")
If k > 0 Then lblTitle.Caption = right$(lstPlaylist.List(lstPlaylist.ListIndex), k)

This works but does not return everything to the right of the last \. It chops off some of the filename.
Is there a different way to do this in Jabaco?

Neil

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Saturday, March 27th 2010, 12:44pm

Well, I think you have to use Mid() rather than Right() to extract all characters starting at a given position.

Look at this:

Jabaco Source

1
2
3
4
5
6
7
Dim k As Long
   Dim s As String = "a very long name\with a middle part\here comes the rest"
   
   k = InStrRev(s,"")
   If k > 0 Then s = Mid(s, k + 1)
   
   MsgBox s & " (k=" & k & ")"


Cheers

A1880

fallon416

Beginner

  • "fallon416" started this thread

Posts: 28

Date of registration: Mar 26th 2010

  • Send private message

3

Saturday, March 27th 2010, 2:00pm

Thanks. To many years away from VB programming.

This worked:

Dim k As Long
Dim s As String = lstPlaylist.List(lstPlaylist.ListIndex)

k = InStrRev(s,"\")
If k > 0 Then s = Mid(s, k + 1)

lblTitle.Caption = s

Rate this thread
WoltLab Burning Board