Enum in macro generates compile error

G

Gene Augustin

MAC Powerbook G4, OS 10.5.6
Office 2004, Excel 2004 Version 11.5.3

I have a macro provided by an equipment manufacturer. It is supposed to work
on MAC. Mfr no help. The macro crashes with message "Compile Error Expected
Identifier" and the code is highlighted in red as noted here:

Public Enum DAQ_states 'red
stopped = 0
running = 1
End Enum 'red

Public DAQ_state As daq_states, DAQ_counter As Long
'
'



If I use the immediate window and print stopped and running, they are 0 and
1 respectively.

Any suggestions on how to fix this code?

Here's the sub that uses the DAQ_states:

Public Sub DAQ_Procedure()
' Data Acquisition Procedure

Dim message As String, car As Byte

If DAQ_state = running Then

DAQ_counter = DAQ_counter + 1
' increment acquisiton sample counter
Worksheets(1).Range("B2") = DAQ_counter
' and display it inside spreadsheet in real time

Put #1, , "adc 1" + vbLf
' ask µChameleon for voltage on its adc input pin 1

message = ""
Do
' retreive answer on byte at a time
DoEvents
Get #1, , car
If car = Asc(vbLf) Then Exit Do
' until we see the end-of-line character
message = message & Chr(car)
Loop

words = Split(message)
' analyse answer - syntax should be : adc 1 <value>

Worksheets(1).Cells(DAQ_counter, 4) = Val(words(2))
' add measured value in column D, in successive rows

If DAQ_counter >= 60 Then DAQ_state = stopped
' do that for a minute
Application.OnTime Now + TimeValue("00:00:01"), "DAQ_Procedure"
' launch next acquisiton in one second

Else

Put #1, , "led pattern 254" & vbLf
' set activity led back to its default pattern so we know it stopped
Close #1
' and close communications port

End If

End Sub
 
B

Bob Greenblatt

MAC Powerbook G4, OS 10.5.6
Office 2004, Excel 2004 Version 11.5.3

I have a macro provided by an equipment manufacturer. It is supposed to work
on MAC. Mfr no help. The macro crashes with message "Compile Error Expected
Identifier" and the code is highlighted in red as noted here:

Public Enum DAQ_states 'red
stopped = 0
running = 1
End Enum 'red

Public DAQ_state As daq_states, DAQ_counter As Long
Maybe it is "Supposed" to work on a mac, but it obviously has never been
tested. The enum variable type is not supported in Mac VBA.
 
J

John McGhie

Hi Gene:

The person who wrote that code should be smacked upside the head. He's
created a whole lot of pain and misery and he doesn't even need the ENUM :)
I mean, how dumb is that? You don't NEED an ENUM if you have only two
entries :)

Try this:


Delete this bit, you don't need it.
Public Enum DAQ_states 'red
stopped = 0
running = 1
End Enum 'red


Change this line
Public DAQ_state As daq_states, DAQ_counter As Long

to:
Public DAQ_state As Boolean, DAQ_counter As Long
Public Sub DAQ_Procedure()
' Data Acquisition Procedure

Dim message As String, car As Byte

Change this line:
If DAQ_state = running Then
to:
If DAQ_state = TRUE Then
DAQ_counter = DAQ_counter + 1
' increment acquisiton sample counter
Worksheets(1).Range("B2") = DAQ_counter
' and display it inside spreadsheet in real time

Put #1, , "adc 1" + vbLf
' ask µChameleon for voltage on its adc input pin 1

message = ""
Do
' retreive answer on byte at a time
DoEvents
Get #1, , car
If car = Asc(vbLf) Then Exit Do
' until we see the end-of-line character
message = message & Chr(car)
Loop

words = Split(message)
' analyse answer - syntax should be : adc 1 <value>

Worksheets(1).Cells(DAQ_counter, 4) = Val(words(2))
' add measured value in column D, in successive rows

Change this line:
If DAQ_counter >= 60 Then DAQ_state = stopped
to:
If DAQ_counter >= 60 Then DAQ_state = False
' do that for a minute
Application.OnTime Now + TimeValue("00:00:01"), "DAQ_Procedure"
' launch next acquisiton in one second

Else

Put #1, , "led pattern 254" & vbLf
' set activity led back to its default pattern so we know it stopped
Close #1
' and close communications port

End If

End Sub

Try that. Since we haven't read the rest of his code, we don't know if he
is using it anywhere else.

Come to think of it, he MUST be using it somewhere else, because nowhere in
that code does he set the state to "running". So you need to search the
code and find out where he's set it to "running" and instead set it to
"True"

But seriously, he does not need an ENUM there, he has only two states, use a
Boolean :)

Cheers


--

This email is my business email -- Please do not email me about forum
matters unless you intend to pay!

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410
+61 4 1209 1410, mailto:[email protected]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top