Google Apps Script on Form Submit Time Formatting Glitch/Fix - formatting

Background:
How: I suspect that this is a glitch within Google Form (submission process)/Spreadsheet, but may be part of the Date conversion utility of the Spreadsheet interface (and is an intended feature).
When entering a format in a text box in Google Forms, there is some sort of communication error between the Form submit and Response Spreadsheet, or pre-processing of the Form's data before it is sent to the spreadsheet. The glitch only seems to happen for data in a text field of the format ##:## TEXT where TEXT contains no '.' characters. For example: 4:15 pm will reproduce the glitch, but 4:15 p.m and 4:15 p.m. will not.
Result: An apostrophe character is added to the beginning of the string when it is put into the Spreadsheet (i.e. '4:15 pm) which throws off several sub-systems I have in place that use that time data. Here are two screenshots (sorry for the bad sizing on the second):
I'm 99% certain that the glitch is caused by the ##: combination.
Temporary Fix?: The real question is... how might I go about removing that pesky apostrophe before I start manipulating the time data? I know how to getValue() of a cell/Range. Assume I have the value of a cell in the following manner:
var value = myRange.getValue();
// value = '4:15 pm
How can I go about processing that value into 4:15 pm? A simple java function could be
value = value.substring(1); // Assuming "value" is a String
But in Google App Scripts for Spreadsheets, I don't know how I would do that.
Post-Script: It is necessary to post-process this data so that I don't have to lecture university faculty in the language department about inputting time format correctly in their forms.
Thanks in advance to those who can help!

How can I go about processing that value into 4:15 pm? A simple java
function could be
value = value.substring(1); // Assuming "value" is a String But in
Google App Scripts for Spreadsheets, I don't know how I would do that.
Google Apps Scripts uses Javascript which has the exact same method.
value = value.substring(1);
should return all except the first character.
More about Javascript substring at: http://www.w3schools.com/jsref/jsref_substring.asp

If you remove the ' in the spreadsheet cell the spreadsheet interface will convert this entry to a date object.
This might (or not) be an issue for you so maybe you should handle this when you read back your data for another use...
It doesn't happen when text is different (for example with P.M) simply because in this case the ' is not necessary for the spreadsheet to keep it as a string since the spreadsheet can't convert it to a date object (time value).
Artificial intelligence has its bad sides ;-)
edit :
You cant do this in an onFormSubmit triggered function using the javascript substring() you mentioned. If you're not familiar with that, here is the way to go :
To run a script when a particular action is performed:
Open or a create a new Spreadsheet.
Click the Unsaved Spreadsheet dialog box and change the name.
Choose Tools > Script Editor and write the function you want to run.
Choose Resources > Current project's triggers. You see a panel with
the message No triggers set up. Click here to add one now.
Click the link.
Under Run, select the function you want executed by the trigger.
Under Events, select From Spreadsheet.
From the next drop-down list, select On open, On edit, or On form
submit.
Click Save.
see doc here and here

Related

How to trace an output in Access back to the section of VBA code that produced it

I am working on updating an Access database with this year's new data. I did not write the code that goes along with it, and am trying to find out where the formula is for an output (ratios) that the VBA code produces. Is there a way to trace back where the output came from?
I've tried just doing CTRL F to find the word "ratio" in the code but it's so long I can't pin down exactly where it's coming from.
No error messages
In debug mode you can step through the code step by step by pressing F8. You should be able to find the origin of every data export that way.
If the outputed data is a result of calculations I would check every query in the database. One of these probably takes care of those ratio's.

Load only select sections of Code in QlikView

