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.

multiple ConstTable blocks?


kirving Aug 9, 2009 07:20 PM

Can more than one ConstTable block be defined in a CR1000 program?

We have constants in several categories, and I'd like to make some changable w/o having to edit the program. It would be convenient to keep both types of constants together, grouped by context.

Thanks, Ken

* Last updated by: kirving on 8/9/2009 @ 1:21 PM *


Sam Aug 10, 2009 12:50 AM

Ken,

You'll notice that the ConstTable instruction does not allow for the specification of a table name, unlike the DataTable instruction. Therefore, you are limited to a single ConstTable/EndConstTable instruction per program. I.e., currently there is not a way to address multiple ConstTables.

I have used another, more convoluted, way of changing constants using custom menus. With this you could have separate custom submenus for the categories of constants. It uses Include, DisplayMenu (and related), FileWrite (and related), and FileManage.

1) Create a file containing your constant declarations, e.g. 'constants.cr1'. This file might look like:

Const cA = 1
Const cB = 1
Const cC = 1

(I've never had good luck doing this with NotePad, so I've always written and run a program that generates the initial file.)

2) Create your main program so that it uses the command

Include "CPU:constants.cr1"

near the top of the file

3) Declare in your main program, variables that shadow the constants. The declaration might look like:

Public vA as Long = cA
Public vB as Long = cB
Public vC as Long = cC
Public ApplySettings as string = "-"

4) In your program, also create a custom menu used to edit these variables. It might look like:

DisplayMenu("",-1)

SubMenu("Config1")
MenuItem("A",vA)
EndSubMenu

SubMenu("Config2")
MenuItem("B",vB)
MenuItem("B",vB)
EndSubMenu

MenuItem("Apply",ApplySettings)
MenuPick(Cancel, -, Yes)

EndMenu


5) Write a SlowSequence routine that checks the status of ApplySettings.

a) If ApplySettings = YES, then overwrite CPU:constants.cr1 with the new contants and restart the program. For example use FileHandle, FileWrite, and FileClose to write out a string like:

"Const cA=" + vA + CHR(13) + CHR(10) + "Const cB=" + vB + CHR(13) + CHR(10) + "Const cC=" + vC + CHR(13) + CHR(10)


Then

'Restart Program
ThisFileName = Status.ProgName(1,1)
FileManage (ThisFileName,6)

and reset ApplySettings = "-"

b) If ApplySettings = CANCEL, then set everything back like it was

ApplySettings = "-"
vA = cA
vB = cB
vC = cC

Sam


kirving Aug 10, 2009 12:57 AM

Yikes! I've just become aware of ConstTable, and can deal with having only one instance available. The alternate scheme you describe seems impressive, but I'd rather not do anything quite so complicated (looking).

It's nice to see the flexibility of the system as demonstrated by this, however.

Thanks!

Ken

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