Link to home
Start Free TrialLog in
Avatar of Sector10
Sector10

asked on

NEED URGENT HELP How to Set 'Start In:' Directory on icons in Listview!!

Hello,

I hope you understand my question so here it goes:

The following code is loading icons in a listview.
When i double click on an icon For Example a MS Word Icon, it starts the program.

My question is: How can i set the 'start in:' (Working directory) for each icon in the listview???
I've got some programs that needs to have their working directory beeing set to a specific path for example 'c:\workdir'.

Dim oLI     As ListItem
Dim nIcon   As Integer
Dim szLine  As String

Open szFile For Input As #1
nIcon = 1

Do Until EOF(1)
    Line Input #1, szLine
        If InStr(1, szLine, "=") > 0 Then
            ImageList1.ListImages.Add nIcon, , _
                LoadPicture(ServerName & "Icon\" & Split(Replace(Split(szLine, _
                "=")(1), Chr(34), ""), ",")(0))
            Set oLI = ListView1.ListItems.Add(, , Split(szLine, "=")(0), nIcon, _
                nIcon)
            oLI.Tag = Split(Replace(Split(szLine, "=")(1), Chr(34), ""), ",")(1)
            Set oLI = Nothing
            nIcon = nIcon + 1
        End If
    Loop
Close #1



Regards,

Paul
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

>>I've got some programs that needs to have their working directory beeing set to a specific path for example 'c:\workdir'.
You can save the specified path of 'c:\workdir' into registry, ini file, database etc, so that you can retrieve that value when necessary not only within your application but also for other applications.

Hope this make sense to you, ask if you need further helps, regards
Avatar of Sector10
Sector10

ASKER

Hello Ryan!

The programs that are shown on the listview are pulled from an ini file like this:

[ICON]
MS Word=Word.jpg,C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE
MS Excel=Excel.jpg,C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE

As you can see from the code above this line is split:

MS Word                                                                            -  This text is desplayed under the Icon
Word.jpg                                                                            -  Is the actual icon to be displayed
C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE   - Is the program to start

So how can i bind different startup dir's to each icon?

Regards,

Paul
JimBobMcGee has help me out A LOT but this is one thing i am still strugglin with.

Take a look at the following link for the history on this issue:

https://www.experts-exchange.com/questions/21289260/Need-Experts-help.html

Regards,


Paul
It's hard to determine the location of a program installed. Yet the urls below may give you some useful info on how to determine the installed path (working path?):

Determining the Name of the Executable Associated with a Specific File
http://vbnet.mvps.org/index.html?code/system/findexecutable.htm

Windows Uninstaller
http://www.freevbcode.com/ShowCode.Asp?ID=4742
Just add working directories to your ini file, then add it to oLI.Tag, separated with some non-printable character (Chr(0), for example), like:
   oLI.Tag = Split(Replace(Split(szLine, "=")(1), Chr(34), ""), ",")(1) & Chr(0) & strWorkingDir(i)

Then, at Dbl_Click event, split tag into 2 parts:
s=Split(Listview1.SelectedItem.Tag,Chr(0))
Hello Ark!

This is the current Dbl_Click event:

Private Sub ListView1_DblClick()
Dim RetVal

Me.WindowState = vbMinimized
RetVal = Shell(ListView1.SelectedItem.Tag, 1)

End Sub

How must i implement: s=Split(Listview1.SelectedItem.Tag,Chr(0))

Regards,

Paul
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Ark!

Let me thank you all for your time and effort on this one, you all have been such great help to me!

So i am almost there, if i hardcode the working dir al works fine so the line reads:
oLI.Tag = Split(Replace(Split(szLine, "=")(1), Chr(34), ""), ",")(1) & Chr(0) & "c:\Temp"

Now this is my ini file:
[ICON]
MS Word=Word.jpg,C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE
MS Excel=Excel.jpg,C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE

I added a working dir for example:
[ICON]
MS Word=Word.jpg,C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE,C:\Word
MS Excel=Excel.jpg,C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE,C:\Excel

How can i read this line using your piece of code, i asume that i have to alter the split?
oLI.Tag = Split(Replace(Split(szLine, "=")(1), Chr(34), ""), ",")(1) & Chr(0) & strWorkingDir(i)

Regards,

Paul

Solved it Ark!

I used a different split character "|" to seperate the working dir from the application. I also could have used Chr(0) offcourse ;o)
Now i know why you told me to use chr(0) .....

Thank you all once again, without you guys i was still struglin with this one!


Regards,

Paul