Link to home
Start Free TrialLog in
Avatar of markleszczynski
markleszczynski

asked on

How do you put a variable in a shell command line?

Shell("C:\Program Files\Microsoft Office\Office11\Outlook.exe /c ipm.note /m mailto:name@comcast.net&subject=Retrofits%21&body=txtRetrofitPartNumber.text")

I have the above command line in a Visual Basic Button_Click event.  When I click the button a pre-addressed, pre-formatted new e-mail message pops up. To: name@comcast.net, Subject: Retrofits.  This is what I want so far.  In the body I have the literal txtRetrofitPartNumber.text. n my program that is a variable.  It is a textbox that the text will change from time to time.  I want my e-mail to have the text that was typed into txtretrofitPartNumber.text not the literal "txtRetrofitPartNumber.text"  Any ideas how to do that?
Avatar of Joel Coehoorn
Joel Coehoorn
Flag of United States of America image

Shell("C:\Program Files\Microsoft Office\Office11\Outlook.exe /c ipm.note /m mailto:name@comcast.net&subject=Retrofits%21&body=" & txtRetrofitPartNumber.text)

That was the simple answer.  The complete answer is that Shell is included for compatibility with VB6, and you should really move on to using System.Diagnostics.Process()  (or just Process() ) instead.  Then build the string like I show above.
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
notice your text should be very short and simple. Will be better if you use UrlEnconding to avoid invalid characters in body text:

Shell("C:\Program Files\Microsoft Office\Office11\Outlook.exe /c ipm.note /m mailto:name@comcast.net&subject=Retrofits%21&body=" & _
System.Web.HttpUtility.UrlEncode(txtRetrofitPartNumber.Text))