Results 1 to 5 of 5

Thread: Split issue

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Split issue

    I have this as code to run the program

    Code:
    Process.Start(ListBox1.SelectedItem.ToString.Split(New String() {"  "}, StringSplitOptions.None)(1))
    Which used to work but then I added a "Preview image" function like this :
    Code:
    (ListBox1.SelectedItem.ToString.Split(New String() {"  Image:"}, StringSplitOptions.None)(1))
    I now discovered that the first code is useless, because it selects everything after " " to run, including the "Image:"

    This is how a listbox item is stored:
    Code:
    Tomb Raider Level Editor - Original  C:\Program Files\Tomb Raider - Level Editor\tomb4.exe  Image:C:\Program Files\Tomb Raider - Level Editor\load.bmp
    As you can see it'll use this
    Code:
    C:\Program Files\Tomb Raider - Level Editor\tomb4.exe  Image:C:\Program Files\Tomb Raider - Level Editor\load.bmp
    to run

    Is there any way I can make it choose the path from " " and when it finds "image:" it stops?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Split issue

    vb Code:
    1. MsgBox("executable:" & Environment.NewLine & ListBox1.SelectedItem.ToString.Split(New String() {"  "}, StringSplitOptions.None)(1))
    2. MsgBox("preview image:" & Environment.NewLine & ListBox1.SelectedItem.ToString.Split(New String() {"  "}, StringSplitOptions.None)(2).Replace("Image:", ""))

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Re: Split issue

    If I use this :
    Code:
    Process.Start(ListBox1.SelectedItem.ToString.Split(New String() {"  "}, StringSplitOptions.None)(1))
    It says Win32 exeption was unhandled ?

    If I create a button and paste the code you provided, it shows fine in the message boxes tho.

    how can I use Process.Start, or something else to start the program
    (in the example I gave : C:\Program Files\Tomb Raider - Level Editor\tomb4.exe)

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Split issue

    are you sure you've got the correct filename?

    try running it directly:

    Process.Start("C:\Program Files\Tomb Raider - Level Editor\tomb4.exe")

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Split issue

    You want everything before "Image:" so just use IndexOf to find that position. You can then use Substring to get everything before that index. You can use Trim to remove the trailing whitespace and you've got your path.

    That said, using a ListBox to store multiple values in one item is a hack anyway. A far better idea would be to use a ListView and store the executable path and image path in different columns.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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