I was wondering if someone could help me out.
I have a number, it could be 004 or 010 ... I would like to subtract it by 1 and keep the leading zero.
Everytime i try to subtract, it always takes away the leading zero.
for instance
004 - 1
This always ends up as just
3
But i would like it to be
003
Having said that if i have 010 and i subtract 1 i would like it to be 009
Any help would be greatly appreciated.
Cheers,
Do your calculations with integers then change to a string to display them. then concatenate "0" or "00" where needed eg
c = a - b
displayvalue = cstr(c)
if c < 100 then
displayvalue = "0" & cstr(c)
end if
if c < 10 then
displayvalue = "00" & cstr(c)
end if
Continue doing the math as you are but include some padding 0's using the Right and String functions.
Dim a, b
a = 003
b = 1
Right(String(3,"0") + cstr(a-b), 3)
Related
I'm trying to set a default value in a DropDown box depending on the current time. (substring-after(now(), "T"))
To be more specific, I would like my DropDown box to have as default value
"AM" if the current time is between 06:00:01 and 12:00:00.
"PM" if the current time is between 12:00:01 and 18:00:00.
"NIGHT" if the current time is between 18:00:01 and 06:00:00.
I tried with "Rules" and "Set default value" but can't figure out a solution.
Thanks for help!
go get the hours and seconds number and put it fields.
A - hours
B - seconds
A >= 6 and B > 0 OR A =< 12 and B = 0 ---> AM
if A >= 12 and B > 0 OR A =< 18 and B = 0 ---> PM
if A >= 18 and B > 0 OR A =< 6 and B = 0 ---> NIGHT
I found a way, I put hours in a field (I don't think it's absolutely necessary but it's more clear for the formula after) then I set the default value for the formula of the DropDown Box as :
concat(substring("AM", 1, (field4 < 12) * string-length("AM")), substring("PM", 1, (not(field4 < 12)) * string-length("PM")))
field4 is the field when I extract the current hour of the day with that formula:
substring-before((substring-after(now(), "T")), ":")
You will find usefull tips here for this application:
http://blogs.msdn.com/b/infopath/archive/2006/11/27/conditional-default-values.aspx
I have a problem (Octave):
lets say I have a = 1 2 3 4 5
and I want to add 'b' character to every element in a.. So that I get something like that: a = 1b 2b 3b 4b 5b
How do I do that?
Thanx
To be able to do that, a must be defined as a string of characters rather than an array of doubles. There may be a more elegant solution, but the following works:
a = num2str(1:5); % '1' is a(1), '2' is a(5), etc...
% a(2) to a(4) are white spaces
for k=2:4:18
a(k) = 'b';
end
I have a database table which contanis a field name Province bits and it adds up the count of the pattern like:
AB-1
BC-2
CD-4
DE-8
EF-16.... and so on.
Now in the table entry I have a value-13(Province bit), which implies checkboxes against entry AB,CD,DE(adds up to 13)should be checked.
I am not able to get the logic behind the same, how can check only those checkboxes whose sum adds up to the entry in the table?
You need to check to see if the value is in the bitwise total.
if( interestedInValue & totalValue == interestedInValue)
{
// this value is in the total, check the box
}
Documentation on & http://msdn.microsoft.com/en-us/library/sbf85k1c(v=vs.71).aspx
e.g. 13 = 1 + 4 + 8
13 & 1 == 1 // true
13 & 2 == 2 // false
13 & 4 == 4 // true
13 & 8 == 8 // true
13 & 16 == 16 // false
EDIT: for more clarification
ab.Checked = 1 && ProvinceBit == 1 // checkbox AB
bc.Checked = 2 && ProvinceBit == 2 // checkbox BC
...
The field is using bit flags.
13 is 1101 binary.
So convert the value to bits and assign one bit to each checkbox.
By converting your number to a string, you can convert to an array or just iterate through the string. A bit brute force, but will give you what you need.
var value = 13
string binary = Convert.ToString(value, 2);
//binary = "1101"
Help on validation expression to validate a string representing either number or addition of numbers.
e.g:
2 OK
22 + 3 OK
2+3 not OK
2 +3 not OK
2 + 34 + 45 OK
2 + 33 + not OK
2 + 33+ 4 not OK
This would be quite a simple pattern
^\d+(?: \+ \d+)*$
See it here on Regexr
^ anchor for the start of the string
$ anchor for the end of the string
The anchors are needed, otherwise the pattern will match "partly"
\d+ is at least one digit
(?: \+ \d+)* is a non capturing group that can be there 0 or more times (because of the * quantifier at the end)
Try:
/^\d+(\s+\+\s+\d+)*$/
This matches a number followed by an optional plus sign and number, which can then be repeated.
I'm trying to accomplish this in LaTeX:
⎡a⎤ ⎡b … n⎤
⎢⁞⎢ ⎢⁞ ⋱ ⁞⎢
⎣x⎦ ⎣y … z⎦
[a … x]
I'm able to get a vector + a matrix on one line, but I'm not sure how to align the vector below so that it sits perfectly under the large matrix.
Here's a less-unicode text representation of the 'drawing' above:
[a] [ b c ]
[d] [ e f ]
[ g h ]
Note that the last line ([ g h ]) is a single-row matrix, separate from the 2x2 matrix above it.
\edit2
final answer:
\begin{align*}
\begin{vmatrix} 1 \\ 2 \end{vmatrix} &\begin{vmatrix} 1 & 2 & 3 \\ 3 & 4 & 5 \end{vmatrix} \\[6px]
&\begin{vmatrix} 2 & 3 & 4 \end{vmatrix}
\end{align*}
does exactly what you want, read below for more info about placement and such. The "&" sign is used to align in general. Forgot the first line had 2 matrices but now you have it :).
info on spacing and such
\begin{align*}
&\begin{pmatrix} 1 & 2 & 3 \ 3 & 4 & 5 \end{pmatrix} \[6px]
&\hspace{2px}\begin{pmatrix} 2 & 3 & 4 \end{pmatrix}
\end{align*}
would do the job. For some strange reason the align gave errors when leaving out the first "&" symbol and it gave a 2px offset. I figured you wanted some space between the two if not leave the [6px]. You can always use \hspace{amount of whitespace} to place your second matrix in the place you want. This can be given in pt's, px's (which i did) etc.
//edit
Hm I notice the \hspace{} is actually not needed, but can be used in case of pmatrix. What happens is that the pmatrix brackets give a biased image of the matrices. When using vmatrix like:
\begin{align*}
&\begin{vmatrix} 1 & 2 & 3 \\ 3 & 4 & 5 \end{vmatrix} \\[6px]
&\begin{vmatrix} 2 & 3 & 4 \end{vmatrix}
\end{align*}
It all goes well :). So basically, probably the easiest way to fix it is either use other brackets to make it look good or use the \hspace to align as you like it.
If all else fails, PGF/TikZ can do this. See this example.
Wrap the thing in \begin{align*} ... \end{align*} and use & as the alignment marker in your formulas.
Example:
\begin{align*}
\begin{pmatrix} ... vector here \end{pmatrix}
&\begin{pmatrix} ... first matrix here \end{pmatrix}\\
&\begin{pmatrix} ... second matrix here \end{pmatrix}
\end{align*}