I have a set of code that is rather large in Qlik. I have dates that are defined at the start of the script
i.e.
Let vBDate = Date(Date#('01/01/2015','MM/DD/YYYY'),'MM/DD/YYYY');
Let vEDate = Date(Date#('12/31/2015','MM/DD/YYYY'),'MM/DD/YYYY');
The entire code runs financial numbers based on a specific data source. Originally I had a version of this QVW for each data source. However, as often goes with financials the QVW constantly needs to be refined. So I merged them all into one code. I broke the Code up into different tabs so I can turn off the sources I don't want.
What I want to do is try to se a variable, either in the code, like this,
Let vROIType = 'Vendor';
or using the method answered in my first attempt at this question where the variable is defined on the designer side using a button.
The hope is that when the variable is set, then only the code associated with that variable will run in the reload and the other code will be skipped.
In my research I tried to create functions in the script and use code to call them, however the call would always error out. I also read about QVDs but many of my date variables are defined at the start of running it, and the QVD needs to be pre-run.
Any help would be appreciated.
As long as you wrap the appropriate sections of the script in the conditionals properly, this should accomplish it:
Create a variable via the Variable Overview window (ctrl + alt + v) like you mentioned to reference the correct script to be reloaded (vROIType)
Create a button or text box and set an action to change the value of the vROIType variable. You can just make two buttons so you can select the correct data source by clicking the appropriate button.
Either reload via the menu or create another text box/button with an action to reload your script.
Most importantly, use conditionals in your script to selectively run the correct portions based on the vROIType variable.
if vROIType = 'Vendor' then
Everything in the script you want run when the source is `Vendor`.
elseif vROIType = 'SomeOtherVendor' then
Everything in the script you want run when the source is ....
end if;
Upon reload, the script will look at the vROIType variable and use that to determine whether or not to run parts of the script. Here's a link to a simple example you can try if you have the paid version of Qlikview, otherwise it'll yell at you that you can't open third party .qvw's.

How do I fill out fillable PDF Form fields using 4gl?

I have a PDF form that I'm filling out with data using progress-4gl. To date, I've been only filling in text fields using the following syntax:
put stream stream1 unform
"^global CHX_SINGLE_CE_PLAN3" skip(0)
"X" skip
CHX_SINGLE_CE_PLAN3 is the field name...
This code works when dealing with text fields but I'm trying to check a box instead of fill in a text field. I cannot find any documentation on this. Is checking a box on a fillable pdf form even possible with 4gl?
As far as I remember PDF Include has support for filling fillable forms. Whilst it's probably a bit over the top in terms of what you want to achieve, it's an open source project and so you may well find the answer to your question within the code itself.
Here's a link to the project page: http://www.oehive.org/pdfinclude
I discovered the answer, which I thought I had already tried before asking this question. The answer is you need to pass the value "Yes" (with capital "Y") in order to check the checkbox. The correct code in this instance is:
put stream stream1 unform
"^global CHX_SINGLE_CE_PLAN3" skip(0)
"Yes" skip
I believe this is the case no matter which language you're using

execCommand insertHTML breaks stored window.getSelection()

When using methods of selecting text and restoring selected text in a page, I have found that running execCommand('insertHTML... inbetween causes the stored selection to break.
This is a sample of how the text is selected and restored.
// Get Selection
var sel = window.getSelection().getRangeAt(0);
// Clear Selections
window.getSelection().removeAllRanges();
// Restore Selection
window.getSelection().addRange(sel)
This works fine, however once you run execCommand('insertHTML.. the selections endOffset sets itself to the same value as the selections startOffset
Is there a reason for this? More importantly is there a way round this?
A full example of the bug, complete with some basic console logging can be seen here.
http://jsfiddle.net/blowsie/Y8pJ7/
The objective of this fiddle is to select text , transform it to uppercase and then reselect the text.
How best to save and restore the selection really depends on what you're doing. For your specific example, where existing text is just having its case transformed, I'd suggest a character index-based approach, such as https://stackoverflow.com/a/5596688/96100 (although that answer requires Rangy, but can be trivially changed not to require it: http://jsfiddle.net/Y8pJ7/8).
For some other cases, a better approach is to use invisible marker elements at the start and end of the selection, which is the approach taken by the selection save/restore module of Rangy (disclosure: I am Rangy's author).
UPDATE 18 June 2012
Rangy now has character offset-based save and restore of selections and ranges via a new TextRange module (demo).

Using VBA in MS Word 2007 to define page elements?

I'd like to be able to create a page element which I can feed text and it will form itself into the preferred layout. For instance:
{MACRO DocumentIntro("Introduction to Business Studies", "FP015", "Teachers' Guide")}
with that as a field, the output should be a line, the first two strings a certain size and font, centred, another line and then the third string fonted, sized and centred.
I know that's sort of TeX-like and perhaps beyond the scope of VBA, but if anyone's got any idea how it might be possible, please tell!
EDIT:
Ok, if I put the required information into Keyword, as part of the document properties, with some kind of unique separator, then that gets that info in, and the info will be unique to each document. Next one puts a bookmark where the stuff is going to be displayed. Then one creates an AutoOpen macro that goes to that bookmark, pulls the relevants out of the keywords, and forms the text appropriately into the bookmark's .Selection.
Is that feasible?
You're certainly on the right track here for a coding solution. However, there is a simpler way with no code - this is the type of scenario that Content Controls in Word 2007 were built for and with Fields/Properties, you can bind to content controls (CC). These CC can hold styles (like centered, bold, etc.). No VBA required.
The very easiest thing to do is to pick 3 built-in document properties that you will always want these to be. For example, "Title" could be your first string, "Subject" your second string and "Keywords" your third. Then, just go to the Insert ribbon, Quick Parts, Document Properties and insert, place and format those how you like. Then go to Word's start button (the orb thingy) and then under Prepare choose Properties. Here you can type, for example "Introduction to Business Studies", into the Title box and then just deselect it somehow (like click in another box). The Content Control for Title will be filled in automatically with your text.
If you want to use this for multiple files, just create this file as a .dotx (after CC insertion/placement/formatting and before updating the Document Properties' text). Then every time all you'll have to do is set these three properties with each new file.
Well, yes, it did turn out to be feasible.
Sub autoopen()
Dim sKeywords As String
sKeywords = ActiveDocument.BuiltInDocumentProperties(4)
ActiveDocument.Bookmarks("foo").Select
Selection.Text = sKeywords
End Sub
Okay, I have some filling out to do, but at least the guts of it are there.