Author | Message | Time |
---|---|---|
OuTLawZGoSu | I cant get this to work . [code] 'frmMain 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 Const SW_SHOWNORMAL = 1 Private Sub cmdRunProgram_Click() Shell frmMain.txtProgramAddress.Text, vbNormalFocus End Sub [/code] For some reason, when I click cmdRunProgram, an error displays " Invalid Procedure, Call, or Argument " and highlights " Shell frmMain.txtProgramAddress.Text, vbNormalFocus " I cant get wats wrong. Help? | March 12, 2004, 4:35 AM |
Grok | Hmm, works here. Maybe textbox is empty? Add: If Len(frmMain.txtProgramAddress.Text) = 0 Then Exit Sub | March 12, 2004, 5:01 AM |
OuTLawZGoSu | Nope, still showing the same thing. | March 12, 2004, 5:17 AM |
o.OV | I noticed you declared the API function.. Why don't you use it? Add-On: What did the variable contain exactly? When you use the native Shell function.. you should imagine you are in MS-DOS. For example.. You are running DOS-Prompt. You would type: notepad c:\thefiledirectory\readme.txt notepad readme.txt (if you are currently in the same directory as file) | March 12, 2004, 5:49 AM |
Flame | [quote] 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 Const SW_SHOWNORMAL = 1 Private Sub cmdRunProgram_Click() Shell frmMain.txtProgramAddress.Text, vbNormalFocus End Sub For some reason, when I click cmdRunProgram, an error displays " Invalid Procedure, Call, or Argument " and highlights " Shell frmMain.txtProgramAddress.Text, vbNormalFocus " [/quote] I believe you meant ShellExecute instead of Shell for one, second you're missing a few of the arguments. I have mine set similar to the code below, and it works fine (I edited it to open what seems to be the file you want to open): [code]ShellExecute Me.HWnd, vbNullString, frmMain.txtProgramAddress.Text, vbNullString, "C:\", SW_SHOWNORMAL[/code] This code would go into the same form that your button is located, I hope it helps some Edit: Oops... I forgot about Shell, anyways that is the code to use ShellExecute, if you choose to use it, I've never even used the Shell command, but I suppose you could if you wanted to | March 12, 2004, 9:12 PM |
o.OV | [quote author=Flame link=board=31;threadid=5737;start=0#msg49095 date=1079125922] [code]ShellExecute Me.HWnd, vbNullString, frmMain.txtProgramAddress.Text, vbNullString, "C:\", SW_SHOWNORMAL[/code] [/quote] Just an opinion. :) but if it were me.. I wouldn't predefine the drive. | March 12, 2004, 9:30 PM |
OuTLawZGoSu | That works, but if the address is invalid, it wont do anything. I need to notify the user that the program isnt there. [code] Msgbox "The requested program could not be found." 'Just an example. [/code] Help? | March 13, 2004, 3:23 AM |
Spht | [code] If Len(Dir(frmMain.txtProgramAddress.Text)) Then ' Program exists, launch Else ' Doesn't exist, show error End If[/code] | March 13, 2004, 3:32 AM |
Newby | [quote author=Spht link=board=31;threadid=5737;start=0#msg49160 date=1079148728] [code] If Len(Dir(frmMain.txtProgramAddress.Text)) Then ' Program exists, launch Else ' Doesn't exist, show error End If[/code] [/quote] Another way. [code]If Dir$(frmMain.txtProgramAddress.Text) <> vbNullString Then 'Program exists, gogogo! Else 'Program doesn't exist, nonono! End If[/code] | March 13, 2004, 5:19 AM |
o.OV | I use LenB instead of Len (A speed difference maybe.. but I use it since code optimize sites suggest it when checking for empty strings.) and I don't think Dir$ makes a difference since is a function that returns a string anyways. ending the function with a "$" is more commonly used with Left, Right, and Mid (maybe some others) because they can be used with various datatypes. | March 13, 2004, 8:23 AM |
Grok | [quote author=Spht link=board=31;threadid=5737;start=0#msg49160 date=1079148728] [code] If Len(Dir(frmMain.txtProgramAddress.Text)) Then ' Program exists, launch Else ' Doesn't exist, show error End If[/code] [/quote] Bad. What if user put "calc.exe" in the text box? If you just use Dir(), you're missing out on the machine's search path. | March 13, 2004, 10:16 AM |
Spht | I figured program "address" included the full path. | March 13, 2004, 5:29 PM |
Spht | [quote author=Newby link=board=31;threadid=5737;start=0#msg49178 date=1079155176] Another way. [code]If Dir$(frmMain.txtProgramAddress.Text) <> vbNullString Then 'Program exists, gogogo! Else 'Program doesn't exist, nonono! End If[/code] [/quote] Yes, that is another way, but it requires more typing, so your point is? IIRC, checking length is faster than checking string content anyway. | March 13, 2004, 6:31 PM |
g0dFraY | Hey, some of you may know that im just starting to learn DLL's and i was reading this post and found: [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 Const SW_SHOWNORMAL = 1[/code] is the [code]Alias "ShellExecuteA"[/code] needed and if so what does it do, just other functions you may use instead of "ShellExecute" or what? | March 19, 2004, 11:33 PM |
o.OV | "ShellExecuteA" is the entry point (is needed) ShellExecute is whatever you want to name the entry point to assuming it isnt a conflicting name. You should read up on a tutorial.. Google. | March 20, 2004, 1:27 AM |