Jumat, 06 April 2012

[ExcelVBA] Using the Shell function in VBA

 



I have had great success using Excel for Serial/USB I/O using the CreateFile Function (and related functions) in kernel32, but the functions and low level routines were written my someone more knowledgable than me. MSDN helped understand them.

I want to try using the Shell function to set the com port up.

I can manually do it in the DOS window using the mode command like this:
C:\> mode com4:96,n,8,1
The response is correct. (The port parameters)

However if I use this (used by someone else) in my VBA:

Shell (Environ("comspec") + " /c mode Com4:9600,n,8,2")

There is no error, but it does not change the port parameters. I do see a DOS window 'placeholder' thingy momentarily popup in the task bar at the bottom of the Vista Window.

To verify this I can either change port parameters manually in DOS to something like 300 baud and the above doesn't change it back to 9600. Or I can change it to 300 baud:
Shell (Environ("comspec") + " /c mode Com4:300,n,8,2")
And the port stays at 9600.

I know this isn't exactlly VBA, but there must be a slightly different syntax for VBA.

Any help here?

FWIW, The references I do have as well as on-line don't give complete syntax for the DOS mode command either.

Regards, Steve

__._,_.___
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
.

__,_._,___

Tidak ada komentar:

Posting Komentar