Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21842

VB6 - Sub Or Function Not Delcared

$
0
0
Hello All,

I have been coding in VB6 for over a month now without issue as everything is pretty straightforward. However lately I keep getting this error when I try to seperate out a snippet of code from one function to another.

EX: This is the snippet I have taken from a larger function and for some reason when I try to run my code it chokes when it comes to the function. It says Compile Error - Sub or Function Not Declared





Public Function Test()

Dim HexStr As String
Dim Dec As Integer

For i = 0 To 23
HexStr = "&H" & R(i)
Dec = Val(HexStr)
TAdd = Dec * 0.5
AVal = -64 + TAdd
R(i) = AVal
Next
For i = 0 To 23
HexStr = "&H" & T(i)
Dec = Val(HexStr)
TAdd = Dec * 0.5
AVal = -64 + TAdd
T(i) = AVal
Next
If Cl = True Then
For i = 0 To 23
Text3(i).Text = T(i) - R(i) & "V"
Next
For i = 0 To 23
Text1(i).Text = T(i) & "V"
Next
For i = 0 To 23
Text2(i).Text = R(i) & "V"
Next
Cl = False
End If

End Function

I have tried to call it with as:
Test
Call Test
As well as changed the type from Function to Sub.

It works just fine in the following code:


Public Sub Read()


MSComm1.Output = Chr$(24)
Comput = MSComm1.Input

If MSComm1.InBufferCount > 5 Then
If MsgBox("Not Connected", vbOKOnly) = vbOK Then
End If
GoTo ExitRead
End If
StartF = InStr(Comput, "|00|")
Where = StartF + 8

T(0) = Mid$(Comput, Where, 2)
R(0) = Mid$(Comput, Where + 3, 2)
T(1) = Mid$(Comput, Where + 7, 2)
R(1) = Mid$(Comput, Where + 10, 2)
T(2) = Mid$(Comput, Where + 14, 2)
R(2) = Mid$(Comput, Where + 17, 2)
T(3) = Mid$(Comput, Where + 21, 2)
R(3) = Mid$(Comput, Where + 24, 2)
T(4) = Mid$(Comput, Where + 30, 2)
R(4) = Mid$(Comput, Where + 33, 2)
T(5) = Mid$(Comput, Where + 37, 2)
R(5) = Mid$(Comput, Where + 40, 2)
T(6) = Mid$(Comput, Where + 44, 2)
R(6) = Mid$(Comput, Where + 47, 2)
T(7) = Mid$(Comput, Where + 51, 2)
R(7) = Mid$(Comput, Where + 54, 2)
T(8) = Mid$(Comput, Where + 60, 2)
R(8) = Mid$(Comput, Where + 63, 2)
T(9) = Mid$(Comput, Where + 67, 2)
R(9) = Mid$(Comput, Where + 70, 2)
T(10) = Mid$(Comput, Where + 74, 2)
R(10) = Mid$(Comput, Where + 77, 2)
T(11) = Mid$(Comput, Where + 81, 2)
R(11) = Mid$(Comput, Where + 84, 2)
T(12) = Mid$(Comput, Where + 90, 2)
R(12) = Mid$(Comput, Where + 93, 2)
T(13) = Mid$(Comput, Where + 97, 2)
R(13) = Mid$(Comput, Where + 100, 2)
T(14) = Mid$(Comput, Where + 104, 2)
R(14) = Mid$(Comput, Where + 107, 2)
T(15) = Mid$(Comput, Where + 111, 2)
R(15) = Mid$(Comput, Where + 114, 2)
T(16) = Mid$(Comput, Where + 120, 2)
R(16) = Mid$(Comput, Where + 123, 2)
T(17) = Mid$(Comput, Where + 127, 2)
R(17) = Mid$(Comput, Where + 130, 2)
T(18) = Mid$(Comput, Where + 134, 2)
R(18) = Mid$(Comput, Where + 137, 2)
T(19) = Mid$(Comput, Where + 141, 2)
R(19) = Mid$(Comput, Where + 144, 2)
T(20) = Mid$(Comput, Where + 150, 2)
R(20) = Mid$(Comput, Where + 153, 2)
T(21) = Mid$(Comput, Where + 157, 2)
R(21) = Mid$(Comput, Where + 160, 2)
T(22) = Mid$(Comput, Where + 164, 2)
R(22) = Mid$(Comput, Where + 167, 2)
T(23) = Mid$(Comput, Where + 171, 2)
R(23) = Mid$(Comput, Where + 174, 2)
Dim HexStr As String
Dim Dec As Integer

For i = 0 To 23
HexStr = "&H" & R(i)
Dec = Val(HexStr)
TAdd = Dec * 0.5
AVal = -64 + TAdd
R(i) = AVal
Next
For i = 0 To 23
HexStr = "&H" & T(i)
Dec = Val(HexStr)
TAdd = Dec * 0.5
AVal = -64 + TAdd
T(i) = AVal
Next
If Cl = True Then
For i = 0 To 23
Text3(i).Text = T(i) - R(i) & "V"
Next
For i = 0 To 23
Text1(i).Text = T(i) & "V"
Next
For i = 0 To 23
Text2(i).Text = R(i) & "V"
Next
Cl = False
End If
ExitRead:

End Sub



Also I do not get the error when I comment out the code as well.
I keep running into this problem and I am not entirely sure what I am doing wrong.
I am under the impression that when I write [Private/Public] (TYPE) NAME and end with END (TYPE) that is defining the (TYPE). Is there something I am missing because when I right-click any of my Subs or Functions, including ones created by VB as in Command_Click1() it says 'identifier under cursor is not recognized'.

I would appreciate any help and will provide any additional information!

Thanks

Viewing all articles
Browse latest Browse all 21842

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>