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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell execute command that requires textbox value

Status
Not open for further replies.

a1sifat

Programmer
Aug 22, 2018
11
BD
I'm developing a simple vfp application which has 3 textboxes(mobile_number, amount, pin) and 1 command button. Command button is to execute a Shell execute command which requires the value of those three textboxes.
As an example, if the user inputs 12345678901 in mobile_number textbox, 50 in amount textbox and 2568 in pin textbox then the command button should execute this command-
Code:
adb shell am start -a android.intent.action.CALL -d tel:*999*12345678901*50*2568#
here goes the command button click event code-
Code:
DECLARE INTEGER ShellExecute IN shell32.dll ; 
INTEGER hndWin, ; 
STRING cAction, ; 
STRING cFileName, ; 
STRING cParams, ; 
STRING cDir, ; 
INTEGER nShowWin 
local lcCmd, lcPar 
lcPar = '*999*'+thisform.mobile_number.Value+'*'+thisform.amount.Value+'*'+thisform.pin.Value+'#' 
lcCmd = 'adb shell am start -a android.intent.action.CALL -d tel:'+lcPar && command to Execute 
ShellExecute(0,'open','cmd', '/C' +lcCmd+' ', '',1)

How to achieve this? TIA
 
Something went wrong with your posting.

Likely you didn't read the prompt you get when you click on the code toolbar button. You're not asked to paste in the code in the textbox, you're asked for the name of the programming language - and can also leave that blank, especially when posting VFP code in a VFP forum, that's unnecessary info.
postcode_myzgky.png


The header of your two code sections now show part of your code as the "name" of the language:
postcode2_ojjjsj.png


The code you want to post goes into the main textarea you write your post in after you clicked ok and have this:
postcode3_ny8ch7.png

The text cursor is positioned between code start and end tags, now you can paste your code.

Use the Edit link at the bottom right of your post to ccrrect that.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Not quite clear exactly what command you want execute. Is [tt]adb[/tt] the command, and the rest of the line the parameters? If so, you need something like this:

Code:
ShellExecute(0, "open", "adb", ;
  "shell am start -a android.intent.action.CALL -d tel:*999*12345678901*50*2568#", ;
  "", 1)

More generally:

The third parameter to ShellExecute is the command that you want to execute;

The fourth parameter to ShellExecute is the parameters that you pass to that command.

For more details and some examples, see Introducing ShellExecute()

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Now that you have edited the post, your code is a lot clearer. I think my solution is still valid, but it looks like you already have the correct code. So what exactly is your question?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Do you get any errors? If thisform.amount is a numeric textbox, you will get a type error when trying to concatenate this to a string.
Does your lcCmd have any surplus spaces? Try Alltrimm()ing your input values.

And if Messagebox(lcCmd shows the correct line), what error does ShellExecute return?

? ShellExecute(0,'open','cmd', '/C' +lcCmd+' ', '',1)
MSDN about ShellExecute said:
Return Value

If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value that indicates the cause of the failure

Bye, Olaf.

Olaf Doschke Software Engineering
 
Hi Mike, thanks for your reply. I edited the post. Please take a look at this updated code. Thanks
 
@Mike this is a very basic mobile recharge application. When user inputs customers mobile number, recharge amount and pin and hits the command button then the command button should shell execute this command
Code:
adb shell am start -a android.intent.action.CALL -d tel:*999*12345678901*50*2568#
Please note that i used 12345678901 as mobile number, 50 as amount and 2568 as pin here, this can be any number. May be i should put this textboxes values in dynamic variables and then call those variables inside the shell execute command. What do you think?
Thanks for your time.
 
This is the error message which i get after clicking the command button.
scnshot_klissb.png
 
A1sifat,

I've shown you how to call ShellExecute() and pass parameters to it (see my post dated 22 Aug 18 07:53 above). You have obviously done that correctly, otherwise you would not have got as far as seeing the error message.

So the fault lies in the actual command that you are executing and the parameters that you are passing to it. In other words, it's a problem with adb, not with ShellExecute() - nor even with FoxPro.

So are you sure your parameters to adb are correct? Do you have any documentation for the program? For that matter, where did you get the code that you are using?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I've found what looks like the definitive documentation for ADB:
Clearly it is quite a complex issue, and will need careful reading. I suggest that, before you try to get your VFP code working, you focus on understanding the parameters you need to pass to ADB. The best way to do that is to communicate with it directly from a command prompt. Type (or paste) at the command prompt the command and the parameters that you wish to send, and check the results. It will be easier to get it right there than from within VFP.

Once you know exactly what you need to send to ADB, it should be relatively easy to transfer that to ShellExecute(). As I mentioned earlier, the 4th parameter to ShellExecute() is basically whatever you type at the command prompt after the word ADB itself.

If you need help in understanding ADB, you could try posting in a forum that deals with Android developer issues.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
@Mike i have figured out the problem, the problem was actually in the textboxes. I did not set the maximum length of those textboxes as a result those variables were carrying values with too much white spaces. Due to those white spaces adb was not responding correctly. So now i decided to use STRTRAN() command and remove those white spaces. Here is the modified click event code of the command button.

Code:
DECLARE INTEGER ShellExecute IN shell32.dll ; 
INTEGER hndWin, ; 
STRING cAction, ; 
STRING cFileName, ; 
STRING cParams, ;  
STRING cDir, ; 
INTEGER nShowWin
LOCAL lcMn, lcAmt, lcPin, lcParas
lcMn = thisform.txt_mn.Value && Mobile Number
lcAmt = thisform.txt_amt.Value && Amount
lcPin = thisform.txt_pin.Value && Pin
lcParas = '*999*'+lcMn+'*'+lcAmt+'*'+lcPin+'#' && example: *999*012345678901*50*2568#
Now here i want to use STRTRAN() command to remove white spaces from lcParas variable and then pass the refined variable to

Code:
ShellExecute(0, "open", "adb", ;
  "shell am start -a android.intent.action.CALL -d tel:"+lcParas, ;
  "", 1)
How do i achieve that? Thanks for your time :)
 
Leading and trailing spaces as are likely the only surplus spaces you have from the textboxes can be removed by ALLTRIM(), as I already suggested.

To remove all spaces, also inside strings, though that's not typically, you can use CHRTRAN. So do this, if really no spaces are wanted even in between:
Code:
lcParas = CHRTRAN(lcParas," ","")

You can find all commands and descriptions on how to use them in the help file by typing in a command selecting it and pressing F1.
And when you already know you want to use STRTRAN, that's the main info you need to look it up. If you don't know this trick, the help also has a search feature.

Bye, Olaf.

Olaf Doschke Software Engineering
 
@Olaf Working like a charm! Thanks for your help. [thumbsup2] Btw what is the merit of using CHRTRAN instead of STRTRAN?
 
In case of removing just one character there is no difference.

CHRTRAN exists to map single character to other single characters (or remove them), so you could for example remove all whitespace with CHRTRAN('value, " "+chr(9)+chr(160),'') whereas you would need 3 STRTRAN for that. But you need STRTRAN for searching & replacing more than one character. STRTRAN replaces in search&replace fashion.

From that perspective, removing spaces is removing a single character and goes in the direction of removing whitespace, CHRTRAN() is the better fit.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top