run time error 8018:
operation valid only when the port is open.
when debuggin it says Mscomm1.output = 6
im a newbie in vb..
my code...
Dim hwdc As Long
Dim startcap As Boolean
Private Sub Command10_Click()
Dim sdata2 As Long
MSComm1.Input = sdata2
Label1.DataField = CLng(sdata2)
End Sub
Private Sub MSComm1_OnComm()
Dim sData As String
Dim lHighByte As Long
Dim lLowByte As Long
Dim lByte As Long
If MSComm1.CommEvent = comEvReceive Then
sData = MSComm1.Input
lHighByte = Asc(Mid$(sData, 1, 1))
lLowByte = Asc(Mid$(sData, 2, 1))
lByte = JoinHighLow(lHighByte, lLowByte)
Label1.Caption = CStr(lByte)
DrawScale lByte
End If
MSComm1.RThreshold = 2
MSComm1.InputLen = 2
MSComm1.Settings = "2400,N,8,1"
MSComm1.DTREnable = False
MSComm1.CommPort = 1
MSComm1.PortOpen = True
End Sub
Private Function JoinHighLow(lHigh As Long, lLow As Long) As Long
JoinHighLow = (lHigh * &H100) Or lLow
End Function
Private Sub DrawScale(lVal As Long)
Picture1.Cls
Picture1.Line (0, 0)-(lVal, Picture1.ScaleHeight), vb3DShadow, BF
End Sub
Private Sub Command11_click()
Dim PinNumber As Variant
PinNumber = Text2.DataField
MSComm1.Output = Chr$(PinNumber)
End Sub
Private Sub Command2_click()
MSComm1.Output = Chr$(3)
End Sub
Private Sub Command3_Click()
MSComm1.Output = 4
End Sub
Private Sub Command1_click()
MSComm1.Output = 1
End Sub
Private Sub Command4_Click()
MSComm1.Output = 2
End Sub
Private Sub Command5_Click()
MSComm1.Output = 9
End Sub
Private Sub Command6_Click()
MSComm1.Output = 6
End Sub
Private Sub Command7_Click()
MSComm1.Output = 7
End Sub
Private Sub Command8_Click()
MSComm1.Output = 8
End Sub
Private Sub Command9_Click()
MSComm1.Output = 5
End Sub
Private Sub cmdCapture_Click()
Dim temp As Long
hwdc = capCreateCaptureWindow("NeV0 Vision System", ws_child Or ws_visible, 0, 0, 640, 480, Picture1.hWnd, 0)
If (hwdc <> 0) Then
temp = SendMessage(hwdc, wm_cap_driver_connect, 0, 0)
temp = SendMessage(hwdc, wm_cap_set_preview, 1, 0)
temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 0)
startcap = True
Else
MsgBox ("No Webcam found")
End If
End Sub
Private Sub cmdClose_Click()
Dim temp As Long
If startcap = True Then
temp = SendMessage(hwdc, WM_CAP_DRIVER_DISCONNECT, 0&, 0&)
startcap = False
End If
End Sub
Private Sub cmdVideoFormat_Click()
Dim temp As Long
If startcap = True Then
temp = SendMessage(hwdc, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
End If
End Sub