Question about the OpenLocation function


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 14 of 14

Thread: Question about the OpenLocation function

  1. #1
    Join Date
    Dec 2008
    Posts
    14

    Question about the OpenLocation function

    Is is possible to make the OpenLocation function accept a string variable as an argument? I tried, and I can't make it work. I am using VB6.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    What is the OpenLocation function? I am not familiar with it.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Dec 2008
    Posts
    14
    It's a function used for opening a file with its default program (or just opening a program) and it takes a string containing the path to the file/program as an argument. Here is the code for it:
    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    
    Public Function OpenLocation(ByVal WhichFilePath As String, Optional sParams As String = "", Optional sStartIn As String = vbNullString, Optional lngOpenMode As Long = 1) As Long
        OpenLocation = ShellExecute(0, "Open", WhichFilePath, sParams, sStartIn, lngOpenMode)
    End Function
    Last edited by Littlebro; 12-22-2008 at 02:54 AM.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    OK, the first argument (WhichFilePath) accepts a string. You should be able to pass a string variable. How are you calling the function?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Dec 2008
    Posts
    14
    I call it like this:
    OpenLocation ("C:\WINDOWS\system32\sol.exe") if I want to open a file or program in a specific location. I am using this function in conjunction with another function which gets a file path from a .ini file, and stores the path in a string variable. I know that this function works, but when I try to use the string variable as an argument for the OpenLocation function, it just opens the folder the program is in.

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Sounds like the variable you're passing only contains a path, not the name of the actual program. Check the value of the variable you're passing to the function.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  7. #7
    Join Date
    May 2008
    Posts
    37
    Quote Originally Posted by Littlebro View Post
    I call it like this:
    OpenLocation ("C:\WINDOWS\system32\sol.exe") if I want to open a file or program in a specific location. I am using this function in conjunction with another function which gets a file path from a .ini file, and stores the path in a string variable. I know that this function works, but when I try to use the string variable as an argument for the OpenLocation function, it just opens the folder the program is in.
    isnt that the way its supposed to be ? to open the folder where the file (executable or not) is in, afterall thats why its called OpenLocation, right ?

    cheers and seasons greetings to all !!!
    BASED FROM YOUR POSTS, I HAVE EXAMINED YOUR BEHAVIORAL PATTERN AND I SAW YOUR BRAIN'S TWO SIDES : LEFT & RIGHT, AND I SAW THAT ON THE LEFT SIDE THERE'S NOTHING RIGHT WHILE ON THE RIGHT SIDE THERE'S NOTHING LEFT

  8. #8
    Join Date
    Dec 2008
    Posts
    14
    The path obtained from the .ini file contains the name of the program I want to open. It doesn't open.
    EDIT: I might have misphrased something above. The program doing the calling opens the folder it's in when I call OpenLocation using a string variable (with a value obtained from a .ini file) as an argument.
    Last edited by Littlebro; 12-22-2008 at 03:48 AM.

  9. #9
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    If you hard code the path and file name does it work?

    (i.e., OpenLocation ("C:\WINDOWS\system32\sol.exe") )
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  10. #10
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    What prints in the debug window if you set a breakpoint on the call to OpenLocation and Debug.Print VariableName (replacing VariableName with the name of your string variable)?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  11. #11
    Join Date
    Dec 2008
    Posts
    14
    I don't really know how to do what you are asking, but I have found a workaround. I set the caption of a label to the string, used the label caption as an argument, and it worked.

  12. #12
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    He is referring to using the debug window (or "immediate window") as a debugging tool to see what is actually in the variable.

    This sort of thing is invaluable when working with code (and it doesn't even have to be troublesome code)

    http://msdn.microsoft.com/en-us/libr...ffice.10).aspx
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  13. #13
    Join Date
    Dec 2008
    Posts
    14
    Nothing is printed in the debug window. The cursor just goes to the next line in the debug window.
    EDIT: I feel like an idiot. The reason it wasn't working was that I declared the string variable in a private subroutine. Thanks for your help anyway.
    Last edited by Littlebro; 12-24-2008 at 04:24 AM.

  14. #14
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by Littlebro View Post
    EDIT: I feel like an idiot. The reason it wasn't working was that I declared the string variable in a private subroutine. Thanks for your help anyway.
    Don't feel like an idiot. Everyone has done the same thing, and I would venture to say, everyone has done the same thing more than once.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Replies: 4
    Last Post: 08-28-2005, 04:16 PM
  2. comparing function pointers [was: typedef problem]
    By swapnil_paranja in forum C++
    Replies: 20
    Last Post: 08-25-2005, 03:54 PM
  3. OleDb SQL question: SUM function
    By MikeKraken in forum Database
    Replies: 11
    Last Post: 03-15-2005, 08:12 PM
  4. Getting a GUI to function
    By Eric in forum Java
    Replies: 1
    Last Post: 11-27-2001, 06:53 AM
  5. Replies: 0
    Last Post: 06-22-2000, 07:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center