Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default MSComm locking up Excel

Has anyone ever experienced locking issues when they use
the MSCOMM control? Mine does it quite often and I do not
know why. Here is the code I am using:

Sub GetInput()
ActiveCell.Value = GetWeight()
End Sub

Public Function GetWeight() As Double
Dim sInput As String

On Error GoTo ErrorHandler

If frmComm.comExcel.InBufferCount 0 Then
frmComm.comExcel.InBufferCount = 0
End If

ActiveCell.Value = "Waiting for Stable..."
frmComm.comExcel.CommPort = 1
frmComm.comExcel.Settings = "9600,N,7,2"
frmComm.comExcel.PortOpen = True
frmComm.comExcel.Output = "1S" & Chr$(13) 'Print on
stable
frmComm.comExcel.Output = "P" & Chr$(13) 'Display data

Do
DoEvents
Loop Until frmComm.comExcel.InBufferCount = 18

sInput = frmComm.comExcel.Input
Dim x As Integer
Dim intLength As Integer
Dim strTemp As String
Dim strTemp1 As String

intLength = Len(sInput)

For x = 1 To intLength
strTemp = Mid(sInput, x, 1)

Select Case strTemp
Case 0 To 9
strTemp1 = strTemp1 + strTemp
Case "."
strTemp1 = strTemp1 + strTemp
End Select
Next x

GetWeight = strTemp1

frmComm.comExcel.PortOpen = False

'GetWeight = Val(Mid$(sInput, 1))

Exit Function

ErrorHandler:
If Err.Number = 8005 Then
Exit Function
Else
MsgBox Err.Description
End If
End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default MSComm locking up Excel

Do
DoEvents
Loop Until frmComm.comExcel.InBufferCount = 18

would loop forever if InBufferCount doesn't achieve 18

perhaps you also want to capture the time when you enter the loop and have
it jump out or end when a certain amount of time has elapsed.

--
Regards,
Tom Ogilvy

"Eric" wrote in message
...
Has anyone ever experienced locking issues when they use
the MSCOMM control? Mine does it quite often and I do not
know why. Here is the code I am using:

Sub GetInput()
ActiveCell.Value = GetWeight()
End Sub

Public Function GetWeight() As Double
Dim sInput As String

On Error GoTo ErrorHandler

If frmComm.comExcel.InBufferCount 0 Then
frmComm.comExcel.InBufferCount = 0
End If

ActiveCell.Value = "Waiting for Stable..."
frmComm.comExcel.CommPort = 1
frmComm.comExcel.Settings = "9600,N,7,2"
frmComm.comExcel.PortOpen = True
frmComm.comExcel.Output = "1S" & Chr$(13) 'Print on
stable
frmComm.comExcel.Output = "P" & Chr$(13) 'Display data

Do
DoEvents
Loop Until frmComm.comExcel.InBufferCount = 18

sInput = frmComm.comExcel.Input
Dim x As Integer
Dim intLength As Integer
Dim strTemp As String
Dim strTemp1 As String

intLength = Len(sInput)

For x = 1 To intLength
strTemp = Mid(sInput, x, 1)

Select Case strTemp
Case 0 To 9
strTemp1 = strTemp1 + strTemp
Case "."
strTemp1 = strTemp1 + strTemp
End Select
Next x

GetWeight = strTemp1

frmComm.comExcel.PortOpen = False

'GetWeight = Val(Mid$(sInput, 1))

Exit Function

ErrorHandler:
If Err.Number = 8005 Then
Exit Function
Else
MsgBox Err.Description
End If
End Function



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
row locking, instead of file locking? Bob W Excel Discussion (Misc queries) 2 September 7th 07 09:36 PM
locking formula in cells in without locking whole sheet SuziQ Excel Discussion (Misc queries) 1 July 21st 06 03:58 PM
Unloading userform in MSComm event Sunny[_4_] Excel Programming 0 June 10th 04 06:04 PM
MSCOMM markm Excel Programming 3 November 21st 03 02:49 PM
Loading MSComm.vbx into Excel VB ryan Excel Programming 0 August 10th 03 06:17 PM


All times are GMT +1. The time now is 06:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"