EDN logo


Design Ideas: February 17, 1994

VisualBasic does I/O

Jon Titus,,
Test & Measurement World, Newton, MA


Listing 1—C++ source code for DLL (Borland C++ compiler)
Listing 2—VisualBasic location declarations
Microsoft's VisualBasic—which runs under Windows—cannot operate on a PC's I/O ports. However, you can add dynamic-link libraries (DLLs) to extend the keywords of native VisualBasic (Listing 1). The compiled code, listings, and documentation in ZIPfile DI1167Z.ZIP (attached to EDN BBS /DI_SIG #1367) let you perform I/O operations using the new keywords Inp and Out. These added keywords operate the same way these keywords do in other Basic dialects.

To use Inp and Out in VisualBasic, you must tell your program that these operations exist. Use the Declare statements, as Listing 2 shows. Remember that the Out operation is a subroutine because it simply outputs a byte; it returns nothing back to your VisualBasic program. The Inp operation is a function, because it returns a byte from an input port. You use the ByVal keyword to tell VisualBasic that you want it to transfer the actual value, and not a reference or pointer to the value.

In addition, you must explicitly tell VisualBasic where to find the library functions in your DLL. This example assumes the DLL is on a floppy disk in the B drive. You can put the DLL on another drive, but be sure to tell VisualBasic where it is.

Simple VisualBasic program fragments show how to use the Inp and Out instructions. For example, Out 771, 130 sends the value 130 to output port 771 of my PC. On the other hand, A=Inp(769) assigns the byte at input port 769 to variable A. The syntax is exactly the same as in most other Basics. EDN BBS /DI_SIG #1367





| EDN Access | feedback | subscribe to EDN! |
| design features | design ideas |


Copyright © 1995 EDN Magazine. EDN is a registered trademark of Reed Properties Inc, used under license.