Dim MSComm1 As MSComm
on error goto cant_open_com1
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.DTREnable = True
MSComm1.Handshaking = comRTS
MSComm1.InBufferSize = 12 + 1 ' +1 for the CR
MSComm1.RThreshold = MSComm1.InBufferSize
MSComm1.RTSEnable = True
MSComm1.InputLen = 0 ' read entire input buffer
MSComm1.InputMode = comInputModeText
MSComm1.NullDiscard = True
MSComm1.OutBufferSize = 0 ' not used, we don't write to the serial port
MSComm1.SThreshold = MSComm1.OutBufferSize
'MSComm1.ParityReplace = ?
MSComm1.PortOpen = True
控制傳遞到對錯誤處理程序爲什麼VB 6代碼不能打開串口?
而且我們有猜測錯誤信息是什麼? (?) – Marco 2010-09-02 14:02:13
@Marco給出發佈的代碼,它應該是'Object variable或With block variable not set',因爲'MSComm1'是'Nothing'。 – GSerg 2010-09-02 14:05:03
我想這是因爲你沒有初始化MSComm1,嘗試將它設置爲新的msComm。 設置MSComm1 =新的MSComm(或類似的東西) 這是使用一個控件來做到這一點。 我從來沒有使用COM端口..只有一次,但我用了一個很好的OCX:P http://www.thaiio.com/prog-cgi/0002_serial.htm – Marco 2010-09-02 14:17:10