VBS If Variable > Variable Then - if-statement

I am writing a script to delete folders older than a certain time window.
The issue I am having is with an If then statement.
If strCurrentAge > strAgeCutoff Then
strCurrentAge = date diff calculation (calculates days between now and the last modified date of the folder)
strAgeCutOff = AgeCutOff.value (textbox input value from an HTA... Typical value would be 30)
strAgeCutOff as a number.
strCurrentAge seems to be recognized as a number though.
Banging my head against the wall trying to figure this out.

If AgeCutOff is a text box, then AgeCutOff.value won't actually be a number, it will be text.
If you want a number from it, look into the CInt() function. You could also use CLng for a greater range but, unless you're talking about the ages of thngs that live substantially longer than humans, integers up to 32,000 should suffice.

Related

OpenOffice Calc SUM of TRUNC number cells, with rows that include text cells

RE: Apache OpenOffice 4.1.7, AOO417m1(Build:9800) - Rev. 46059c9192, 2019-09-03 12:04.
I need to sum non-integer entries across a range of cells, but without including the decimal values (complicated by some cells being text). I started with ROUNDDOWN, then TRUNC, then FLOOR. I'm driving myself nuts trying to find a clean code (or even an arbitrarily extensible ugly code) for what would be the following:
=SUMIF(ISTEXT(R7:CL7);0;TRUNC(R7:CL7))
The above doesn't work, of course, since TRUNC() doesn't apply to ranges, but it conveys what I'm trying to do in a nutshell -- some of the cells contain text, which SUM() ignores (luckily), but they flummox TRUNC, so I needed to handle the text problem.
I started with ISNUMBER, just to get the ball rolling; ISTEXT has fewer characters, but it's not worth fixing that right now.
FLOOR was equally disappointing for ranges:
=SUM(FLOOR(R7:T7;1))
I tried variations of =SUM(IF(... and searches for ROUNDDOWN range (and variations on that) and such pseudocode as "IFTEXT" and "SUMTRUNC" (and variations on that). I found info on ROUNDDOWN(SUM(... and so forth, but not "SUM(ROUNDDOWN(..." or any equivalent.
In my delirium, I got silly and even tried:
=SUMIF(ISTEXT(S7:U7);0;AND(TRUNC(S7);TRUNC(T7);TRUNC(U7)))
To be clear: {2.9→2 + 2.9→2 + 2.9→2 = 6} ≠ {2.9+2.9+2.9 = 8.7→8}. I'm looking for a 6, not an 8 (I'd joke about sixes and sevens, but I'm way past pumpkin o'clock and 2.428571 takes up too much space).
My current test-kludge is:
=SUM(IF(ISNUMBER(R7);ROUNDDOWN(R7);0);IF(ISNUMBER(S7);ROUNDDOWN(S7);0);IF(ISNUMBER(T7);ROUNDDOWN(T7);0); ... ;IF(ISNUMBER(AX7);ROUNDDOWN(AX7);0))
It ends at AX7 only because of the char count. I hope to SUM the whole row in a single sweep, but that ain't gonna cut it. I could do it in large chunks in multiple cells, and then add those cells up, but oy gevalt.
Since it's already ugly anyway, I could use the following to save a few characters, but this would only mean being able to extend the range maybe 6 further cells (not much point in that):
=IF(ISTEXT(R7);0;TRUNC(R7))+IF(ISTEXT(S7);0;TRUNC(S7))+IF(ISTEXT(S7);0;TRUNC(S7))
I'm seriously considering simply going down a bunch of rows (to below my data cells) and entering the following, then copying the cell and pasting it to a complementary range, and telling the SUM cells to just sum up their respectively shadowed rows (instead of the data rows that they sit in):
=IF(ISTEXT(R7);0;TRUNC(R7))
Sorry for the rambling; I need sleep. This started as a need, then multiple failed attempts became a grudge match of principle and obstinacy, and now I'm just plugging away at it out of blind habit developed over the past 2-3 days (hopefully I won't forget what the purpose was).
In summary...: ++?????++ Out of Cheese Error +++DIVIDE BY CUCUMBER.
I'm comfortable enough with macros, though it's been ~7 years (and that was in Excel). Thanks in advance, even if the answer is that I'm stuck with one of these! 🙂
EDIT: I don't see a way to attach a .csv here (though I could open the .csv with Notepad, and copy-and-paste the contents if that would help anyone), so here's a set of pics:

Is there a way to override Font.Position increments to make them smaller (to less than.5 pt)? With VBA or otherwise?

I'm writing a VBA macro in Word(365) which loops through a selection character by character and randomizes font position (raise/lower) and spacing*. I know what you're thinking, and yes, this makes the final .docx file size much larger than the original.
*Context: Why? I'm a hobbyist book designer/poet/editor trying to mimic the warmth/analog/organic feel (and subtle inherent flaws) of hand-set letterpress type.
So, here's the deal: The code works. That's not the problem.
The problem is that Word's Font.Position increments are hard-coded at .5 pt, so when my macro calculates the random position, Word rounds it to the nearest .5 pt. That is just too large for what I need with my small fonts (usually 12 pt). I may be on a wild goose chase, but is there any way to override these increments, via VBA (ideally) or otherwise (C++?), to make them smaller for a more subtle effect?
Note: The Font.Spacing increments are .05 pt, so that's not a problem, just Font.Position.
I was also monkeying around with the page size, thinking that I could just make a huge page & font size (ie: 1000%), to make up for the too-large .5 pt increments, and then scale it back down (to 10%) to its intended size in a PDF, but the limit on page size is a mere 22" which is not big enough to make much of a difference.
My next option is to translate the same macro into LibreOffice Writer. That program uses integer % increments instead of .5 pt increments, which would be about 4x more precise # 12 pt font (.12 pt increments). As such, Writer would out perform Word in this application until the font size is 50 pt or larger. I do not have much experience with LO Basic, and documentation/example code is much harder to come by. I know it's very similar to VBA and there's a lot of crossover. It might/might not be an easy project, I just haven't tried yet.
Anyway, I wanted to see if there was a way around the increments in Word first because I'd like to have this application within both Word and Writer.
Right now, I'm under the assumption that the increments are hard-coded into Word and there's nothing I can do about it.
Prove me wrong.
Thanks!
P.S. I know nothing about C++ and if everyone tells me that Word is a lost cause and I should just translate it to Writer I'll do that (I may anyway) and post my code for that later if I get stuck.
Completely nonsense. According to VBA Word reference, property Font.Position is Long. This property sets the vertical alignment of a selected text above (or below) the line. In UI: Font-Advanced-Character Spacing-Position.
Manually you can set this property with 0.5 rounding.
Macro recording also shows command "Selection.Font.Position = 0.5"
No way you can assign the property Font.Position with a fraction using macro, because it's Long.
I would like to have a macro shifting text above or below the line, but it is possible only to shift by step of 1.0 (or 0.5 via UI). Hope, there is a workaround... (at least for 0.5. Could you show you code example with 0.5 shift?)
Updated I have found a workaround. According to the old WordBasic reference - the minimum step for Position is 0.5 pt.
To get the value with 0.5 fraction (of the selected text. Font.Position returns Long with no fraction)
MsgBox Dialogs(wdDialogFormatFont).Position
To set the value with 0.5 fraction (to the selected text), you must use old-style WordBasic
WordBasic.FormatFont Position:="-0.5"
Hope, this helps somebody...
More about old WordBasic: https://learn.microsoft.com/en-us/office/vba/word/concepts/customizing-word/conceptual-differences-between-wordbasic-and-visual-basic
https://learn.microsoft.com/en-us/office/vba/word/concepts/customizing-word/built-in-dialog-box-argument-lists-word

Google Sheets hours worked before and after specified time

I am trying to specify a time that starts a shift premium for a time card. I was so happy I finally figured out how to get it, but then I changed a time to a first shift time and thats when I lost all hope. I have spent hours messing with this and my current formula's looks like
x1.05
=IF(COUNT(A20:B20)=2,MOD($B$18-A20,1)*24,"")
x1.1
=IF(COUNT(A20:B20)=2,MOD(B20-$B$18,1)*24,"")
My end goal is to have it so first shift (7am - 3pm) fall under base pay, 2nd shift (4pm-12am) fall under x1.05 and anything past 12am falls under x1.1
Just getting this far has been a mind blower for me and any help would be greatly appreciated.
I have moved this to its own sheet to share with everyone. I am still playing with things myself and trying different things, but on the sheet I have included the variables along with the wording of the contract that effects the pay scale. NOTE the times I originally provided were just examples from the top of my head.
My Sheet
It doesn't look like your current sheet accounts for the multiple criteria you're wanting to evaluate. First shift (x1) begins at 7; second shift (x1.05) begins at 15:00, and third shift (x1.10) begins at 24:00.
I added each of those directly above the columns they affect and used this formula for the Base column:
=IF(COUNT($A20:$B20)=2,IF($A20<F$18,(MOD(MIN(F$18,$B20)-$A20,1))*24,0),"")
...this for the x1.05 column:
=IF(COUNT($A20:$B20)=2,IF($A20<G$18,(MOD(MIN(G$18,$B20)-$A20,1)*24)-E20,0),"")
...and this for the x1.10 column:
=IF(COUNT($A20:$B20)=2,(MOD(MIN(E$18+1,$B20)-$A20,1)*24)-SUM(E20:F20),"")
So far, it's working as expected. One thing I didn't add into it is to account for someone who starts their shift before 7 a.m. If you want this to be included in the x1.10 column, you could add a calculation for that to the formula there.
Here's what it looks like:
I'm working in Excel, but these formulas should all work in Google Sheets as well.

How to record total values with rrdtool

I'm pretty sure this question has been asked several times, but either I did not find the correct answer or I didn't understand the solution.
To my current problem:
I have a sensor which measures the time a motor is running.
The sensor is reset after reading.
I'm not interested in the time the motor was running the last five minutes.
I'm more interested in how long the motor was running from the very beginning (or from the last reset).
When storing the values in an rrd, depending on the aggregate function, several values are recorded.
When working with GAUGE, the value read is 3000 (10th seconds) every five minutes.
When working with ABSOLUTE, the value is 10 every five minutes.
But what I would like to get is something like:
3000 after the first 5 minutes
6000 after the next 5 minutes (last value + 3000)
9000 after another 5 minutes (last value + 3000)
The accuracy of the older values (and slopes) is not so important, but the last value should reflect the time in seconds since the beginning as accurate as possible.
Is there a way to accomplish this?
I dont know if it is useful for ur need or not but maybe using TREND/TRENDNAN CDEF function is what u want, look at here:
TREND CDEF function
I now created a small SQLite database with one table and one column in that tabe.
The table has one row. I update that row every time my cron job runs and add the current value to the current value. So the current value of the one row and column is the cumualted value of my sensor. This is then fed into the rrd.
Any other (better) ideas?
The way that I'd tackle this (in Linux) is to write the value to a plain-text file and then use the value from that file for the RRDTool graph. I think that maybe using SQLite (or any other SQL server) just to keep track of this would be unnecessarily hard on a system just to keep track of something like this.

How to make localized duration string?

I'm making an app in which I need to show duration string. A few examples:
1 hour 2 minutes left to break,
2 minutes 8 seconds left to break
For the moment I have a C++ function which for a given amount of seconds/milliseconds/minutes gives you a string:
wxString getTimeStr(int value,
ETimeUnit time_unit, // milliseconds or seconds or minutes or hours
wxString const & lang) // english or russian
It consists of lots of conditions depending on language, time units and existing value. Now I'm considering porting the app to other languages and it would be a bit painful to write c++ code for each new language. Is there a way to make that string using standard functions?
The app is written in C++ using wxWidgets and so far works only on Windows. I would prefer not to use platform-dependent functions, although it would be nice to know them.
You won't be able to do it perfectly without writing different code for different languages. For example, I bet your existing code doesn't allow to produce times like "5 minutes before half past threee" which are nevertheless used in (spoken) German. And even without going to such extends, consider that English "half past three" is translated to "half to four" actually.
So if using the official time is not enough (and if it is, look at wxLocale::GetInfo(wxLOCALE_TIME_FMT)), you will indeed need to write code to handle at least some languages specially.
I suggest splitting your function into two.
The first part would return the time remaining as a wxTimeSpan.
The second part 'translates' the wxTimeSpan into the required language and returns a string. This is the only part you need to change for each language.
For the sake of explanation, let's assume that
we only care about hours and minutes
Klingons like to see hours/mins
Vulcans like to see mins:hours
Russians have various forms of the word for minutes
Then your second function would be written something like this
// extract hours and residual minutes into CSV
wxString csv = theTimeSpan.Format("%H,%M);
// extract tokens for csv
wxString hours, mins
...
if( lang == "Klingon" ) {
return hours + "/" + mins
} else if ( lang == "Vulcan" ) {
return mins + ":" + hours
} else if ( lang == "Russian" ) {
wxString min_name;
switch( mins.ToLong() ) {
case 1: min_name = "---"; break;
...
}
return mins + " " + min_name;
}
Unfortunately you can NOT use Format to get an arbitrary 'time structure' because of an essential ambiguity in, for example, the number of hours in a time span. It can be either the total number of hours (for example, for a time span of 50 hours this would be 50) or just the hour part of the time span, which would be 2 in this case as 50 hours is equal to 2 days and 2 hours.
wxTimeSpan resolves this ambiguity in the following way: if there had been, indeed, the D format specified preceding the H, then it is interpreted as 2. Otherwise, it is 50. The same applies to all other format specifiers: if they follow a specifier of larger unit, only the rest part is taken, otherwise the full value is used.
So, you have to muck around with the csv tokens as shown in my code sample.
The traditional approach to the problem of localization is to build a map of label name -> label value and use place holders in the values.
In the code, you only reference the label name, and provide the values for the place holders
To port to another language, you just need to translate the map
Depending on the degree of sophistication you need, you might have a simple placeholder mechanism (snprintf-like), or one that allows a mini-language to build the value at runtime depending on simple parameters (for example, distinguishing between singular and plural).
In this example, it would be as simple as:
using LabelsType = std::map<LabelName, std::string>;
using LangToLabelsType = std::map<Language, LabelsType>;
Note: I advise an enum for the languages, rather than a plain string.
If you were on Linux I would recommend gettext, however I am unsure whether it works on Windows. Still, you can look it up and see how it works, it might help you.
Sometimes, it is better to make the program more technical rather than closer to natural language. I have also found myself in such situations (to make it looking really cool). It often was the case that the customer did not care. The information is sometimes much more important than its exact form.
A programmer should sometimes choose the tradeoffs -- a kind of meta-solution that is not related to the programming language/framework. In other words, you should weight the correctness of the solution and the correctness of the expectation.