Open external applications

Questions regarding syntax

Open external applications

Postby gbison » Wed Sep 07, 2011 8:15 pm

Hello,

Sorry for a million questions folks but I have an active project in Kbasic right now that Im trying to get in beta.

What im doing is basically I need to open 1 of 2 programs from the gui of my application based on user choice. They will be opening either paint.net or gimp by selecting from a radio button then pushing and open button to make it happen. So heres the thing, I am assuming application.externalopenfile() is what i need to use in order to fire up the other application correct? If so what options are available to make paint or gimp open with the file the user currently has selected in our application? I hope I have made myself clear, if not please just let me know and i will explain in more detail.

Thanks
Bryan
"The greatest trick the devil ever pulled was to convince the world he didn't exist" . ;-)
gbison
 
Posts: 29
Joined: Fri Feb 04, 2011 8:16 pm
Location: USA

Re: Open external applications

Postby Slowdown » Thu Sep 08, 2011 11:28 am

Hi gbison,
Two way's to do it,
One with Shell() and the other with Process.Run()
Code: Select all
Private Sub ShellStart_OnEvent()
  Dim ProgPathName As String = "C:\Windows\Notepad.exe"
  Dim ReturnValue As String
 
  ReturnValue = shell(ProgPathName)
End Sub

Private Sub ProcessStart_OnEvent()
  Dim ProgPathName As String = "C:\Windows\Notepad.exe"
  Dim ReturnValue As String
 
  ReturnValue = Process.Run(ProgPathName) 
End Sub
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Open external applications

Postby gbison » Thu Sep 08, 2011 2:33 pm

Hey Slowdown :)

Thanks for replying so quick! Using your method I reworked the sub just a little to try and get this to work. Heres a quick look at the test sub.

Code: Select all
Private Sub CommandButton11_OnEvent()
  Dim progPath as String = "C:\Program Files\Paint.NET\PaintDotNet.exe"
  Dim progPath2 as string = "C:\windows\system32\mspaint.exe"
  Dim progPath3 as string = "C:\Program Files\GIMP-2.0\bin\gimp-2.6.exe"
  Dim returnpath as string
 
  if radiobutton1.value = true then radiobutton2.value = false
  if radiobutton2.value = true then radiobutton1.value = false
 
  if radiobutton1.value = true then
    if dir.isdir("C:\Program Files\Paint.NET") = true then
      returnPath = Shell(progPath)
      'Application.ExternalOpenFile(trim(lcase("C:/Program Files/Paint.NET/PaintDotNet.exe")))
      'format()
      'shell("C:/Program Files/Paint.NET"+"/PaintDotNet.exe", false)
    else
      returnPath = Shell(progPath2)
      'Application.ExternalOpenFile("C:/windows/system32/mspaint.exe")
    endif
  endif
 
  if radiobutton2.value = true then
    if dir.isdir("C:/Program Files/GIMP-2.0/bin") = true then
      'Application.ExternalOpenFile("C:/Program Files/GIMP-2.0/bin/gimp-2.6.exe")
      returnPath = shell(progPath3)
    else
      returnPath = shell(progPath2)
    endif
  endif
End Sub


Now with this heres what happens, I get an error when trying to open paint.net or gimp saying c:\program is not a valid application. However, mspaint will open up just fine. So obviously the command sequence works, so why isnt it working on the other two directories. After further examination, the only difference I can find is white space. It would appear and after further testing that if the directory names have a space in them it breaks its ability to execute..........any ideas?? :?:
"The greatest trick the devil ever pulled was to convince the world he didn't exist" . ;-)
gbison
 
Posts: 29
Joined: Fri Feb 04, 2011 8:16 pm
Location: USA

Re: Open external applications

Postby Slowdown » Thu Sep 08, 2011 2:41 pm

Hi gbison,
any ideas??

yup,
Code: Select all
Dim progPath as String = "C:\Program Files\Paint.NET\PaintDotNet.exe"

change that in,
Code: Select all
Dim progPath as String = Chr(34) & "C:\Program Files\Paint.NET\PaintDotNet.exe" & Chr(34)

I think that solves your problem.
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Open external applications

Postby gbison » Thu Sep 08, 2011 4:06 pm

Slowdown, you my friend are the man! :D It worked!

Now can you please explain to me what that done to make it work because im a little clueless at the moment...lol :?
"The greatest trick the devil ever pulled was to convince the world he didn't exist" . ;-)
gbison
 
Posts: 29
Joined: Fri Feb 04, 2011 8:16 pm
Location: USA

Re: Open external applications

Postby Henning » Thu Sep 08, 2011 5:12 pm

Hi,

This is a String s = "some text". When there is a space in the filepath as string, Windows needs it to be surrounded by quotes (" Chr(34)). Therefor it should be s = ""some text"" or Chr(34) & "some text" & Chr(34). Windows treats a space as the delimiter to arguments.

Don't know if KB allows for s = ""some text"", not tested.

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Re: Open external applications

Postby gbison » Thu Sep 08, 2011 5:29 pm

Hey!

Very beneficial information! This little method actually fixed a ton of problems for me and I have already institued its use in other places to fix other bugs. The core of my program is now fully functional with this implementation. Thank you soooo much!
"The greatest trick the devil ever pulled was to convince the world he didn't exist" . ;-)
gbison
 
Posts: 29
Joined: Fri Feb 04, 2011 8:16 pm
Location: USA


Return to Coding Questions

cron