Increment through dashed lines in AppleScript? - numbers

I'm trying to check the values for an accurate count but I'm having issues with the stepping process. Given the extraction of:
1-1
2-1
3-1
4-1
5-1
6-1
7-1
7-2
8-1
9-1
9-2
9-3
9-4
10-1
11-1
12-2 ## intentionally left out 12-1 to throw error
13-1
how can I properly increment through the list and flag if one is missing. When I run my script it runs through 7-2 but when it comes to 8-1 it fails with:
A child marker seems to be missing.
the code:
tell application "BBEdit"
activate
set parentCount to 1
set childCount to 1
set theDoc to text document 1
select insertion point before first character of theDoc
set searchOpt to {search mode:grep, wrap around:false}
repeat
set theNumbers to find "^(\\d{1,4})-(\\d{1,4})" searching in text 1 of theDoc options searchOpt with selecting match
if not found of theNumbers then exit repeat
set parentNum to (grep substitution of "\\1") as number
set childNum to (grep substitution of "\\2") as number
if parentNum is equal to parentCount and childNum is equal to childCount then
set parentCount to parentCount + 1
else if parentNum is equal to parentCount and (childNum + 1) is equal to childCount then
set parentCount to parentCount + 1
set childCount to 1
else
display dialog "missing marker"
end if
end repeat
display dialog "completed check"
end tell
In AppleScript how can I properly increment through a sequence of numbers?

In your conditional statements, you use the same condition if parentNum is equal to parentCount, the second conditional statement doesn't work , because the script increases the parentCount in these two conditional statements, and your script never increases the childCount.
Use this script:
tell application "BBEdit"
activate
set parentCount to 0
set childCount to 1
set theDoc to text document 1
select insertion point before first character of theDoc
set searchOpt to {search mode:grep, wrap around:false}
repeat
set theNumbers to find "^(\\d{1,4})-(\\d{1,4})" searching in text 1 of theDoc options searchOpt with selecting match
if not found of theNumbers then exit repeat
set parentNum to (grep substitution of "\\1") as number
set childNum to (grep substitution of "\\2") as number
if parentNum = (parentCount + 1) and childNum = 1 then -- if the parentNum increase of 1, the childNum must be 1
set parentCount to parentCount + 1
set childCount to 1 -- so, reset the childCount to 1
else if parentNum = parentCount and childNum = (childCount + 1) then
set childCount to childNum
else
display dialog "missing marker"
set parentCount to parentNum -- start at this value for the next sequence
set childCount to childNum -- start at this value for the next sequence
end if
end repeat
display dialog "completed check"
end tell

Related

How to create a sequential counter in NetLogo 6.2?

