Visual Basic questions - Printable Version +- Renegade Projects Network Forums (https://forums.renegadeprojects.com) +-- Forum: General Forums (https://forums.renegadeprojects.com/forumdisplay.php?fid=1) +--- Forum: The Renegade Inn (https://forums.renegadeprojects.com/forumdisplay.php?fid=2) +--- Thread: Visual Basic questions (/showthread.php?tid=1023) |
Visual Basic questions - Professor_Tesla - 24.07.2008 Does anyone on here know Visual Basic 6? If so, I have a few questions: 0)How do I call another program in the same directory as the program doing the calling? 1)How do I call another program in a subdirectory of the directory of the program doing the calling? 2)How do I open a file in its default program if the file is in a subdirectory to the program doing the calling? I tried looking on google, but it took me about an hour and a half to discover nothing. RE: Visual Basic questions - DCoder - 24.07.2008 Marshall will probably comment in more detail, but the most universal way would be to use ShellExecute. RE: Visual Basic questions - Marshall - 24.07.2008 I'll post some details when I get home from work. However not sure what question 2 is asking: Are you asking, for example, how to "run a TXT file" such that it will open in Notepad (or whatever is the user's associated program)? Or something else? EDIT: You can call pretty much any program from your VB6 app regardless of where it is on your HD. The program you call might expect the current working directory to be set to it's own directory though, rather than the directory of your VB6 app, so you might have to set this using a separate API. You can call programs in several different ways. Here's an example of how I might call oggdec.exe to convert an OGG file to a WAV: Code: dim sOggPath as string The above code calls three API functions that you need to declare: Code: Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Code: Private Const SYNCHRONIZE = &H100000 If you want to open, say, a text file with the user's default program do something like this: Code: If OpenLocation(sTextFilePath) < 32 Then Call frmMain.WriteLogEntry("Error opening " & sTextFilePath, LogMsgBox) Code: If OpenLocation(sWebsite) < 32 Then Call MsgBox("Unable to open " & sWebsite, vbOKOnly + vbInformation, App.Title) Code: Public Function OpenLocation(ByVal WhichFilePath As String, Optional sParams As String = "", Optional sStartIn As String = vbNullString, Optional lngOpenMode As Long = 1) As Long 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 There are other ways to do this but those are the ways I use the most. You may need to play around with quotes and short/long filenames depending on what you're calling and where on the hard drive it is. You can find most of the info you need on the web, you just gotta think how to structure your search. I learnt what I know 10% taught at school, 60% web searching and 30% trial and error. RE: Visual Basic questions - Professor_Tesla - 25.07.2008 Vielen Dank. RE: Visual Basic questions - DCoder - 25.07.2008 Do bear in mind that file paths with spaces need to be enclosed in double quotes to work properly. |