Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

alias declaration syntax in CR1000 program


kirving Oct 5, 2011 06:08 PM

I'm confused about the supported alias declarations syntax for CR1000 programs, and find the documentation in PDF and Windows Help sources somewhat lacking. The basic syntax to declare an alias to an array element is

alias tm(4) = hour

where tm is a declared array variable, and hour is the alias.

To declare another declaration the same structure can be used (as shown in an example program in the cr3000.pdf manual), e.g.,


alias tm(4) = hour
alias tm(5) = minute

I would like to declare multiple aliases on a line, though, but this is apparently not supported (gives a compile-time error):


alias tm(4) = hour, tm(5) = minute

but I *think* this perhaps might work:


alias tm = hour(4), minute

or perhaps:


alias tm = hour(4), minute(5)

If the alias targets are sequential for an array, this syntax can be used (taken from a working program):


Alias CS616_SM = SM1, SM2, SM3, SM4

I may be completely wrong, but it seems that these declarations would be equivalent:


alias tm(4) = hour

and


alias tm = hour(4)

Is this the case?

I'm just trying to nail down the syntax, as we have remotely deployed dataloggers with different OS levels, and it is difficult to do lab bench tests for all variations.

I think the syntax changed drastically at some point (maybe OS 19? -- or maybe that was with the units declarations...) to the extent that programs valid under an older OS level failed to compile under an upgraded OS.


jra Oct 6, 2011 03:16 PM

The safest thing to do, for backward compatibility, is declare each alias on its own line like this:

Public Array(7)

Alias Array(1) = FrontRoom
Alias Array(2) = BedRoom
Alias Array(3) = GreatRoom1
Alias Array(4) = GreatRoom2
Alias Array(5) = GreatRoom3
Alias Array(6) = GreatRoom4
Alias Array(7) = Laundry

In OS19 the ability to declare multiple aliases on the same line was implemented like this:

Public Array(7)

Alias Array = FrontRoom, BedRoom, GreatRoom(4), Laundry
'results in:
' Array(1) = FrontRoom
' Array(2) = BedRoom
' Array(3) = GreatRoom(1)
' Array(4) = GreatRoom(2)
' Array(5) = GreatRoom(3)
' Array(6) = GreatRoom(4)
' Array(7) = Laundry

One other thing to be aware of is not using keywords as an alias. See table 33 in the CR1000 manual for a list of Predefined Constants and Reserved Words. Once in a while one of those can get you, i.e. using "day" as an alias when it is reserved.

Let us know if that helps.
Janet


kirving Oct 6, 2011 05:04 PM


Public Array(7)

Alias Array = FrontRoom, BedRoom, GreatRoom(4), Laundry
'results in:
' Array(1) = FrontRoom
' Array(2) = BedRoom
' Array(3) = GreatRoom(1)
' Array(4) = GreatRoom(2)
' Array(5) = GreatRoom(3)
' Array(6) = GreatRoom(4)
' Array(7) = Laundry

Sorry, still confused about this syntax. Are you saying that
GreatRoom is an array? Or an alias to an array? I had thought the result of the above would be equivalent to:


'alias Array(1) = FrontRoom
'alias Array(2) = BedRoom
'alias Array(4) = GreatRoom
'alias Array(5) = Laundry

But your explanation certainly does make more sense.


kirving Oct 6, 2011 05:15 PM

Ok, I set some aliases to the 9-element array from realtime() and can see that the results are as you show. Thanks for clearing this up for me!


kirving Oct 6, 2011 05:32 PM

This form compiles and runs under OS22, but presumably would not be portable to earlier revisions:

public tm(9)
alias tm(4) = hour, minute

Hour ends up aliased to tm(4) and minute to tm(5). This is probably using the multiple-aliases-on-a-line form added at OS19, but with the with the source variable starting at tm(4) instead of tm(1), and so would not compile under earlier OS revisions.

It would be very useful if the CRBasic Editor could be set to compile to or for a specified OS level, but I don't see that in the interface.


kokihualpa Apr 15, 2020 02:45 PM

Excuseme

I use Alias and declare each Alias per line. But In the program I want to do operations with the Alias but they dont have effect. Why?.

For example

Public Array(7)

Alias Array(1) = FrontRoom
Alias Array(2) = BedRoom
Alias Array(3) = GreatRoom1
Alias Array(4) = GreatRoom2
Alias Array(5) = GreatRoom3
Alias Array(6) = GreatRoom4
Alias Array(7) = Laundry

Beginprog

Array(1)=999

FrontRoom=FrontRoom*0.75

And when the program run that doesnt have effect.


nsw Apr 20, 2020 09:46 AM

Hi,

I tried your code extract on a CR1000X just now and it works fine. In the Public table, the variable FrontRoom has a value of 749.25 in it.

Log in or register to post/reply in the forum.