Parallel Port Programming: Visual Basic

Unfortunately, Visual Basic does not ship with built-in support for addressing the parallel port. However, an excellent DLL from the company SoftCircuits is available for free download. I have a copy of it here. To use it, unzip the file and copy it to your windows/system directory in Win9x. You must be using 32-bit Visual Basic 4 or higher. The following general declarations are needed in your VB program to make use of this DLL. I've included both input and output declarations here.

Declare Sub vbOut Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
Declare Sub vbOutw Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
Declare Function vbInp Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer
Declare Function vbInpw Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer

Once the above declarations are made (I put them in a separate module), you can use the vbOut function to write to the port. The syntax is

vbOut port, value

In the code below, I added a text box called "txtSend" and a command button called "cmdSend" to a form. When cmdSend is clicked, the value in txtSend is interpreted as hex and written to the parallel port at 378 hex.

Option Explicit

Private Sub cmdSend_Click()
    Dim strout As String
    strout = "&H" & txtSend.Text
    vbOut &H378, strout
End Sub