Concatenate string with a foreslash

R

RipperT

Cannot find VB6 newsgroup.

Trying to send a string argument to a shortcut creation method for launching
an Access .mdb file. Here is the string argument (VS 2005).

"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE""
""C:\ITS\ITS.mdb"" /wrkgrp ""G:\~Prisoner Census\I T S\IBC_Staff.mdw"

Here is the path that is generated in the created shortcut:

"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "C:\ITS\ITS.mdb"
\wrkgrp "G:\~Prisoner Census\I T S\IBC_Staff.mdw"

This is totally correct except the foreslash in front of wrkgrp becomes a
backslash. Any idea how I can fix
this? I've tried a million different ways and spent hours. Someone suggested
placing an @ in front of the strings, but that seems to only apply to C and
C#. Please help!

Rip
 
F

Family Tree Mike

RipperT said:
Cannot find VB6 newsgroup.

Trying to send a string argument to a shortcut creation method for launching
an Access .mdb file. Here is the string argument (VS 2005).

"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE""
""C:\ITS\ITS.mdb"" /wrkgrp ""G:\~Prisoner Census\I T S\IBC_Staff.mdw"

Here is the path that is generated in the created shortcut:

"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "C:\ITS\ITS.mdb"
\wrkgrp "G:\~Prisoner Census\I T S\IBC_Staff.mdw"

This is totally correct except the foreslash in front of wrkgrp becomes a
backslash. Any idea how I can fix
this? I've tried a million different ways and spent hours. Someone suggested
placing an @ in front of the strings, but that seems to only apply to C and
C#. Please help!

Rip

Please see the group microsoft.public.vb.general.discussion for vb6
questions.
 
J

J.B. Moreno

Family Tree Mike said:
Please see the group microsoft.public.vb.general.discussion for vb6
questions.

This doesn't seem to be a VB6 question. He says he's using VS 2005...

Anyway, my best guess (without seeing any code that's all I can do), is
that he's using Path.Combine or something related which is
"normalizing" the directory separator and mistaking the /wrkgrp as a
directory.
 
J

James Hahn

What is the "shortcut creation method" that you are using and what is the
code that you are using to call it with?
 
F

Family Tree Mike

J.B. Moreno said:
This doesn't seem to be a VB6 question. He says he's using VS 2005...

It is very confusing, as the OP started by saying they could not find
the VB 6 group.
Anyway, my best guess (without seeing any code that's all I can do), is
that he's using Path.Combine or something related which is
"normalizing" the directory separator and mistaking the /wrkgrp as a
directory.

Maybe... Hard to say without code, as you said.
 
R

RipperT

Dim userDesktop =
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)



Create_ShortCut("C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE""
""C:\ITS\ITS.mdb"" /wrkgrp ""G:\~Prisoner Census\I T S\ibc_Staff.mdw", _

userDesktop, "ITS", "C:\ITS", 1, 0)



Function Create_ShortCut(ByVal TargetPath As String, _

ByVal ShortCutPath As String, ByVal ShortCutname As String, _

ByVal WorkPath As String, ByVal Window_Style As Integer, _

ByVal IconNum As Integer)



Dim VbsObj As Object

VbsObj = CreateObject("WScript.Shell")



Dim MyShortcut As Object

MyShortcut = VbsObj.CreateShortcut(ShortCutPath & "\" & ShortCutname &
".lnk")

MyShortcut.TargetPath = TargetPath

MyShortcut.WorkingDirectory = WorkPath

MyShortcut.WindowStyle = Window_Style

MyShortcut.IconLocation = TargetPath & "," & IconNum

MyShortcut.Save()



Return True

End Function
 
A

Armin Zingler

RipperT said:
Dim userDesktop =
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)



Create_ShortCut("C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE""
""C:\ITS\ITS.mdb"" /wrkgrp ""G:\~Prisoner Census\I T S\ibc_Staff.mdw", _
userDesktop, "ITS", "C:\ITS", 1, 0)

I haven't used that library so far, but after looking at the available
COM references, it seems you should better make use of the

"Windows Script Host Object Model"

This enables you to enable Option Strict On.

In the object browser, I saw that the shortcut interface also has an
arguments property, so you must provide the arguments in this property
and not as part of the target path.

Then your code looks something like this:

Shared Sub Create_ShortCut( _
ByVal TargetPath As String, _
ByVal Arguments As String, _
ByVal ShortCutPath As String, _
ByVal ShortCutname As String, _
ByVal WorkPath As String, _
ByVal Window_Style As Integer, _
ByVal IconNum As Integer)

Dim VbsObj As New IWshRuntimeLibrary.WshShell
Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut
Dim LnkPath As String

LnkPath = IO.Path.Combine(ShortCutPath, ShortCutname & ".lnk")


MyShortcut = DirectCast( _
VbsObj.CreateShortcut(LnkPath), _
IWshRuntimeLibrary.IWshShortcut _
)

MyShortcut.TargetPath = TargetPath
MyShortcut.Arguments = Arguments
MyShortcut.WorkingDirectory = WorkPath
MyShortcut.WindowStyle = Window_Style
MyShortcut.IconLocation = TargetPath & "," & IconNum
MyShortcut.Arguments =
MyShortcut.Save()

End Sub

I've also changed it to a Shared Sub.

Call:

Create_ShortCut( _
"""C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE""", _
"""C:\ITS\ITS.mdb""" _
& " /wrkgrp ""G:\~Prisoner Census\I T S\ibc_Staff.mdw""", _
userDesktop, _
"ITS", _
"C:\ITS", _
1, _
0 _
)


(I don't know if each path has to be enclosed in quotation marks. Try it.)


Can you try it and tell us if it works?
 
R

RipperT

Had to add a reference to the Object Model and it works beautifully...Thank
you Armin and others!

Rip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top