I would like to know if there is any way to implement a sequential counter without using a list by intervals. I'm trying to implement the following: at the end of each tick is counting the population size (NFinal). And then, we would check the constancy of the population, through a subtraction (the logical test would be the result of this subtraction is equal to zero during 3 consecutive ticks?).
For example:
NFinal of tick 0 - NFinal of tick 1 = 0
NFinal of tick 1 - NFinal of tick 2 = 0
NFinal of tick 2 - NFinal of tick 3 = 0
If this is the scenario (with 3 sequential values ​​equal to zero), the simulation will stop.
However, if it is in the scenario:
NFinal of tick 0 - NFinal of tick 1 = 0
NFinal of tick 1 - NFinal of tick 2 = 0
NFinal of tick 2 - NFinal of tick 3 = 2
The simulation does not stop (since it did not have 3 zero values ​​in sequence) and therefore would reset the counter to continue the simulation.
However what I managed to implement was by intervals using list. I don't know if it's the best way. Well, every time I use the list my model is getting slower. Is there a simpler way to implement this?
Thanks in advance!
Attempt below:
globals [ StabilityList ConstanceInterval ]
to go
if ConstanceInterval = 0 [ stop ]
end
to StabilityCheckerProc
set StabilityList lput 1 StabilityList ;; 1 = NFinal
let i 3 ;;
if length StabilityList >= i
[
let t1 last StabilityList
let start ( length StabilityList - i )
let t0 item start StabilityList
set ConstanceInterval abs ( t1 - t0 )
]
set StabilityList get-last i StabilityList
end
to-report get-last [ num lst ]
let b length lst
let a b - num
report sublist lst ( ifelse-value ( a < 0 ) [ 0 ] [ a ] ) b
end
You could use a counter to track the number of occurrences in a row, such that if your condition is satisfied you increase the counter, and if it is not you reset the counter. For example:
globals [ zero-tracker ]
to setup
ca
reset-ticks
end
to go
let variable-placeholder random 5
ifelse variable-placeholder = 0 [
; If a zero is recorded (eg, the result of your subtraction operation,
; increase the zero-tracker by one
set zero-tracker zero-tracker + 1
] [
; If anything BUT a zero is recorded, reset the zero-tracker
set zero-tracker 0
]
tick
if zero-tracker = 3 [
stop
]
end
Luke's answer is the answer.
But, if for any reason you did have a problem that needed to look at the last X things, and a counter was not going to work, you could use a list, but keep it at length X.
;; in setup, initialize the list with 'memory-size' items
set memory map [ -> 0] range 0 memory-size
;; in go, add a new memory to the list, and drop an old memory
set memory but-first lput value memory
;; then do what you must to examine the memories
< that code here >
Still slower than using a counter, but probably faster than accumulating and taking sections from an ever-growing list of values.
If you do need to maintain an ever-growing list of values, you might still maintain this smaller list.
Finally, even when using the ever-growing list of values, it would be fewer operations to take the sublist off the front of the list:
;; add new memory to front of list
set memory fput value memory
;; get last three memories from front of list
let last-three sublist memory 0 3 ;; no math or length needed
As always, test any assertion that something might be faster.

Updating counter of picked objects from a list

I would like to update the counter of an element in a list, every time it is picked from turtles.
To do that, I am setting the item I am interested in and adding 1 to it (counter).
I created a global variable called it_cnt and I set it equal to 0 in the hatch where I create the objects (in order to know which turtle owns that item initially).
This is where I initialise the counter:
ask buyers [
hatch-obj random 5 [
set it_cnt 0
]
]
Please see below the list that I am considering
let picked_obj (list item 0 obj_in_shop_bag item 1 obj_in_shop_bag item 2 obj_in_shop_bag item 3 obj_in_shop_bag)
I am updating the counter as follows
let new_id_cnt item 3 picked_obj + 1
to add 1 in case the picked_obj is chosen by a buyer. However, when I print the list to see if it works
print (word " ; " item 0 obj_in_shop_bag " ; " item 1 obj_in_shop_bag " ; " item 2 obj_in_shop_bag " ; " item 3 new_id_cnt)
if the item is picked twice from different buyers in different ticks (ticks are item 0 in the list), the only value that I get is 1, as it was reset.
I would greatly appreciate if you could tell me how to fix the counter in order to let it work correctly.
Many thanks.
This is not an answer but is too long for comments. I can't make sense of the question.
You have set it_cnt 0 in the hatch but you say it's a global variable. So if you have 10 buyers, each of them hatches 0 to 4 obj and that single copy of the global variable is set to the value 0 by every one of the potentially 40 objs. Why? Do you mean that it's a turtle variable that is owned by obj?
Where you are updating the counter, you have suddenly switched the name from it_cnt to new_id_cnt. That won't update anything, there is no connection shown between the values of these two variables.

Suppress a Text Object Based on Field Value in Object

I have a Text Object that contains a text string followed by a database field Max Weight {table.field}
I want to suppress all of the Text Object whenever {table.field} = 0.
I tried the following formula under Format Text > Common > Suppress
if {table.field} = 0 then true else false
What I get is the field value within the text object either on or off while the text is always suppressed. What do I need to do to make this work? Thanks.
You can try 2 different solutions:
1) Keeping your Max Weight label, create a new Formula in the 'Formula Fields' then enter this code:
if {table.field} = 0 then '' else ToText({table.field})
2) Supressing all text, you have to create a new Formula too, but type this:
if {table.field} = 0 then '' else 'Max Weight ' + ToText({table.field})
This second way, you will create a label that will only appears when your conditions happens, and you must replace the old TextObject with this new Formula. This will cause a blank area, because no text and no weight will show, but it looks like exactly what you need.
I just tested here and it's working. Note that both 'spaces' are in the document. Attached is an image that may help you find the formulas section. Hope you can use it.

How to change background color for each two rows in SSRS in a group

