I'm working with a Tcl script and want to do two separate things if an if statement is true. Code is below:
if { $Start_day >= 1 && $Start_day <= 15} {set Meteo_file "edas.$Start_month2$Start_year.001"
set Meteo_file_back "edas.$Start_month2_back$Start_year_back.002"}
However, I error out and get this:
wrong # args: should be "set varName ?newValue?"
while executing
"set Meteo_file "edas.$Start_month2$Start_year.001"
set Meteo_file_back "edas.$Start_month2_back$Start_year_back.002""
Is there any way (syntax) to have an if statement do two separate things when it comes true?
It would be more readable IMO to have them on separate lines:
if {$Start_day >= 1 && $Start_day <= 15} {
set Meteo_file "edas.$Start_month2$Start_year.001"
set Meteo_file_back "edas.$Start_month2_back$Start_year_back.002"
}
And I cannot get your error... The above works fine for me.
As a side note, could it be that you're using both set on the same line? I don't see why there'd be a lot of whitespaces to the right of the first set otherwise.
Related
I have a working If else statment as below
ifelse({location_building_code} ='XC',ifelse({shift_pattern_code}='AAAA','AM-FT',{shift_pattern_code}),
ifelse({location_building_code} ='XA',ifelse({shift_pattern_code}='AAAA','AM-FT', {shift_pattern_code}),{shift_pattern_code}))
however i would like to add in additional If statement.
ifelse({location_building_code} ='XC', ifelse({badge_type} = 'Green', ifelse({shift_pattern_code}='AAAA','AM-FT',{shift_pattern_code}),
ifelse({location_building_code} ='XA', ifelse({badge_type} = 'Green', ifelse({shift_pattern_code}='AAAA','AM-FT', {shift_pattern_code}),{shift_pattern_code}),{shift_pattern_code})))
However I get syntax error I would like to expand to inlucude more nested if's
expected outcome to be able to have IF else Building = x the badge type x then define Shift codes by actual meaning rather than code as long as multiple conditions are met.
I got this little piece of code: {if $smarty.get.id_cms == 1 }
I would like iterate on every cms page with the id 1 to 20. Rather than creating 19 more if statements.
I tried to use "," and ";" without any success.
Using "," or ";" breaks the page into whiteness. Indicating that my 'guessed' syntax is wrong.
I must've been under the influence.
Of course it was as easy as
{if in_array($smarty.get.id_cms, array (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20))}
Try :
{if $smarty.get.id_cms => 1 && $smarty.get.id_cms <= 1}
Regards
I'm trying to use autohotkey to gather a chuck of data from a website and then click a certain spot on the website depending on what the text is. I'm able to get it to actually pick up the value but when it comes to the if statement it won't seem to process and yields no error message. Here is a quick sample of my code, there is about 20 if statement values so for brevity sake I've only included a few of the values.
GuessesLeft = 20
Errorcount = 0
;triple click and copy text making a variable out of the clipboard
;while (GuessesLeft!=0) part of future while loop
;{ part of future while loop
click 927,349
click 927,349
click 927,349
Send ^c
GetValue = %Clipboard%
if ( GetValue = "Frontal boss")
{
click 955,485
Guessesleft -= 1
}
else if ( GetValue = "Supraorbital Ridge")
{
click 955,571
Guessesleft -= 1
}
;....ETC
else
{
Errorcount += 1
}
;} part of future while loop
Any tips on what I might be doing wrong. Ideally I'd use a case statement but AHK doesn't seem to have them.
Wait a second -- you are triple clicking to highlight a full paragraph and copying that to the clipboard and checking to see if the entirety of the copied portion is the words in the if statement, right? And your words in the copied portion have quotes around them? Probably you will have to trim off any trailing spaces and/or returns:
GetValue = % Trim(Clipboard)
If that doesn't work, you may even have to shorten the length of the copied text by an arbitrary character or two:
GetValue = % SubStr(Clipboard, 1, (StrLen(Clipboard)-2))
Now, if I am wrong, and what you are really looking for is the words from the if statement wherever they may be in a longer paragraph -- and they are not surrounded by quotes, then you will want something like:
IfInString, Clipboard, Frontal boss
Or, if the quotes ARE there,
IfInString, Clipboard, "Frontal boss"
Hth,
I am using Stata 14. I have US states and corresponding regions as integer.
I want create a string variable that represents the region for each observation.
Currently my code is
gen div_name = "A"
replace div_name = "New England" if div_no == 1
replace div_name = "Middle Atlantic" if div_no == 2
.
.
replace div_name = "Pacific" if div_no == 9
..so it is a really long code.
I was wondering if there is a shorter way to do this where I can automate assigning values rather than manually hard coding them.
You can define value labels in one line with label define and then use decode to create the string variable. See the help for those commands.
If the correspondence was defined in a separate dataset you could use merge. See e.g. this FAQ
There can't be a short-cut here other than typing all the names at some point or exploiting the fact that someone else typed them earlier into a file.
With nine or so labels, typing them yourself is quickest.
Note that you type one statement more than you need, even doing it the long way, as you could start
gen div_name = "New England" if div_no == 1
So I've been trying to figure out what is wrong with my if-condition, but I am getting nowhere. I am still new to R, so maybe I am not understanding some very basic concept here?
I have a dataframe (dc) to which I appended a column with logical "FALSE". Now I want to change each FALSE into a TRUE based on the values in two columns of dc (dc$Probe and dc$Resp) that I specified using regexpr().
What it does so far is that, for both if-conditions, it changes each FALSE into TRUE regardless of the values in column 5 of dc. When I run the if-conditions seperately, I can see that they seem to be working fine on the OR-part of the condition, meaning the code only generates TRUE when the strings in dc$Probe match one of the strings specified in the OR-part. However, the AND-part seems to be ignored? Thus, when I run the complete code, I get a column with only TRUE, which is not what I want.
Edit: I should get a TRUE only if the string in Probe ends in a certain pattern (as specified in either of the two if conditions I wrote) and if the corresponding value in Resp is a "100" for the patterns specified in my first condition or a "200" for the patterns specified in my second condition. Thus, for strings ending in (sg|s|w1|w3|s1|s2), Resp must be "100" to get a TRUE and for strings ending in (\d\dg|\d\d), Resp must be "200" to get a TRUE. All other cases should be FALSE. For example, if a string ends in s1 and the corresponding value in Resp is 200, the code should return FALSE.
Edit: Some example data:
>dc<-data.frame(Subject=rep("SN",6), item.c=(1:6), Stim=c("XYZc02s03","XYZc01s30","XYZc02s29", "XYZc01s38", "XYZc02s11", "XYZc06w21"), Probe=c("XYzf02s03","XYZf01s30g","XYZf02s29w1","XYZf01s38sg","XYZf02s11s","XYZv06w21s1"), Resp=c(200, 100, 100, 100, 100, 200))
This is my code:
>dc$Resp<-as.character(dc$Resp) #column 5 in dc
dc$Probe<-as.character(dc$Probe)
dc$correct_response <- FALSE
for (i in 1:nrow(dc)) {
if (regexpr("^.*sg$", dc$Probe[i])==1 || regexpr("^.*s$", dc$Probe[i])==1 || regexpr("^.*w1$", dc$Probe[i])==1 || regexpr("^.*w3$", dc$Probe[i])==1 || regexpr("^.*s1$", dc$Probe[i])==1 || regexpr("^.*s2$", dc$Probe[i])==1 && dc[i,5]=="100") {(dc$correct_response[i]<- TRUE)}
if (regexpr("^.*\\d\\dg$", dc$Probe[i])==1 || regexpr("^.*\\d\\d$", dc$Probe[i])==1 && dc[i,5]=="200") {(dc$correct_response[i]<- TRUE)}
}
Is there something wrong with the regular expressions I am using? I checked them with glob2rx() and it seems like they are ok...Is my use of "OR" (||) or/and "AND" (&&) incorrect? How do I implement the AND-part properly? I have also tried the following code for the AND-part, but it didn't change anything:
regexpr("200", dc$Resp[i])==1
I read the R-help on regular expressions and control flow, but I still don't see what I am doing wrong. Consulting other webpages on logical expressions did not help me either.
Please help!
Im wondering if it can all be reduced to the following:
dc<- read.table(header=T,text="Subject item.c Stim Probe Resp
SN 1 XYZc02s03 XYzf02s03 200
SN 2 XYZc01s30 XYZf01s30g 100
SN 3 XYZc02s29 XYZf02s29w1 100
SN 4 XYZc01s38 XYZf01s38sg 100
SN 5 XYZc02s11 XYZf02s11s 100
SN 6 XYZc06w21 XYZv06w21s1 200")
cond1<-regexpr("^.*(sg|s|w1|w3|s1|s2)$", dc$Probe)==1 & dc$Resp==100
cond2<-regexpr("^.*(\\d\\dg|\\d\\d)$", dc$Probe)==1 & dc$Resp==200
dc$correct_response<-cond1|cond2
For one thing, you are missing a logical operator between the 2nd and 3rd clauses of your first if statement.