You are not logged in.

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