|
-
Jan 6th, 2007, 04:04 PM
#1
Thread Starter
Lively Member
[RESOLVED] launching a program
i want to be able have my program launch another program. However this program will obviously be installed in different places on different computers. So i want to be able have the user set the address to the program, so when the launch button is pressed in my program, my program opens the other program.
-
Jan 6th, 2007, 04:18 PM
#2
PowerPoster
Re: launching a program
And your problem is?
"shell text1" should (from memory) work fine, as long as text1 contains the location for a program...or you can use an FSO (file-system object) to get the location and shell it
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 6th, 2007, 04:20 PM
#3
Thread Starter
Lively Member
Re: launching a program
ok thanks. the problem is im new to vb6 and dont know how to go about doing this.
-
Jan 6th, 2007, 04:24 PM
#4
PowerPoster
Re: launching a program
Best way to learn is to play about like most learners do. If you're truly stumped feel free to ask for more help and someone will provide it eventually :-)
The FSO is a bit of a pain to use unless you know how it works and have at least a working knowledge of VB, so I would suggest forgetting that for now...you could have a pre-check on the run line the user inputs by doing a dir() of the location and not shelling it if dir returns "" (meaning the location is invalid :-)). Just do if dir(text1) <> "" then...
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 6th, 2007, 08:38 PM
#5
Re: launching a program
Any program of yours that a user uses will probably not work unless they are installed.
-
Jan 7th, 2007, 06:26 AM
#6
Re: launching a program
 Originally Posted by stevevb6
