ListObjects.Add.QueryTable Source Array String - vba

I will provide some context before I ask my question.
I am attempting to query an SQL Server and create a table within Excel from the data. Because I am not familiar with how to accomplish this in VBA I recorded by using Data -> Get External Data -> From Other Sources -> Microsoft Query. In the dialog box that appears, I chose a .DSN file provided to me by someone else. I then used the Microsoft Query interface to structure the query and import the data onto a worksheet.
The code in the recorded macro looked something like this. I will use generic terms instead of the actual code.
With Sheet2.ListObjects.Add(SourceType:= 0, Source:=Array _
(Array("ODBC;DRIVER=SQL Server;SERVER=ServerName;UID=userid;Trusted_Connection=Yes;APP=Microsoft Windows Operating System;WSID=SomeString"), _
Array("A;DATABASE=DatabaseName")), Destination:=Range ("Sheet2!$A$1")).QueryTable
I know this is not formatted ideally, which is part of my question below.
https://msdn.microsoft.com/en-us/library/bb211863(v=office.12).aspx
From the above article, I know that SourceType:= 0 is an xlSrcExternal, or an external data source. This makes sense to me.
My confusion begins to arise when I get to the Source component of the Add method. From the provided article, "When SourceType = xlSrcExternal, an array of String values specifying a connection to the source, containing the following elements:
•0 - URL to SharePoint site
•1 - ListName
•2 - ViewGUID
So to begin with, what exactly is meant by "an array of String values", as the code from the recorded macro does not appear to correspond to what I thought was an array. I know that normally an array is declared something like this Array("string1", "string2", etc.). Or is the array recorded simply an array of one value? In other words Array("string1"). Does anyone know the purpose of passing an "array of string values" as opposed to just passing a string?
Also does anyone know the nuances of why the recorded macro has this particular formatting/syntax? In other words, why does it appear to have this syntax Array(Array("string1"),_ (new line) Array("string2"))? Why not just Array ("string1")? Does it have something to do with the second line being too long?
I have several more questions related to this topic, but this seemed like a good place to start..
Thank you all for any help given.

Related

Meaning of (052) at the end of text literal?

Really just a curious question.
Here are a few examples of the same concern that I have since they are being exported to the FM "REUSE_ALV_GRID_DISPLAY" for parameter "it_fieldcat".
ls_fieldcat-seltext_l = 'Material number'(052).
ls_fieldcat-seltext_m = 'Material'(053).
ls_fieldcat-seltext_s = 'Mat.'(054).
I tried removing the numbers on the right and executed the program but I didn't see any differences and I also tried to see what happens inside debug mode but it only fills the field with the string value, am I missing something or is there something that I wasn't able to notice?
I've been tasked to create a copy of a program which originally joins multiple tables and filters them according to the Parameters from the SELECTION-SCREEN and then shows the results in an ALV Grid Report, but for the use case of the copy it should instead populate a table in ECC that we will then be replicating to BW side. I have successfully copied and modified it accordingly but I can't seem to understand what the numbers beside the strings are doing.
Can someone please explain what their use is, would be very grateful to see a few examples.
Thanks!
The number in the brackets is a text symbol defined as a part of the text elements of the program. Using the syntax 'Literal'(idf) replaces these literals in the program if the symbol is in the currently loaded text pool.

LabVIEW Inserting/overwriting text into existing string

