Searching for {time} in a message template, without having the workbook parse it as a parameter - azure-monitoring

I want to create an azure monitor workbook that lets me search for specific message templates. Usually, these message templates contain placeholders. For example:
logger.LogInformation("Finished executing, took {time}ms", time);
Problem is though, if I include the placeholder in the query string for a workbook, it will fail since it considers the placeholder a parameter for the workbook. A very small example can be seen underneath.
AppTraces
| where Properties.MessageTemplate == 'Finished executing, took {time}ms'
This will give me the following error message:
This query could not run because some parameters are not set.
Please set: time
I can't seem to figure out how to escape these characters, since this is not actually related to the kusto language, but more of an issue with the workbook. Can someone please advise?

Unfortunately, we don't (yet) have an escape sequence for parameters in workbooks.
As a workaround, what you can do is split it up so workbooks doesn't detect it as a parameter, something like strcat('Finished executing, took {', 'time}ms'

Related

Adding a hyperlink with VBA--coding syntax

I am trying to add a hyperlink to the workbook data is pulled from to a summary workbook. I can get the filepath to populate the cell no problem but when I enter hyperlink.add I usually get a parameter error.
This provides me with the URL in the selected cell:
.offset(rowcount,112)=sXLFile
I tried this to add a hyperlink but I get a parameter error with the second comma after 'sXLFile' being highlighted:
hyperlinks.Add (anchor:=.Offset(rowcount, 112), address:= sXLFile,,, incidentreport & agentname)
What I think this could would do is make a hyperlink to the filepath saved in sXLFile and read as IncidentReportAgentName. When I reference the exact workbook/sheet in the code below I get a runtime error 13: Type Mismatch.
Workbooks("Incident Reports").Worksheets("Supplementary").Hyperlink.Add anchor:=.Offset(rowcount, 112), Address:=sXLFile, TextToDisplay:=IncidentReport & AgentName
Does anyone see what I am doing wrong?
You've got a couple things going on. You're trying to accomplish too much at once, so we'll need to take a step back.
First issue - you said:
When looking at the arguments needed for the Hyperlink.Add, I didn't want to add a subaddress or screentip and these are optional arguments. I thought I still needed to use the "," as a placemark for those arguments.
Parameters for functions can be entered one of two ways:
FunctionName Parameter1Name:=Parameter1Value, Parameter2Name:=Parameter2Value, Parameter3Name:=Parameter3Value
...is equivalent to:
FunctionName Parameter1Value, Parameter2Value, Parameter3Value
...however the purpose of using the Parameter1Name:= is so that you can skip parameters or include them out-of-order without a problem.
So this:
FunctionName Parameter1Value, , Parameter3Value
...is the same as:
FunctionName Parameter1Name:=Parameter1Value, Parameter3Name:=Parameter3Value
...which is also the same as:
FunctionName Parameter3Name:=Parameter3Value, Parameter1Name:=Parameter1Value
Therefore, when you're specifying parameters with :=, do not add additional commas for missing parameters.
Troubleshooting 101
If the correction above still does not solve you problem try this.
A couple early steps in troubleshooting should be:
Replace all variables and referenced values with the actual values. For example: instead of referring to an Offset to reference the location of the anchor, specify the actual range.
So instead of anchor:=.Offset(rowcount, 112), specify anchor:=Range("A1") or whatever cell the link is supposed to be in.
Instead of address:= sXLFile, use address:= "http://www.google.com (or wherever the destination address is.
Simplify the expression as much as possible to get the basic functionality working. For example, you don't need the "TextToDisplay" label right now to make your link work. Get rid of it, temporarily.
So after those changes, your entire line should be a nice, simplified and functioning:
Workbooks("Incident Reports").Worksheets("Supplementary").Hyperlink.Add Anchor:=Range("A1"), Address:= "http://www.google.com"
If that's indeed doing what it is supposed to, now you can start changing the values to variables and adding more parameters... but make a single change, and then test it. Then make the next change, and test it. One change at a time.
More Information:
MSDN : Hyperlinks.Add Method (Excel)
Chip Pearson : Debugging VBA

Is it possible to copy the contents of the Immediate window in Excel VBA?

