Results 1 to 8 of 8

Thread: Listbox selected item help.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83

    Listbox selected item help.

    I have a list box that is filled with files. Now I need to be able to take the selected file and then launch a program that will use the file. I know how to launch the program, but I just dont know how to take the selected item and put it into a varible. It wont take strings... So I'm at a loss. Or maybe it will but I dont know how.

    Anyway if anyone has some ideas please let me know.
    12/32/84 - I need some code to make me a sandwhich.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Are you trying to get the text of the selected item? Use SelectedText.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    SeletedText wont work. Its not a member of a listbox.
    I assume you ment SeletedItems?

    But I did get the code below to work.. Sort of. But I need a way to pass commandline arguments to the "fceu.exe"
    Code:
    Shell(GetSetting("Multi-Front", "NesEmu", "EmuPath_Name"), AppWinStyle.NormalFocus)

    Next I would need to add (lstRomsNes.SelectedItems) as a command line argument. Have any ideas?
    Last edited by Jes|er; Nov 25th, 2002 at 10:08 PM.
    12/32/84 - I need some code to make me a sandwhich.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Sorry I guess I was thinking of the ComboBox. Do you want each SelectedItem to be a seperate commandline argument or all run together? Also what are you filling the Listbox items with? Strings? Objects?

    VB Code:
    1. 'if you want them all run together it'd be something like this
    2. dim sb as New System.Text.StringBuilder()
    3. dim o as Object
    4. For each o in lstRomsNes.SelectedItems
    5.   Sb.Append(o.ToString & ",")
    6. Next
    7. If sb.Length > 1 Then sb.Remove(sb.Length - 1, 1)'trim last comma
    8. 'commandline arguments now are in
    9. Msgbox(sb.ToString)

    Or if you want them seperate then just set it while doing the for..each loop.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    Thank you! Thanks works pefectly. Now I have another problem..

    The filenames are like: ADAD Corp (U).zip

    So when I pass the filename to the program it says
    it cant find C:\Dir\ADAD!

    So I need to rename the file and then store it in a temp
    dir..

    Ok so its not that hard.. I got this from VS.NET Help:

    Code:
    Public Sub Rename(ByVal OldPath As String, _
           ByVal NewPath As String)
    
    
            Dim OldName, NewName As String
            OldName = "test.txt"
            NewName = "renamed.txt" ' Define file names.
            Rename(OldName, NewName)   ' Rename file.
    
            OldName = "C:\test.txt"
            NewName = "C:\renamed.txt"
            Rename(OldName, NewName)   ' Move and rename file.
    
    
        End Sub
    But now I cant figure out how to call this sub! Call Rename() gives me an error, as does just Rename() ..
    Last edited by Jes|er; Nov 26th, 2002 at 08:36 PM.
    12/32/84 - I need some code to make me a sandwhich.

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Where are you getting the Rename function from? What error are you getting?

    Its probably something like:

    IO.File.Rename(OldName,NewName)

    Or

    File.Rename(OldName,NewName)

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Wharever is rejecting the path could be expecting a ShortPathname also, which I think you can get from the FileInfo object I believe.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    IO.File.Rename(OldName,NewName) seems to work.

    I also found this to work:

    FileCopy("C:\test.txt", "C:\renamed.txt") which is
    shorter.

    I want to thank you for all your help. You have been of tremendus assistance.
    12/32/84 - I need some code to make me a sandwhich.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width