Suppose I have a variable $$Range which is inputted as either a range (e.g. 1..2).
Can I write a boolean which is true if $$Number is in the range $$Range, and false otherwise?
E.g. $$Number is 1 and $$Range is 1..2 should return True, and $$Number is 4 and $$Range is 1..2 should return False.
For convenience Set Variable [$$range2; Substitute($$Range;["..";" "];["...";" "]) ]
Then, the required boolean is:
RightWords($$range2;1) <= $$Number & $$Number < RightWords($$range2;2)
Related
I understand the whole code and
I just want to know why there has to be a -1 at the end of the range function.
I've been checking it out with pythontutor but I can't make it out.
#Given 2 strings, a and b, return the number of the positions where they
#contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3,
#since the "xx", "aa", and "az" substrings appear in the same place in
#both strings.
def string_match(a, b):
shorter = min(len(a), len(b))
count = 0
for i in range(shorter -1): #<<<<<<<<< This is -1 I don't understand.
a_sub = a[i:i+2]
b_sub = b[i:i+2]
if a_sub == b_sub:
count = count + 1
return count
string_match('xxcaazz', 'xxbaaz')
string_match('abc', 'abc')
string_match('abc', 'axc')
I expect to understand why there has to be a -1 at the end of the range function. I will appreciate your help and explanation!
The value indices of the for loop are counted since 0 so the final value actually would be the (size -1)
if ((status & 0x3F) == 1 ){ }..
the status is variable in swift language.
what is mean about this condition, & mean and (status & 0x3F) value return
& is the bitwise AND operator. It compares the bits of the two operands and sets the corresponding bit to 1 if it is 1 in both operands, or to 0 if either or both are 0.
So this statement:
((status & 0x3F) == 1)
is combining status with 0b111111 (the binary equivalent of 0x3F and checking if the result is exactly 1. This will only be true if the last 6 bits of status are 0b000001.
In this if:
if( (dtc24_state[2] & 0x8) == 0x8 ) {
self.haldexABCDTC24State.text = status_str + " - UNKNOWN"
self.haldexABCDTC24State.textColor = text_color
active_or_stored_dtc = true
}
dct24_state is an array of values. The value of dct24_state[2] is combined with 0x8 or 0b1000 and checked against 0x8. This is checking if the 4th bit from the right is set. Nothing else matters. If the 4th bit from the right is set, the if is true and the code block is executed.
0x3F is 111111. So, it means this:
for each bit of yourNumber in binary system presentation use and method.
This way truncates the left part of the number. and the result compares with 1.
e.g.
7777 is 1111001100001 after executing and this number converts into
100001. So the result is false.
But for 7745 (1111001000001) the result is 1. The result is true.
The rule for 'and' function: 0 & 0 = 0 ; 0 & 1 = 0; 1 & 0 = 1; 1 & 1 = 1.
I have a question about finding and replacing all numbers in a word document.
I have numbers from 59...~600 or so, and I want to increment all of them by a fixed number. I'm not at all familiar with word macros.
You could use a macro like:
Sub Demo()
Application.ScreenUpdating = False
Const i As Long = 50
With ActiveDocument.Range
With .Find
.ClearFormatting
.Text = "<[0-9]{2,3}>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
If CLng(.Text) > 58 Then
If CLng(.Text) < 700 Then .Text = CLng(.Text) + i
End If
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
End Sub
where 50 in the above code is the amount you want to increment the other numbers by. Note that, given your specifications, the above will only process numbers between 58 and 700.
I am under the impression that || is the "or" statement in MATLAB. Perhaps someone can explain the confusing behaviour I am seeing:
a = 2;
a == 2 %returns ans = 1 (true)
a == 2 || 3 %returns ans = 1 (true)
a == 3 || 4 %returns ans = 1 (true)??!!
What am I missing here? 'a' is neither 3 or 4, so shouldn't
a == 3 || 4
return ans = 0 (false)?
The expression
a == 3 || 4
is evaluated that way :
a == 3 => false
then
false || 4 => true
if you want to check whether a is equal to 3 or 4 you should write
(a == 3) || (a == 4)
which is evaluated that way
a == 3 => false
then
a == 4 => false
then
false || false => false
Thomas's answer is an excellent explanation of what's going on here; another way that you can compare a variable to multiple answers is using the any() function.
solutions = [3 4];
any(a==solutions);
The a==solutions line creates a matrix the same size as solutions, which contains 1's in indecies which where the conditional is true, and 0's where it is false.
A few more examples:
any(isprime([17:24])); %returns true; 17, 19 and 23 are prime
any(isinteger(sqrt([17:24]))); %(test for square number) returns false; no square numbers in this range
any(mod(magic(3)(:),6)==3); %returns true; 9 mod 6 == 3. Note (:) inserted so that any is evaluated against all entries of the square matrix created by magic
a == 3 || 4 %returns ans = 1 (true)??!!
The reason for the above behaviour is due to the fact that any real number other than '0' in MATLAB is always evaluated to true.
So what is happening here is
The expression a == 3 is evaluated first and found to be false.
Next, expression false || 4 is evaluated.
Since '4' is a real number other than zero, the resulting expression is false || true which is evaluated to true.
To get a desire result use (a == 3) || (a == 4) which is evaluated as false || false which returns false.
Access 2010: I have a table that includes 3 Boolean fields - call them Field_A, Field_B, and Field_C.
On the data entry form, a user should be able to check (make the value TRUE) any one of those options, but only one option can be TRUE at any time. If Field_B is already true and the user wants to change it so Field_C is the option selected to be TRUE, he should first have to unselect Field_B (reset it to FALSE) before he can check the box on the form for Field_C.
So I need some validation code for each of these fields which, if the user tries to set one field to TRUE, checks the status of the other two fields. If both other fields are currently FALSE, it allows the current field to be changed to TRUE. But if either of the other fields is currently TRUE, it should create a popup message saying there's already another selection and the other field must first be changed to FALSE before he can proceed.
I tried this using the numerical values for the Yes/No option, setting a conditional validation that required the sum of the other two values to be zero before allowing the field of interest (e.g. Field_A) to be changed to TRUE (value = -1) (just something like ([Field_B] + [Field_C]) =0, but I kept getting syntax errors. I'm new enough to this that I don't know if it really is just a simple syntax problem, or if a completely different approach is needed.
Last piece of info-- it's acceptable to have all 3 fields set to FALSE, so I don't want something that forces one of them to become TRUE if another is changed back from TRUE to FALSE.
You have two acceptable combinations for those 3 check boxes:
all are False (unchecked)
only one can be True (checked)
So that means the sum of those check box values must be either 0 or -1.
? False + False + False
0
? False + False + True
-1
You can add a function in the form's code module ...
Private Function checkBoxProblem() As Boolean
Dim blnReturn As Boolean
Dim intSum As Integer
Dim strPrompt As String
intSum = Nz(Me.Field_A, 0) + Nz(Me.Field_B, 0) + Nz(Me.Field_C, 0)
If Not (intSum = 0 Or intSum = -1) Then
strPrompt = "only one box can be checked"
MsgBox strPrompt
blnReturn = True
Else
blnReturn = False
End If
checkBoxProblem = blnReturn
End Function
Then call the function from the before update events of each of those 3 check boxes.
Private Sub Field_A_BeforeUpdate(Cancel As Integer)
Cancel = checkBoxProblem
End Sub
Private Sub Field_B_BeforeUpdate(Cancel As Integer)
Cancel = checkBoxProblem
End Sub
Private Sub Field_C_BeforeUpdate(Cancel As Integer)
Cancel = checkBoxProblem
End Sub
A bit of code behind your data-entry form should do the trick. Try something along these lines:
Option Compare Database
Option Explicit
Private Sub Field_A_BeforeUpdate(Cancel As Integer)
Const ThisField = "Field_A"
If Me.Field_A.Value Then
If Me.Field_B.Value Then
ShowMyMessage "Field_B", ThisField
Cancel = True
ElseIf Me.Field_C.Value Then
ShowMyMessage "Field_C", ThisField
Cancel = True
End If
End If
End Sub
Private Sub Field_B_BeforeUpdate(Cancel As Integer)
Const ThisField = "Field_B"
If Me.Field_B.Value Then
If Me.Field_A.Value Then
ShowMyMessage "Field_A", ThisField
Cancel = True
ElseIf Me.Field_C.Value Then
ShowMyMessage "Field_C", ThisField
Cancel = True
End If
End If
End Sub
Private Sub Field_C_BeforeUpdate(Cancel As Integer)
Const ThisField = "Field_C"
If Me.Field_C.Value Then
If Me.Field_B.Value Then
ShowMyMessage "Field_B", ThisField
Cancel = True
ElseIf Me.Field_A.Value Then
ShowMyMessage "Field_A", ThisField
Cancel = True
End If
End If
End Sub
Private Sub ShowMyMessage(OtherField As String, CurrentField As String)
MsgBox _
"You must un-select """ & OtherField & """" & _
" before you can select """ & CurrentField & """", _
vbExclamation, _
"Mutually exclusive options conflict"
End Sub