Question
I would like to know whether it is possible to copy or extract the contents of the Immediate window in Excel VBA, so I can store it somewhere. I already know you can copy and paste from the window manually, I am interested in whether it is possible to do it with code (preferably in VBA itself).
Explanation
Questions similar to this have been asked a few times on SO (e.g. this and this), no-one has given a definitive answer and I was unable to find one from a quick search. Most of the time, answers respond asking why anyone would want to do that, and give ways to get around it in the circumstances provided in the question (e.g. how to output messages to a file or cell range). Given this, I have thought of a couple of example scenarios where someone might want to do this and cannot (easily) get around it.
Example scenarios
A) I am developing a large workbook including a large set of macros, debugging as I go. This includes using debug.print statements and directly querying in the Immediate window, e.g. ? myVar. At the end of the session, I would like to be able to automatically copy the contents of the immediate window into a log file, so I know what happened during my debug session afterwards. This could, for example, make use of the Workbook_BeforeClose event procedure.
B) I am working with two workbooks that contain VBA projects - one I can't edit, another that I can and am working on. The one I can't edit outputs debug information to the immediate window via debug.print that I would like to store somewhere (but I don't really care where).
Disclaimer
I ask this question purely out of curiosity. I suspect I already know the answer (it's not possible to do this), but I am not sure.
Yes-- but not with control-c .... select what you need and then drag and drop
1-Create a sheet named "debug.print"
2-Hide it:
Sheets("debug.print").Visible = 2 'xlSheetVeryHidden, only can be visible with vba
3-Create this function:
Function debug_print(c As String)
ThisWorkbook.Sheets("debug.print").[a1048576].End(xlUp).Offset(1).Value = c
Debug.Print c
End Function
4-Replace your codes "debug.print" to "debug_print"
5-Example:
Sub blablabla()
debug_print "i am doing whatever"
End Sub
But: Using "?" in the immediate window will not save
There is many ways to export this as file now like CSV, TXT, save in SQL etc...

Inconsistent recognition of ranges (No errors thrown)

This is code from Excel 2010. All of the code resides within the workbook itself. Information is gathered using internal forms and the code is run.
I have code that retrieves data from a spreadsheet and populates an object with that data. The row number is dynamic as it is dependent on the form input. The column is by the header, not the column number. The following code works perfectly but for two anomalies:
cTank.RowForTankSpecs = rNum
cTank.MP = .Cells(rNum, Range("MP").Column).Value
cTank.Form = .Cells(rNum, Range("formName").Column).Value
cTank.TankProcess = .Cells(rNum, Range("Process").Column).Value
cTank.Location = .Cells(rNum, Range("Location").Column).Value
cTank.TankName = .Cells(rNum, Range("Tanks").Column).Value
cTank.tankID = .Cells(rNum, Range("TankID").Column).Value
First:
The cTank.TankName is retrieving information from a column named "Tanks". That column does not exist. The actual column header is "Tank". But, it is retrieving the correct information. If I change the name to what it really is (Tank), it does not work.
Second:
When the cTank.TankID line is executed, I get the following error on the Range("TankID"):
Runtime Error 1004: Method 'Range' of object '_Global' failed
This one has the appropriate header (column header), but it is not recognizing the range.
I have tried simple things such as changing the order of the code, but it doesn't help. As earlier stated, the other lines work. Later in the program, information is gathered in the same manner but using another worksheet from the same workbook, and none of them are working. I've double checked that strings are strings and integers are integers, etc. I've double checked the column headers match the range names. Nothing seems to jump out at me.
I would appreciate any input you may have on the situation.
Thanks in advance.
Steve
Ok. Being pretty sure my code was correct, I went to the spreadsheet itself. For some reason it was recognizing only certain columns and it was recognizing one of them incorrectly. So I started highlighting the columns that worked and also the columns that didn't. What I noticed was that on the columns that were being recognized, that column header was displayed where the cell location is normally displayed whereas on the columns that were not being recognized, the cell location (i.e. A1, A2, etc.) for the header was being displayed and not the header title itself. The incorrect label was showing up for one of them. As it turns out, the mislabeled column was one that I had used for a form dropdown menu. So, I checked the name manager, and the ones that were working were listed. So anyway, using the name manager, I added named ranges using the headers. Now, when I select the columns, the column header(named range) appears in that window and now, the code works.
Thanks guys for your input. I really appreciate it.
Two things you can do:
Do not use use Range, but as it seems you are using names, use Names("Yourname").Referstorange.
OR
Make sure your names are set up correctly using the Name Manager in Data Ribbon.

Google Apps Script on Form Submit Time Formatting Glitch/Fix

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

Word VBA - Load part of doc into variable, and run .indexOf to search

Okay, I am a Javascript programmer and VBA is driving me insane - I know nothing about it and it is like pulling teeth to find simple documentation on the simplest thing.
I'm literally trying to run a little script to auto-format a document, partly based in content.
I want to grab the third line of document, or first 100 characters, I really don't care, and run the equivalent of String().indexOf('foobar') on it, to check if that part of the document contains a string.
I cannot for the life of me find how to:
a. Load text selection into a variable.
b. Run a sane semblance to indexOf.
Can someone please help? And maybe point me to a sane VBA documentation that is not Micrsoft?
a. Load text selection into a variable.
Identify a range (Word.Range) you want and get the Text property of that range.
For instance,
dim s as string
s = ThisDocument.Paragraphs(3).Range.Text
b. Run a sane semblance to indexOf.
Is InStr no good?
msgbox InStr(s, "foobar")