I was wondering if folks have found a reliable way to inject text into an existing string. Some context, I'm writing data to a string indicator formatted like a table, and I wanted to inject values into so they maintain a specific format, spacing-wise. Writing to a table would definitely be easier, however I am porting a legacy program and wanted to provide familiarity to the end user.
Essentially, I want to do the equivalent of typing into a .txt file with the INSERT function enabled, where it just overwrites the content already in the string. Example below (dashes added to show spacing) of how it is currently looking when I inject the values with hard coded spacing:
Time---value---avg. value---result
60------10---------20---------PASS
120------11---------20---------PASS
180------9---------15---------FAIL
I'd prefer it to look more lined up, like below:
Time---value---avg. value---result
60------10---------20---------PASS
120-----11---------20---------PASS
180-----9--------- 15---------FAIL
Writing my application using LabVIEW 2019
Edit: Header will obviously not change, only each subsequent line where the values can result in entries not looking lined up
What about "Replace Substring" function (https://zone.ni.com/reference/en-XX/help/371361R-01/glang/replace_substring/)? Doesn't it meet your requirements?
The diagram below outputs 01234999990123PASS890123456789. The values of the integer and the word PASS are added replacing characters in the existing string, exactly like overstrike would do.

Getting the values of an /AIF/ERR variant

I did try using the RS_VARIANT_CONTENTS and RS_VARIANT_VALUES_TECH_DATA, it did show the values of the variant except the values of the name space, interface and interface version in which I also need to retrieve. I also searched the VARI* and TVARC tables but I didn't found it there.
I think it has something to do with the program name and screen number. Do you have any ideas or other way that I can retrieve all those values, whether using FM or select?
Thank you.
Some of the parameters in the transaction /AIF/ERR, the ones you are talking about, vary dynamically based on the value chosen in the Application screen field. They are handled by another AIF program, and they are not saved in the program variant, but in the table /AIF/T_ERR_VARS.
You may call the function module /AIF/ERR_VAR_LOAD to load the missing parameters.
Its usage is shown in the subroutine GET_VAR of the program /AIF/ERROR_HANDLING_TRANS (which is the program behind the transaction /AIF/ERR).

how do you flatten and unflatten an array of doubles in labview?

I have created a simple LabView program shown below that attempts to flatten an array [1,0,3] and then unflatten it and print out the contents.
However, I am unsuccessful in doing so. What am I doing wrong?
What am I doing wrong?
You're not going through tutorials or you're not reading the context help for the unflatten function (Ctrl+H) or you're not reading the full help for the function (right click>>Help) or you're not looking at the examples (from the help or Help>>Find Examples). Take your pick (preferably all four).
If you want an actual answer it is that LV is strictly typed, and therefore you need to tell the unflatten function which data type you want it to output (1D DBL array) and you're not doing that, but the real answer is what's in the previous paragraph - you should use those tools to learn how to find such an answer yourself.
The string returned by Flatten to String only contains the data, not the description of what data type was passed in, so in order to unflatten it again you need to tell Unflatten from String what type it was. You do this by wiring some data of the appropriate type (any data - if it's an array it can be an empty one) to the Type terminal.
I don't think this is immediately obvious from the LabVIEW 2012 help but I think it's fairly clear if you follow the link from the Unflatten from String help page to one of the examples. The Read Flattened Data.vi example has an array wired to the Type input.

Execute coldfusion code stored in a string dynamically?

I have an email body stored as a string in a database, something like this:
This is an email body containing lots of different variables. Dear #name#, <br/> Please contact #representativeName# for further details.
I pull this field from the database using a stored proc, and then I want to evaluate it on the coldfusion side, so that instead of "#name#", it will insert the value of the name variable.
I've tried using evaluate, but that only seems to work if there's just a variable name. It throws an error because of the other text.
(I can't just use placeholders and a find/replace like this - Resolving variables inside a Coldfusion string, because the whole point of storing this in a database is that the variables used to build the string are dynamic. For example, in one case the name field can be called "name" and in another it could be "firstName", etc.)
I would loop over each #variableName# reference and replace it with the evaluated version.
A regex will be able to find them all and then a loop to go over them all and just evaluate them one by one.
You need to write it to a file and CFINCLUDE it. This will incur a compilation overhead, but that's unavoidable.
Can you not save the code to the file system and just store a reference to where it is in the DB? That way it'll only get recompiled when it changes, rather than every time you come to use it?
<!--- pseudo code --->
<cfquery name="q">
SELECT fileContent // [etc]
</cfquery>
<cfset fileWrite(expandPath("/path/to/file/to/write/code.cfm"), q.fileContent)>
<cfinclude template="/path/to/file/to/write/code.cfm">
<cfset fileDelete(expandPath("/path/to/file/to/write/code.cfm"))>
That's the basic idea: get the code, write the code, include the code, delete the code. Although you'll want to make sure the file that gets created doesn't collide with any other file (use a UUID as the file name, or something, as per someone else's suggestion).
You're also gonna want to load test this. I doubt it'll perform very well. Others have suggested using the virtual file system, but I am not so sure there'll be much of a gain there: it's the compilation process that takes the time, not the actual file ops. But it's worth investigating.
Are you using ColdFusion 9 or Railo? If yes, writing to and including in-memory files may be quick and simple solution. Just generate file name with something like CreateUUID() to avoid collisions.
So basically, after researching and reading the answers, it seems that these are my options:
Have separate fields in the table for each variable and evaluate them individually. e.g. nameVariable, reprNameVariable, and then I can build the body with code like this:
This is an email body containing lots of different variables. Dear #evaluate(nameVariable)#, <br/> Please contact #evaluate(reprNameVariable)# for further details.
Have an "emailBody" field with all the text and applicable field names, and write it to a temporary file and cfinclude it. (As suggested by Adam Cameron, and I think that's what Sergii's getting at)
Have an "emailBody" field and write code to loop over it, find all coldfusion variables, and replace them with their "evaluate"d version. (As suggested by Dale Fraser)
Have small template files, one for each report type, with the email body, and have a field "emailBodyTemplate" that indicates which template to include. (As suggested by Adam Cameron)
Now I just have to decide which to use :) When I do, I'll accept the answer of the person who suggested that method (unless it's one that wasn't suggested, in which case I'll probably accept this, or if someone comes up with another method that makes more sense)
It's been a while since you posted this - but it's EXACTLY what I do. I found your question while looking for something else.
I've simply created my own simple syntax for variables when I write my emails into the database:
Hello ~FirstName~ ~LastName~,
Then, in my sending cfm file, I pull the email text from the database, and save it to a variable:
<cfset EmailBody = mydatabasequery.HTMLBody>
Then I quickly strip my own syntax with my variables (from another query called RecipientList):
<cfset EmailBody = ReplaceNoCase(EmailBody, "~FirstName~", "#RecipientList.First#", "ALL")>
<cfset EmailBody = ReplaceNoCase(EmailBody, "~LastName~", "#RecipientList.Last#", "ALL")>
Then I simply send my email:
<cfmail ....>#EmailBody#</cfmail>
I hope you manage to see this. If you control the authoring of the email messages, which I suspect you do, this should work well.
Russell