How can I write the expression in order to change background color for each two rows in SSRS?
I need something like that:
I tried expression
=IIF(Fields!Type.Value="2016 Submitted" , "LightBlue",
IIF(Fields!Type.Value="2015 Submitted" , "LightBlue",
Nothing))
But because some months dont have values it looks like this:
If I try this expression I get below:
=IIF(RunningValue(Fields!Count.Value, CountDistinct, Nothing) MOD 2 = 1, "White", "PaleTurquoise")
Dance-Henry I tried your code
=IIF(RowNumber(Nothing) Mod 4 = 1 or RowNumber(Nothing) Mod 4 = 2, "Aqua","White")
and this is what i got:
You can select the row in design pane and press F4 to setup property BackgroundColor as =IIF(RowNumber(Nothing) Mod 4 = 1 or RowNumber(Nothing) Mod 4 = 2, "Aqua","White")
Captures are attached. Do it accordingly.
RESULT is something like this
After going thru the link https://blogs.msdn.microsoft.com/chrishays/2004/08/30/green-bar-matrix/
Tested and it works well for the Green Bar Effect for Matrix. I will show it step by step here as for later reference.
Step 1: Create the Matrix and add one more column under the innermost row grouping in your matrix. (ColorNameTextbox here)
Step 2: Select the textbox of ColorNameTextbox and press F4 to setup BackgroundColor property as =Value shown below.
Step 3: Select the textbox of Matrix cell and press F4 to setup BackgroundColor property as =ReportItems!ColorNameTextbox.Value shown below.
Step 4: Drag the inner grouping header (ColorNameTextbox) to be as narrow as possible.
Step 5: Preview Pane to check the result.
If you could add a hidden color_group column and populate it with a new number at each point you want to change the color (in your case 1,1,2,2,3,3,4,4) then you could use something like the following (which works for varying size groups):
IIF(RunningValue(Fields!color_group.Value, CountDistinct, Nothing) MOD 2 = 1, "White", "PaleTurquoise")
I had a similar problem where I could not come up with alternating rows because my data has Column Groups that were the RowNumber(Nothing) method to fail. Learning from all the other posts here this is how I resolved it in steps.
I added the following code into the report properties, that provides a function to get the row number, each time it is called. The function increments the row count each time it is called. >>Right click space around the report >> Properties >> Code. Alternatively go to Code Properties Window, when the report is selected.
Add the following lines:
Public Row_Sum As Decimal = 0
Public Function Lookup_Sum( ) As integer
Row_Sum = Row_Sum + 1
Return Row_Sum
End Function
I added a new column at the beginning of the rows called No. that would calculate and show the row number.Right click the first column >>Insert Column>>Inside Group-Left.
On the expression for the new report add this line of code. Also take a note of the name of the TextBox that will have the No. Value. It will be needed in the next step. In my case the TextBox is called TextBox6 (Properties Window). >>Right Click Cell>>Expression.
Add the code:
=Code.Lookup_Sum()
I highlighted the entire row and went to the Background property and added the following expression to compute the row number.
Add the code(TextBox6 is the name Textbox name noted above):
=IIF(VAL(ReportItems!Textbox6.Value) MOD 2, "LIGHTBLUE", "WHITE")

Subtracting element of ith position from element at (i + 1)th position of any list in netlogo

I want to create a list of count values of some variable (tot-turtles) increasing with each tick. I tried the below code but all time list is having single element of length 1. neither i is getting incremented. please correct me.
set tot-turtles count turtles
to go
let mylist [ ]
set mylist lput tot-turtles mylist ; show mylist
set i 1
foreach mylist [ ; print ? ;show i
set x ? - i ; print x
set i (i + 1) ;show i
]
end
I want to subtract elements of list in the following fashion where the length of list depends on the number of simulation run or till simulation ends, then
i need subtraction of element as element at (i + 1)th - element at ith position till the end of the list.
In the above code i is 1 then increments by 1 ie 2 and then continue to 1 2 1 2 1 2. mylsit always shows single element. Confused with "?" , it gives element of current position if i am not wrong, but how we know the current position?
Please help me out of these doubts and code. thanks a lot.
Thank you sir, yes i was doing mistake with local and global variable i checkd it later. and the thing i wanted is as below.
to setup
set mylist [ 0]
set item-difference 0
end
to go
set tot-turtles count tutles set
mylist lput tot-turtles mylist
let _n (length mylist)
set item-difference (( item ( _n - 1 ) mylist - item ( _n - 2 ) mylist )
end
I hope you got Allan sir.
It's a bit difficult to tell what you are after, but it seems you are using a local variable when you want a global variable. See if this offers some help:
globals [mylist]
to setup
ca
set mylist []
crt 10
end
to go
crt 1
set mylist lput (count turtles) mylist ; show mylist
end
to test
let _n (length mylist)
(foreach mylist n-values _n [? + 1] [
print ?1 - ?2
])
end