i want to be able have my program launch another program. However this program will obviously be installed in different places on different computers. So i want to be able have the user set the address to the program, so when the launch button is pressed in my program, my program opens the other program.
Since you won't know where it is, you need to find it. This should do the trick.
VB Code:
Option Explicit
Private Declare Function SearchTreeForFile Lib "imagehlp" _
(ByVal RootPath As String, ByVal InputPathName As String, _
ByVal OutputPathBuffer As String) As Long
Private Const MAX_PATH = 260
Private Sub Command1_Click()
Dim tempStr As String, Ret As Long
'create a buffer string
tempStr = String(MAX_PATH, 0)
'returns 1 when successfull, 0 when failed
Ret = SearchTreeForFile("c:\", "TheProgram.exe", tempStr)
If Ret <> 0 Then
MsgBox "Located file at " + Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1)
Else
MsgBox "File not found!"
End If
End Sub
Instead of displaying the location, save it to a variable, and use that to launch the program. To launch the program, I would use the ShellExecute API.
-
Jan 7th, 2007, 07:46 AM
#7
Re: launching a program
You'll also, presumably, need a way of storing the progam paths between sessions. Search for "GetSetting", "DeleteSetting", "SaveSetting" and "GetAllSettings".
-
Jan 7th, 2007, 07:51 AM
#8
PowerPoster
Re: launching a program
Hack and SchoolBus, did both of you miss the line "So i want to be able have the user set the address to the program"?
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 7th, 2007, 07:57 AM
#9
Re: launching a program
Ah I thought he was creating a multi program launcher. Maybe something to add command line parameters instead ?
-
Jan 7th, 2007, 02:30 PM
#10
Thread Starter
Lively Member
Re: launching a program
yeah i want to make a program launcher that will launch an external exe file. The obvious problem is that not everyone will have the exe file in the same dir. So i want the user to search or even copy and paste the dir for the file into a textbox and press an ok button would be fine. Im just not sure what i would need to use to do it.
-
Jan 7th, 2007, 02:56 PM
#11
Re: launching a program
Use a CommonDialog control to allow the user to browse and select the exe file. Then store it in the registry with SaveSetting and read it with GetSetting. The Shell the exe with the complete filepath.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 7th, 2007, 04:29 PM
#12
Thread Starter
Lively Member
Re: launching a program
is it possible to store it in the program, insted of haveing to make reg entrys?
-
Jan 7th, 2007, 04:32 PM
#13
PowerPoster
Re: launching a program
Once a program is running it is impossible (or next to impossible, as there are ways but you won't be doing them :-)) to edit the program data. You *CAN* store the data in a file in the same folder if you want (or a file anywhere you want), but the getsettings and savesettings APIs do this for you (or is it another API you use to save to INI files?) just as well as you could do it yourself :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 7th, 2007, 05:26 PM
#14
Re: launching a program
GetPrivateProfileString and WritePrivateProfileString are the 2 APIs needed to read and write to a ini file. But an ini file is nothing more then a textfile so users could open it too.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 7th, 2007, 05:33 PM
#15
Thread Starter
Lively Member
Re: launching a program
is it possible to launch a file listed in a regular text file?
-
Jan 7th, 2007, 05:36 PM
#16
PowerPoster
Re: launching a program
Didn't I just say that with "You *CAN* store the data in a file in the same folder if you want (or a file anywhere you want), but the getsettings and savesettings APIs do this for you (or is it another API you use to save to INI files?) just as well as you could do it yourself :-)"
Okay, I didn't clearly state it, but yes you can...save each file name with a carriage return (vbCrLf, or vbNewLine...same thing, really) or something and you can load the whole file with the code in my sig then split them using that carriage return (or whatever you use)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 7th, 2007, 05:36 PM
#17
Re: launching a program
Just read the file into your program and shell the data read if it contains a filepath to the program's exe.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 7th, 2007, 07:15 PM
#18
Thread Starter
Lively Member
Re: launching a program
Can you give me an example of how to do this?
Thanks
-
Jan 8th, 2007, 12:55 AM
#19
Re: launching a program
Here are a couple of text file faqs that will help -
http://vbforums.com/showthread.php?t=405051
http://vbforums.com/showthread.php?t=342619
Then to shell the filepath...
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim strFile() As String
Dim i As Integer
'Read the entire file to the strFile string array
Open "C:\MyPrograms.txt" For Input As #1
strFile = Split(Input$(LOF(1), 1), vbNewline)
Close #1
'Shell each array entry as it contains each program file and path
For i = 0 to UBound(strFile)
Shell strFile(i), vbNormalFocus
Next
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 8th, 2007, 11:40 AM
#20
Thread Starter
Lively Member
Re: launching a program
Thanks for the code. It works great ad the program opens like expected, however i get a runtime error 53. the line " Shell strFile(i), vbNormalFocus" is highlighted in yellow. I dont know whats wrong wih it.
-
Jan 8th, 2007, 11:44 AM
#21
Re: launching a program
What is the array element data? It should be a valid full filepath and name.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 8th, 2007, 12:04 PM
#22
Thread Starter
Lively Member
Re: launching a program
D:\myapp.exe is what is in the txt file. The program opens, it works just as it should... i just get an error message when there is no apperent error.
-
Jan 8th, 2007, 12:25 PM
#23
Re: launching a program
Could it be that there is an extra blank line at the end of the file?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 8th, 2007, 12:43 PM
#24
Thread Starter
Lively Member
Re: launching a program
yeah, thats what is wrong, but how do i fix that in the program, to stop it from saving that blank?
Last edited by stevevb6; Jan 8th, 2007 at 12:48 PM.
-
Jan 8th, 2007, 12:50 PM
#25
Re: launching a program
Post your code for that part. Its probably just an extra vbNewline or something easy.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 8th, 2007, 01:07 PM
#26
Thread Starter
Lively Member
Re: launching a program
VB Code:
Private Sub Command1_Click()
Dim hFile As Long
Dim sFilename As String
sFilename = "c:\myprogram.txt"
'obtain the next free file handle from the
'system and and save the text box contents
hFile = FreeFile
Open sFilename For Output As #hFile
Print #hFile, Text1.Text
Close #hFile
Last edited by stevevb6; Jan 8th, 2007 at 01:16 PM.
-
Jan 8th, 2007, 01:21 PM
#27
Re: launching a program
If its only going to print the one item to the textfile then you can use the semicolon to designate that it not enter a newline since no more entries will be made.
VB Code:
Print #hFile, Text1.Text;
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 8th, 2007, 02:15 PM
#28
Thread Starter
Lively Member
-
Jan 8th, 2007, 02:50 PM
#29
Thread Starter
Lively Member
Re: launching a program
i found the problem. saving the location as a .txt file would make an extra line at the end of the path, making it have the error, by makeing up my own extention, it works just fine.
-
Jan 8th, 2007, 03:09 PM
#30
Re: launching a program
Is Text1.Text
a multiline textbox?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 8th, 2007, 03:25 PM
#31
Thread Starter
Lively Member
Re: launching a program
nope. Its a single line textbox. I think it has something to do with txt files in general. not really sure, but when i sove the textbox as a .rtc file (made up by me) It opened just fine.
-
Jan 8th, 2007, 03:35 PM
#32
Re: [RESOLVED] launching a program
Weird as the semi colin fixes it for me. The semicolon designates that there will be no new line added after the print statement.
VB Code:
Open "C:\DeleteMe\Test2.txt" For Output As #1
Print #1, "Test";
Close #1
Produced a single line text file with no next blank line.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|