×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Shell execute command that requires textbox value

Shell execute command that requires textbox value

Shell execute command that requires textbox value

(OP)
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

RE: Shell execute command that requires textbox value

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.


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


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

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
https://www.doschke.name

RE: Shell execute command that requires textbox value

Not quite clear exactly what command you want execute. Is adb 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

RE: Shell execute command that requires textbox value

I see you already noticed.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Shell execute command that requires textbox value

(OP)
Thanks Olaf, i edited the post.

RE: Shell execute command that requires textbox value

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

RE: Shell execute command that requires textbox value

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)

Quote (MSDN about ShellExecute)

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
https://www.doschke.name

RE: Shell execute command that requires textbox value

(OP)
Hi Mike, thanks for your reply. I edited the post. Please take a look at this updated code. Thanks

RE: Shell execute command that requires textbox value

Yes, I saw that you edited your post, and replied to that a few minutes ago (see my post, above).

So what exactly is your question? Are you seeing an error message? Or what?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Shell execute command that requires textbox value

(OP)
@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.

RE: Shell execute command that requires textbox value

(OP)
This is the error message which i get after clicking the command button.

RE: Shell execute command that requires textbox value

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

RE: Shell execute command that requires textbox value

I've found what looks like the definitive documentation for ADB: https://developer.android.com/studio/command-line/...

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

RE: Shell execute command that requires textbox value

(OP)
@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 :)

RE: Shell execute command that requires textbox value

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
https://www.doschke.name

RE: Shell execute command that requires textbox value

(OP)
@Olaf Working like a charm! Thanks for your help. thumbsup2 Btw what is the merit of using CHRTRAN instead of STRTRAN?

RE: Shell execute command that requires textbox value

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
https://www.doschke.name

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close