本文介绍了运行时错误8018?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行时错误8018:
该操作仅在端口打开时有效.
调试时说Mscomm1.output = 6
我是vb的新手..
我的代码...
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 ' Holds our incoming data
MSComm1.Input = sdata2
Label1.DataField = CLng(sdata2)
End Sub
Private Sub MSComm1_OnComm()
Dim sData As String ' Holds our incoming data
Dim lHighByte As Long ' Holds HighByte value
Dim lLowByte As Long ' Holds LowByte value
Dim lByte As Long ' Holds the Byte result
' If comEvReceive Event then get data and display
If MSComm1.CommEvent = comEvReceive Then
sData = MSComm1.Input ' Get data
lHighByte = Asc(Mid$(sData, 1, 1)) ' get 1st byte
lLowByte = Asc(Mid$(sData, 2, 1)) ' Get 2nd byte
lByte = JoinHighLow(lHighByte, lLowByte)
Label1.Caption = CStr(lByte)
DrawScale lByte
End If
' Fire Rx Event Every Two Bytes
MSComm1.RThreshold = 2
' When Inputting Data, Input 2 Bytes at a time
MSComm1.InputLen = 2
' 2400 Baud, No Parity, 8 Data Bits, 1 Stop Bit
MSComm1.Settings = "2400,N,8,1"
' Make sure DTR line is low to prevent Stamp reset
MSComm1.DTREnable = False
' Use COM9
MSComm1.CommPort = 1
' Open the port
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) 'Chr$(255) &
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
推荐答案
这篇关于运行时错误8018?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!