Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
compiler: invalid outside procedure

error while debugging what is the problem???

<pre lang="vb">Dim hwdc As Long
Dim startcap As Boolean

' 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 = 9

' Open the port
MSComm1.PortOpen = True


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
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$(255) & Chr$(PinNumber)
End Sub
Private Sub Command2_click()
MSComm1.Output = 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 Form_Load()

' Default to text2 being selected
Text2.DataField = 0

' 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 COM17
MSComm1.CommPort = 17

' Open the port
MSComm1.PortOpen = True

End Sub


Private Sub cmdCapture_Click()
Dim temp As Long

  hwdc = capCreateCaptureWindow("NeV0 Vision System", ws_child Or ws_visible, 0, 0, 320, 240, 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
Posted
Updated 12-Mar-12 10:20am
v4
Comments
Sergey Alexandrovich Kryukov 12-Mar-12 16:05pm    
What are you thinking about, in principle? Without any code sample? Can you see "Improve question" above? This is your change to get some answer.
--SA
Sergey Alexandrovich Kryukov 12-Mar-12 16:07pm    
Besides, this is compiler message. How could this be an error while debugging?
--SA
OriginalGriff 12-Mar-12 16:08pm    
My guess is that he typed the error while the debugger as stopped at a breakpoint.
OriginalGriff 12-Mar-12 16:07pm    
As SA says, we would need more information - the error the line occurred on, a few lines either side for context.
Use the "Improve question" widget to edit your question and provide better information.
ZurdoDev 12-Mar-12 16:33pm    
The error should refer to a line of code.

1 solution

The error message is telling you exactly what is happening. MSComm1.RThreshold = 2 is an assignment and it needs to be inside one of your Sub routines.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Mar-12 0:54am    
Yes, as simple as that, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900