Cicode problem

Hello.
I have a simple problem, I searched in help files and it didn't answer my question!

The problem is: I want a function to get a my string as an input (the input string is the name of a local variable) and return my local variable as a tag. just this!

for example:
I have several local variables like this:
BIT_1, BIT_2, BIT_3, ...

I want to set all of them to 1 by pressing a button. The code may be like this:


FOR I=1 TO 30 DO
TempVar = someFunction("BIT_" + intToStr(I));
TempVar = 1;
END


The problem is : "someFunction".
I have lots of nodes in my project that have the same parameters. So I create some super genie and pass the ID number of every instance to it. Now I need to access my local variable with this ID number.

I'm new in my job, and I'm trying to understand it.
Hope you can help me.
Thanks a lot.

 
Instead of using seperate local variables
Use an Array "Bits[xx]", declare as global.
Ok if is only temporay but problem if needed to be retentive.

OR use whole word

iBit = 1;
For i = 0 TO 30 DO
IF ((Word_1 BITAND iBit) = iBit) THEN;
Bit_1 = 1;
ELSE
Bit_1 = 0;
END
iBit = iBit * 2;
END

Or to set bit in word
Word_1 = Word_1 BitOr iBit;

Put in function and pass word and retrieve bit value.

Just random thoughts!
 
The function you are looking for is write_var (or writevar) You pass the name of a tag as a string ("BIT_" + strIndex)and it will return the value. This will only work however if the function is not used to directly display the data. On a super genie you probably should use ***_Tag or one of the other ***_ functions

(it wont let me write the first part of the function name - *** should be *=a *=s *=s)
 
Alternatively, you could make your local variables be tags of a disk IO device. This means you could use the TagWrite function which accepts the name of the tag as a string.
 
FUNCTION
SetVarToOne(STRING Variable)
INT I
STRING sTtemp
FOR I=1TO30DO
sTemp = Variable + IntToStr(I)
TagWrite(sTemp,"1")
//Display current ariable at Prompt field
Prompt(sTemp)

// Show a popup with the current variable and its value
Message(sTemp,inttostr(tagread(sTemp)),0)

END
END

In the button touch property

SetVarToOne("Bit_")
 

Similar Topics

I have an array with more than 500 tags and I need to get values from each tag. The problem is that using the TAGREAD function, the program runs...
3
Replies
1,047
Views
Hey People! I got an problem with the slider property, i use the scale function to show an group of images to zoom in, after this zoomin i use...
0
Replies
2,956
Views
Hey Guys, I am thinking of having the alarm timer in cicode instead of in PLC. The alarm would be generated to citect after say 30 secs. Any...
12
Replies
981
Views
full1 = "INSERT INTO table1 (`date`,`timestamp`,name,age,address,phone,email,personal_id,department,last_login) VALUES (CURRENT_DATE...
5
Replies
943
Views
Hi All, Can anyone advise me on how to determine the AN of a genie instance I writing to. I have created a genie to display a valve and some text...
0
Replies
677
Views
Top