IIF Statements with blank or alpha characters in MS Visual Basic - reporting-services

I have a field CODE_USER_2 that can be equal to 1.75, 2, 2.62, 3.75, 5.25, 6, OT(w/2 spaces, or __(4 spaces). If it is 1.75, 2, 2.62, 3.75, 5.25, 6 I would like corresponding weights to result (THIS PART WORKS).
If the field is __ or OT, I would like the equation to result with 0. I currently get #error with the following formula.
=IIf(Fields!CODE_USER_2_IM.Value= " " OR "OT " ,0,Switch(Fields!CODE_USER_2_IM.Value=1.75,.629,Fields!CODE_USER_2_IM.Value=2,.67,Fields!CODE_USER_2_IM.Value=2.62,1.089,Fields!CODE_USER_2_IM.Value=3.75,1.767,Fields!CODE_USER_2_IM.Value=5.25,3.224,Fields!CODE_USER_2_IM.Value=6,3.895))
Please let me know if you have ideas!

You have to repeat "Fields!CODE_USER_2_IM.Value = " after the OR.
Or try this - less wordy but more obscure :
=IIf( ( " |OT |" ).Contains(Fields!CODE_USER_2_IM.Value + "|"
,0,Switch(Fields!CODE_USER_2_IM.Value=1.75,.629,Fields!CODE_USER_2_IM.Value=2,.67,Fields!CODE_USER_2_IM.Value=2.62,1.089,Fields!CODE_USER_2_IM.Value=3.75,1.767,Fields!CODE_USER_2_IM.Value=5.25,3.224,Fields!CODE_USER_2_IM.Value=6,3.895
, True , 0))
Always close out a Switch with:
, True , [default value] )
Also beware that matching in SSRS expressions is exact e.g. 2 spaces not = 4 spaces.

Related

regex pattern starting with "=" and exceptions

I'm trying to write an expression which will be used with json files for a vscode extension. My expression should start with "=\s*" and then I want it to select everything after the equal except for the following cases:
TRUE or FALSE after the equality
starting with digit
starting with ' or "
I have tried many things and separately each case I manage to make it work but when I try to put it all together, it doesn't work
Example of doc strings:
abc = test
abc = TRUE
abc = FALSE
abc = "test"
abc = 'test'
abc = 123
Out of these examples my regex should only keep the very first one and "test" can be anything.
What was the closest to the solution was this one /(=\s*)^(((?!TRUE|FALSE|[0-9]|\"|\').)*)$/gm
You can use
Find what: ^(.*?=)(?!\s*(?:TRUE|FALSE|[0-9"'])).*
Replace With: $1
Details:
^ - start of a line
(.*?=) - Group 1: any zero or more chars other than line break chars, as few as possible and then a = char
(?!\s*(?:TRUE|FALSE|[0-9"'])) - a negative lookahead that fails the match if, immediately to the right of the current location, there are
\s* - zero or more whitespace
(?:TRUE|FALSE|[0-9"']) - TRUE, FALSE, digit or " or '
.* - the rest of the line.
See the regex demo and the demo screenshot:

Why is isspace() returning false for strings from the docx python library that are empty?

My objective is to extract strings from numbered/bulleted lists in multiple Microsoft Word documents, then to organize those strings into a single, one-line string where each string is ordered in the following manner: 1.string1 2.string2 3.string3 etc. I refer to these one-line strings as procedures, consisting of 'steps' 1., 2., 3., etc.
The reason it has to be in this format is because the procedure strings are being put into a database, the database is used to create Excel spreadsheet outputs, a formatting macro is used on the spreadsheets, and the procedure strings in question have to be in this format in order for that macro to work properly.
The numbered/bulleted lists in MSword are all similar in format, but some use numbers, some use bullets, and some have extra line spaces before the first point, or extra line spaces after the last point.
The following text shows three different examples of how the Word documents are formatted:
Paragraph Keyword 1: arbitrary text
1. Step 1
2. Step 2
3. Step 3
Paragraph Keyword 2: arbitrary text
Paragraph Keyword 3: arbitrary text
• Step 1
• Step 2
• Step 3
Paragraph Keyword 4: arbitrary text
Paragraph Keyword 5: arbitrary text
Step 1
Step 2
Step 3
Paragraph Keyword 6: arbitrary text
(For some reason the first two lists didn't get indented in the formatting of the post, but in my word document all the indentation is the same)
When the numbered/bulleted list is formatted without line extra spaces, my code works fine, e.g. between "paragraph keyword 1:" and "paragraph keyword 2:".
I was trying to use isspace() to isolate the instances where there are extra line spaces that aren't part of the list that I want to include in my procedure strings.
Here is my code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
def extractStrings(file):
doc = file
for i in range(len(doc.paragraphs)):
str1 = doc.paragraphs[i].text
if "Paragraph Keyword 1:" in str1:
start1=i
if "Paragraph Keyword 2:" in str1:
finish1=i
if "Paragraph Keyword 3:" in str1:
start2=i
if "Paragraph Keyword 4:" in str1:
finish2=i
if "Paragraph Keyword 5:" in str1:
start3=i
if "Paragraph Keyword 6:" in str1:
finish3=i
print("----------------------------")
procedure1 = ""
y=1
for x in range(start1 + 1, finish1):
temp = str((doc.paragraphs[x].text))
print(temp)
if not temp.isspace():
if y > 1:
procedure1 = (procedure1 + " " + str(y) + "." + temp)
else:
procedure1 = (procedure1 + str(y) + "." + temp)
y=y+1
print(procedure1)
print("----------------------------")
procedure2 = ""
y=1
for x in range(start2 + 1, finish2):
temp = str((doc.paragraphs[x].text))
print(temp)
if not temp.isspace():
if y > 1:
procedure2 = (procedure2 + " " + str(y) + "." + temp)
else:
procedure2 = (procedure2 + str(y) + "." + temp)
y=y+1
print(procedure2)
print("----------------------------")
procedure3 = ""
y=1
for x in range(start3 + 1, finish3):
temp = str((doc.paragraphs[x].text))
print(temp)
if not temp.isspace():
if y > 1:
procedure3 = (procedure3 + " " + str(y) + "." + temp)
else:
procedure3 = (procedure3 + str(y) + "." + temp)
y=y+1
print(procedure3)
print("----------------------------")
del doc
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import docx
doc1 = docx.Document("docx_isspace_experiment_042420.docx")
extractStrings(doc1)
del doc1
Unfortunately I have no way of putting the output into this post, but the problem is that whenever there is a blank line in the word doc, isspace() returns false, and a number "x." is assigned to empty space, so I end up with something like: 1. 2.Step 1 3.Step 2 4.Step 3 5. 6. (that's the last iteration of print(procedure3) from the code)
The problem is that isspace() is returning false even when my python console output shows that the string is just a blank line.
Am I using isspace() incorrectly? Is there something in the string I am not detecting that is causing isspace() to return false? Is there a better way to accomplish this?
Use the test:
# --- for s a str value, like paragraph.text ---
if s.strip() == "":
print("s is a blank line")
str.isspace() returns True if the string contains only whitespace. An empty str contains nothing, and so therefore does not contain whitespace.

Subtring and Substring index to split into two integers

I'm trying to split this hours into two different columns, I have the columns "hrs" and "mins"
For example, if the user enters 0.50 --- 0 should go to the "hrs" column, while 50 should go to the mins column.
I tried to use SUBSTRING_INDEX and SUBSTRING and it worked
SUBSTRING_INDEX(SUBSTRING("0.50", 3), ".", 2)
SUBSTRING_INDEX(SUBSTRING("0.50", 1), ".", 1)
and I got the output 0 and 50. so that's working, but what if the user will enter, 10.5 or 2.5 then it all becomes messed up.
How can I properly split it into 2 separate integers?
Thank you
Why not explode?
$pizza = "05.500";
$pieces = explode(".", $pizza);
echo $pieces[0];
echo '/';
echo $pieces[1];

SSRS Format seconds as time (negative seconds)

I have a column with integers: TotalSec that has seconds. It can be 0, negative or positive.
I have to format these seconds in a report. But cant get something working for the negative seconds.
My logic:
For 0 = Nothing,
For Positive format as HH:mm:ss
For Negative - ABS the value then format as -HH:mm:ss
=IIF(SUM(Fields!TotalSec.Value)=0, Nothing, IiF(SUM(Fields!TotalSec.Value)>0,
Format(DateAdd("s",SUM(Fields!TotalSec.Value), "00:00:00"), "HH:mm:ss"), "-" & Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss")))
I get an #Error for the Negative numbers. With the warning:
Warning 2 [rsRuntimeErrorInExpression] The Value expression for the textrun ‘TotalSec.Paragraphs[0].TextRuns[0]’ contains an error: The added or subtracted value results in an un-representable DateTime. Parameter name: value
It worked like this:
=IIF(SUM(Fields!TotalSec.Value)=0,Nothing,IIF(SUM(Fields!TotalSec.Value)< 0,"-"&Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss"),Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss")))
I cleaned up the previous answer:
=IIf(Fields!elapsed.Value < 0, "-", "+")
&
Format(
DateAdd(
"s",
Abs(Fields!elapsed.Value),
"00:00:00"
),
"HH:mm:ss" ' can be m:ss
)
The "+" is to keep the results lined up, and can be replaced with "" if desired.

quadratic equation

Question: I have a program that solves a quadratic equation. The program gives real solutions only. How do I perform the quality testing of the program? Do you need to ask me for some extra input parameters?
Create test cases, and check the result of your program against the expected result (which is calculated externally) in the test case.
The test cases can cover several ordinary cases, together with special cases, such as when the coefficient is 0, or the discriminant is < 0, = 0, near 0. When you compare the result, make sure you handle the comparison properly (since the result is floating point numbers).
# "quadratic-rb.rb" Code by RRB, dated April 2014. email ab_z#yahoo.com
class Quadratic
def input
print "Enter the value of a: "
$a = gets.to_f
print "Enter the value of b: "
$b = gets.to_f
print "Enter the value of c: "
$c = gets.to_f
end
def announcement #Method to display Equation
puts "The formula is " + $a.to_s + "x^2 + " + $b.to_s + "x + " + $c.to_s + "=0"
end
def result #Method to solve the equation and display answer
if ($b**2-4*$a*$c)>0
x1=(((Math.sqrt($b**2-4*$a*$c))-($b))/(2*$a))
x2=(-(((Math.sqrt($b**2-4*$a*$c))-($b))/(2*$a)))
puts "The values of x1 and x2 are " +x1.to_s + " and " + x2.to_s
else
puts "x1 and x2 are imaginary numbers"
end
end
Quadratic_solver = Quadratic.new
Quadratic_solver.input
Quadratic_solver.announcement
Quadratic_solver.result
end