Static Variable and Data Grid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Static Variable and Data Grid
Hi,
Does anyone know how to create a static variable?
I want to set a variable to a specific number for the first run but also increment the value on every run.
let's say. I have a variable called tCount, and it is 0 at the beginning. At the end of my code, I write "put tCount + 1 into tCount". Thus, it will be 1. However, it shouldn't be zero again when I run the code again. It should be 2 at the second run.
I hope I am clear,
Regards,
ARAS
Does anyone know how to create a static variable?
I want to set a variable to a specific number for the first run but also increment the value on every run.
let's say. I have a variable called tCount, and it is 0 at the beginning. At the end of my code, I write "put tCount + 1 into tCount". Thus, it will be 1. However, it shouldn't be zero again when I run the code again. It should be 2 at the second run.
I hope I am clear,
Regards,
ARAS
Last edited by ARAS on Sun Dec 08, 2013 9:23 pm, edited 1 time in total.
Re: Static Variable
Hi Aras,
make it a global variable!
Important: Remember to declare it in every SCRIPT you use it!
Example In a script, so it will be available to all its handlers and functions:
In a single handler script like "mouseup"
You get the picture
Best
Klaus
make it a global variable!
Important: Remember to declare it in every SCRIPT you use it!
Example In a script, so it will be available to all its handlers and functions:
Code: Select all
global my_static_var
on preopenstack
put 0 into my_static_var
### more stuff...
end preopenstack
on openstack
dowhatever...
end openstack
on opencard
add 1 to my_static_var
end opencard
command myhandler
add 25 to my_static_var
end myhandler
etc...
...
Code: Select all
on mouseup
global my_static_var
answer my_static_var
end mouseup

Best
Klaus
Re: Static Variable
Thanks Klaus,
It works but not like I thought.
I have a datagrid in my project. I want to enter datas into the datagrid. Whenever I try to enter a new entry. It replaces with the old one. I want the second entry or the former entry to go to the next row.
This is my code.
Thanks,
ARAS
It works but not like I thought.
I have a datagrid in my project. I want to enter datas into the datagrid. Whenever I try to enter a new entry. It replaces with the old one. I want the second entry or the former entry to go to the next row.
This is my code.
Code: Select all
on mouseUp
global tCount
--answer tCount
put field "fName" into theDataA[ tCount ][ "Name" ]
put field "fSurname" into theDataA[ tCount ][ "Surname" ]
if the hilite of btn "rMale" then
put "Male" into theDataA[ tCount ][ "Sex" ]
--put the label of button "rMale" into theDataA[ 1 ][ "Sex" ]
else if the hilite of btn "rFemale" then
put "Female" into theDataA[ tCount ][ "Sex" ]
else
--answer "You have to choose the sex of the person you are registering!" with "Okay"
end if
put the label of button "cDay" into sD
put the label of button "cMonth" into sM
put the label of button "cYear" into sY
put sD & space & sM & space & sY into theDataA[ tCount ][ "Birth Date" ]
set the dgData of group "dgDisplay" to theDataA
answer "Data entry has been succesfuly done." with "Okay"
put tCount + 1 into tCount
//CLEAR SECTION
put empty into field "fName"
put empty into field "fSurname"
--set the hilite of btn "rMale" to false
--set the hilite of btn "rFemale" to false
set the hilitedbuttonname of group "gSex" to false
set the label of btn "cDay" to line 1 of the text of btn "cDay"
set the label of btn "cMonth" to line 1 of the text of btn "cMonth"
set the label of btn "cYear" to line 1 of the text of btn "cYear"
end mouseUp
ARAS
Re: Static Variable and Data Grid
Hi Aras,
well, this line:
...
set the dgData of group "dgDisplay" to theDataA
...
will always REPLACE the complete content of the datagrid!
You want to append your data to the existing data, right?
In that case you need to do this, this is how datagrids work,
and that eliminates the need of your global variable tCount completely
Best
Klaus
well, this line:
...
set the dgData of group "dgDisplay" to theDataA
...
will always REPLACE the complete content of the datagrid!
You want to append your data to the existing data, right?
In that case you need to do this, this is how datagrids work,
and that eliminates the need of your global variable tCount completely

Code: Select all
---
## NO index in the array that you want to append!
## The Datagrid will take care of this itself!
put field "fName" into theDataA["Name" ]
put field "fSurname" into theDataA["Surname" ]
if the hilite of btn "rMale" then
put "Male" into theDataA["Sex" ]
else if the hilite of btn "rFemale" then
put "Female" into theDataA[ "Sex" ]
else
--answer "You have to choose the sex of the person you are registering!" with "Okay"
end if
put the label of button "cDay" into sD
put the label of button "cMonth" into sM
put the label of button "cYear" into sY
put sD & space & sM & space & sY into theDataA[ "Birth Date" ]
## Let the datagrid do the rest:
dispatch "addData" to group "dgDisplay" with theDataA
...
Klaus
Re: Static Variable and Data Grid
Thanks Klaus,
You are the hero of the day!
Could you explain what exactly dispatch does?
Best wishes,
ARAS
You are the hero of the day!

Could you explain what exactly dispatch does?
Best wishes,
ARAS
Re: Static Variable and Data Grid
Oh I've just realized that when I delete all the data in a row and enter a new entry. I continues from the following row not from the empty row. Do you have any solution in mind?
ARAS
ARAS
Re: Static Variable and Data Grid
Hi Aras,
Then use your GLOBAL tCount, still no INDEX in the array to add and replace "dispatch..." with this line:
...
set the dgDataOfLine[tCount] of group "dgDisplay" to theDataA
...
I hope this is what you are after
Best
Klaus
I know, I know...ARAS wrote:You are the hero of the day!![]()

I think i cannot explain this better than the dictionaryARAS wrote:Could you explain what exactly dispatch does?

Ah, sorry, I did not know that you want to replace the LINE tCount in your datagrid!ARAS wrote:Oh I've just realized that when I delete all the data in a row and enter a new entry. I continues from the following row not from the empty row. Do you have any solution in mind?
Then use your GLOBAL tCount, still no INDEX in the array to add and replace "dispatch..." with this line:
...
set the dgDataOfLine[tCount] of group "dgDisplay" to theDataA
...
I hope this is what you are after

Best
Klaus
Re: Static Variable and Data Grid
Hi Klaus,
If I use global variable method, it will increment the value in every run.
Let's say. We have 15 rows which have data in it, and I delete all the data in row 9. Thus I will have 14 in total. However, my global variable will be 16(instead of 15), so it will leave a blank row. Row number 15 will be empty.
I wish I knew a code that finds the empty rows and put the data there.
Anyway, the code you have given me before without a global variable works fine for me. I was just trying to learn about data grid.
Thanks again,
ARAS
If I use global variable method, it will increment the value in every run.
Let's say. We have 15 rows which have data in it, and I delete all the data in row 9. Thus I will have 14 in total. However, my global variable will be 16(instead of 15), so it will leave a blank row. Row number 15 will be empty.
I wish I knew a code that finds the empty rows and put the data there.
Anyway, the code you have given me before without a global variable works fine for me. I was just trying to learn about data grid.
Thanks again,
ARAS