• Welcome to Valhalla Legends Archive.
 

Whats wrong with this?

Started by OuTLawZGoSu, March 11, 2004, 10:35 PM

Previous topic - Next topic

OuTLawZGoSu

I cant get this to work .



'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


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?

Grok

Hmm, works here.  Maybe textbox is empty?  Add:

   If Len(frmMain.txtProgramAddress.Text) = 0 Then Exit Sub


OuTLawZGoSu

Nope, still showing the same thing.

o.OV

#3
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)
If the facts don't fit the theory, change the facts. - Albert Einstein

Flame

#4
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 "

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):
ShellExecute Me.HWnd, vbNullString, frmMain.txtProgramAddress.Text, vbNullString, "C:\", SW_SHOWNORMAL
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

o.OV

Quote from: Flame on March 12, 2004, 03:12 PM
ShellExecute Me.HWnd, vbNullString, frmMain.txtProgramAddress.Text, vbNullString, "C:\", SW_SHOWNORMAL

Just an opinion. :)
but if it were me..
I wouldn't predefine the drive.
If the facts don't fit the theory, change the facts. - Albert Einstein

OuTLawZGoSu

That works, but if the address is invalid, it wont do anything. I need to notify the user that the program isnt there.

Msgbox "The requested program could not be found."
'Just an example.


Help?

Spht

   If Len(Dir(frmMain.txtProgramAddress.Text)) Then
       ' Program exists, launch
   Else
       ' Doesn't exist, show error
   End If

Newby

Quote from: Spht on March 12, 2004, 09:32 PM
   If Len(Dir(frmMain.txtProgramAddress.Text)) Then
       ' Program exists, launch
   Else
       ' Doesn't exist, show error
   End If


Another way.

If Dir$(frmMain.txtProgramAddress.Text) <> vbNullString Then
   'Program exists, gogogo!
Else
   'Program doesn't exist, nonono!
End If
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

o.OV

#9
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.
If the facts don't fit the theory, change the facts. - Albert Einstein

Grok

Quote from: Spht on March 12, 2004, 09:32 PM
   If Len(Dir(frmMain.txtProgramAddress.Text)) Then
       ' Program exists, launch
   Else
       ' Doesn't exist, show error
   End If


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.

Spht

I figured program "address" included the full path.

Spht

#12
Quote from: Newby on March 12, 2004, 11:19 PM
Another way.

If Dir$(frmMain.txtProgramAddress.Text) <> vbNullString Then
   'Program exists, gogogo!
Else
   'Program doesn't exist, nonono!
End If


Yes, that is another way, but it requires more typing, so your point is? IIRC, checking length is faster than checking string content anyway.

g0dFraY

Hey, some of you may know that im just starting to learn DLL's and i was reading this post and found:

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


is the Alias "ShellExecuteA" needed and if so what does it do, just other functions you may use instead of "ShellExecute" or what?

o.OV

#14
"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.
If the facts don't fit the theory, change the facts. - Albert Einstein