Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input question....

Status
Not open for further replies.

TinkerBear

Programmer
Oct 1, 2001
8
US
Hello,
I finally got my cmd button to, when clicked till launch another application (ie solitare), but now it gets better :

I want the user to be able to input a file location (c:\windows\whatever.exe) via input box, and then the location will be put under a cmd button for execution...here is what my code looks like for the execution function.

------------------------------------------------------------

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

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileStringByKeyName Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Function Exec(str As String) As Long
Dim hwnd As Long
Exec = ShellExecute(hwnd, vbNullString, str, vbNullString, vbNullString, vbNormalFocus)

End Function

Private Sub Command1_Click()
Dim addfile As String

addfile = inputbox("Please enter the name and directory of the chosen file.", "Input Name")
Let addlocation = inputbox("Please enter the full location of file.", "Input Location")

Command3.Caption = addfile

End Sub

Private Sub Command3_Click()
Exec ("addlocation")
End Sub

-----------------------------------------------------------
I can get it to change the caption of the cmd button via input box, but when i want to then have that button to launch the application (addlocation), it jsut doesn't want to load....can ya help me?

Thanks a ton!
 
Your code works fine with me!

Where is addlocation defined ? Shouldn't make a difference, but....

Why don't you use the FileOpen dialog ?

D'Mzzl!
RoverM
 
Question: why are you popping up two input boxes that essentially ask for the same information? And what's the Let statement for? You don't need to use a let when assigning to a string. In fact, it doesn't look like you need that addlocation variable at all.
I never messed with ShellExecute, but I think it just takes a string with the full path to the file. If so, the following might be easier to work with:

Private addfile As String 'This has module scope.

Private Sub Command1_Click()
addfile = inputbox("Please enter the name and directory of the chosen file.", "Input Name")
Command3.Caption = addfile
End Sub

Private Sub Command3_Click()
Exec (addfile)
End Sub

 
I just didn't explain myself correct prolly..

Ok i had "Addfile" on there, so when the user puts the input vaule in (string), is will change the caption to "Solitare" for example...

Then the 2nd input box was for the location....if i do it with just one, the caption for cmd3 will equal the location.

I tried that code you gave me, and it (for some reason beyond me) opens up the visual basic folder....

I was messin with it before, and thats as far as i got.

Any idea whats goin on there?
 
Okay, so addfile is basically the caption for the button. So the user might enter something like "Microsoft Word", and that would display on the button. That means that addlocation is the full path to whatever you want to start, e.g. "C:\Program Files\MS Office\word.exe". To make it a little clearer, you might just use a form with two text boxes, but that's just my opinion.

As to starting the program, the only other thing I might suggest is using the Shell function instead of the API call. I've never used the ShellExecute API, but it looks like all you're really doing is using it to start a program, which you can do with the Shell(pathname) function. So, you could just change the code for the command butotn to:

Private Sub Command3_Click()
'This assumes that addlocation is a module level string
Shell addlocation
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top