First time question asker - I have searched through the site for questions related to VBSCRIPT, C++, and COM. I have found a couple of threads that I do believe speak to my core question but I was not able to walk away with an absolute.
I have been tasked with writing an automation script for a trucking company that uses PCMIler (which is arguably the most pervasive commercial trip routing tool in the market). The product comes with a tool called PCMiler Connect. PCmiler connect offers various API's to query the database. One of those is COM.
PCMiler is written in C++. I'm trying to accomplish this with VBScript.
The problem I'm having is trying to execute a method that requires 1 argument to be passed by reference. The method takes 4 arguments. It uses 3 of them to calculate the distance in miles from 2 points. The 4th argument is the one passed by reference and the retval is the 'time' in minutes.
Set server = CreateObject("PCMServer.PCMServer")
region = Server.DefaultRegion
Dim dist 'dist is short for Distance
Dim minutes
Dim time
'First Example use standard CalcDistance //THIS FUNCTION WORKS JUST FINE.
dist = server.CalcDistance("63139","62025") 'the passed parameters are Zip Codes
Wscript.Echo "CalcDistance: " & (dist / 10) 'Echo the distance in miles
//THIS EXAMPLE DOES NOT WORK!!!!
'Third Example use CalcDistance3 with a Route Type of 'Practical' (which is the 3rd argument). Pass variable 'minutes' as the return variable.
'Third Example - version 1. Passing the variable 'minutes' by itself - no character to indicate it is being passed by reference.
dist = server.CalcDistance3("63139","37217",1,cLng(time))
I have read in some threads that C++ must return the retval as Variant. This function returns a Long Integer. I can't change this. When I read the log file for PCMiler connect I can see where the retval is being calculated and logged - but VBScript is not picking it up, or it is not being returned correctly?
Ultimately - I'd like to ask someone to tell me If I'm out of look for using VBScript due to the fact I can't alter the C++ method - or if I can find a way to get the value - please help. If not - can someone tell me a better option for what I need to do?
While I have successfully used VBA in Access - this needs to be an automated script running every 30 minutes. I understand Access is not something that can be run reliably as an automated service.
C#?
VB?
Thank you.
Related
This might be similar to this question (pre_limit_mult in synth_runner package stata does not work), However, I ask this because I could not find any useful tips from the link.
I am trying to use the pre_limit_mult(real) option to limit the placebo effects in the pool for inference. The ultimate purpose is to test the validity of estimation of the economic impact of the coup in Gambia in 1994.
However, even though I follow the practice as the guidebook explains, the command does not work and present the message like the following.
tsset country_id year
synth rgdpe pop rconna csh_i csh_x rgdpe(1971) rgdpe(1982) rgdpe(1993), trunit(21) trperiod(1994) keep("Gambia_outout") replace fig
local K = 2
synth_runner rgdpe pop rconna csh_i csh_x rgdpe(1971) rgdpe(1982) rgdpe(1993), trunit(21) trperiod(1994) keep("Gambia_outout") replace gen_vars pre_limit_mult(`K')
single_treatment_graphs, trlinediff(-1) raw_gname( rgdpe_raw) effects_gname(rgdpe_effects) effects_ylabels(-1500(750)1500) effects_ymax(2000) effects_ymin(-2000) do_color(bluishgray)
With -, gen_vars- the program needs to be able create the following variables: lead rgdpe_sy nth effect pre_rmspe post_rmspe. Please make sure there are no such varaibles and that the dependent variable [rgdpe] has a short enough name that the generated vars are not too long (usually a max of 32 characters)
I received this message.
With -, gen_vars- the program needs to be able create the following variables: lead rgdpe_synth effect pre_rmspe post_rmspe.
Please make sure there are no such varaibles and that the dependent variable [rgdpe] has a short enough name that the generated vars are not too long (usually a max of 32 characters).
Please download the input data and dofile from the following link (I could not find the way to directly attach the file in stackoverflow).
(https://drive.google.com/drive/folders/1VyP2GN3NfQT6jQ9enbCvE2VTVNxZdPgc?usp=sharing)
Does anyone know how to fix it?
I have a port 'Number_1' in expression transformation in Informatica. I connected the Number_1 port to a target sql table. I need to generate number for this port 'Number_1' every time i run the mapping starting from 1 till 999. once it reaches 999 then again the value of the Number_1 should reset to 1. I'm aware there is sequence generator trans. but i need to call Sequence function from SQL server. how to achieve above?
Create a stored procedure in sql server then use stored procedure tranformation to call this from Informatica
You may call it using Stored Procedure transfomation. You may also use a stored procedure as SQL Override on Source Qualifier, however...
I hope you know what you're doing, as this is in general a very bad idea. Each call requires communication between Intergration Service and database - this will cause huge delays. Therefore it's much better to use Informatica's Sequence Generator or - even better perhaps, if all you need is an integer port with round robin - a simple expression variable.
While maciejg says makes a lot of sense performance wise - however I've known a fair few people who were more comfortable using the native database sequencer than the inbuilt one ( even some Informatica specialists ).
The thing with Informatica sequencer is how much flexibility they give and when they get set wrong it can lead to unexpected numbers being picked.
One example I have is for a sequencer being used to create unique keys in a table - if you persist the value between sessions then it works fine until you select the incorrect option while reimporting the mapping.
If you choose to lookup your previous ending value from a config file / table and add the value produced by the sequencer to this then one day when someone by mistake sets the sequencer to persist values between runs you'll all of a sudden skip that many numbers in the sequence each time the session is restarted. Native db sequencers are very basic making them very predictable and fool proof
I use Stata since several years now, along with other languages like R.
Stata is great, but there is one thing that annoys me : the generate/replace behaviour, and especially the "... already defined" error.
It means that if we want to run a piece of code twice, if this piece of code contains the definition of a variable, this definition needs 2 lines :
capture drop foo
generate foo = ...
While it takes just one line in other languages such as R.
So is there another way to define variables that combines "generate" and "replace" in one command ?
I am unaware of any way to do this directly. Further, as #Roberto's comment implies, there are reasons simply issuing a generate command will not overwrite (see: replace) the contents of a variable.
To be able to do this while maintaining data integrity, you would need to issue two separate commands as your question points out (explicitly dropping the existing variable before generating the new one) - I see this as method in which Stata forces the user to be clear about his/her intentions.
It might be noted that Stata is not alone in this regard. SQL Server, for example, requires the user drop an existing table before creating a table with the same name (in the same database), does not allow multiple columns with the same name in a table, etc. and all for good reason.
However, if you are really set on being able to issue a one-liner in Stata to do what you desire, you could write a very simple program. The following should get you started:
program mkvar
version 13
syntax anything=exp [if] [in]
capture confirm variable `anything'
if !_rc {
drop `anything'
}
generate `anything' `exp' `if' `in'
end
You then would naturally save the program to mkvar.ado in a directory that Stata would find (i.e., C:\ado\personal\ on Windows. If you are unsure, type sysdir), and call it using:
mkvar newvar=expression [if] [in]
Now, I haven't tested the above code much so you may have to do a bit of de-bugging, but it has worked fine in the examples I've tried.
On a closing note, I'd advise you to exercise caution when doing this - certainly you will want to be vigilant with regard to altering your data, retain a copy of your raw data while a do file manipulates the data in memory, etc.
We’re using JCo 3.0 to connect to RFCs and read data from SAP R/3. We use one RFC RFC_READ_TABLE often and use a second custom RFC to read employee information. My questions revolve around a third RFC RSAQ_REMOTE_QUERY_CALL. I'm calling an ad-hoc query I built in SAP using this RFC but I’m not getting the expected results. The main problem is that it appears that SAP is ignoring one of my selection criteria and using what was saved in SAP when I originally built it. The date criterion stored in my ad-hoc is 6/23/2013. If I pass in 6/28/2013 from JCo, I get the same results as if I had passed 6/23/2013 from JCo.
We have built several ad-hoc queries whose only criteria is a personnel number and call them successfully using RFC RSAQ_REMOTE_QUERY_CALL.
Background on my ad-hoc query: reporting period of today, joining together four aspects of an employee’s information: their latest action (hire, rehire, etc.), organization (e.g. company), pay (e.g. pay scale level) and communication (e.g. email). The query will run every workday.
Here are my questions:
My ad-hoc has three selection criteria. The first two are simple strings. The third is a date. The date will vary each time the query runs. We are referencing the first criteria using SP$00001, the second with SP$00002 and the third with SP$00003. The order of the criteria changes from the ad-hoc to SQ01 (what was SP$00001 in the ad-hoc is now SP$00003). Shouldn’t we reference them in the order defined in the ad-hoc (e.g. SP$00001)?
The two simple string selections are using OPTION “EQ”. The date criteria is using OPTION GT (greater than). Is “GT” correct?
We have some limited accessibility to SAP. Is there a way to see which SP$ parameters are mapped to which criteria?
If my ad-hoc was saved with five criteria but four of them never change when I call the ad-hoc from JCo, do I just need to set the value of the one or do I need to set the other four as well?
Do I have to call this ad-hoc using a variant (function.getImportParameterList().setValue(“VARIANT”, “VARIANT_NAME”))?
Does the Reporting Period have an impact on the date criteria? I have tried changing the Reporting Period to be PNPBEGDA = today and PNPENDDA = today and noticed no change.
Is there a way in SAP to get a “declaration” of your ad-hoc (name, inputs, outputs, criteria)? I have looked at JCoFunction.toXml() and JCoFunctionTemplate. These are good if you want to see something at runtime before it goes to SAP, but I’m looking for something I can use on the JCo end to help me write Java code that matches the ad-hoc.
I have looked at length on the web for answers to my questions and have not found anything that is useful. If there is anything which would help me, please let me know.
Thanks,
LM
Since I don't know much about SQnn, I won't be able to answer all of your questions...
I don't know, sorry.
It should be, at least it's the usual operator for greater than.
Yes - set an external breakpoint right inside the function module and trace its execution while performing the RFC call. Warning: At least basic ABAP knowledge required.
I don't know, sorry.
I don't know either, sorry.
That would depend on the query, I suspect...
JCo won't be able to help you out there - it doesn't know about queries, it only knows function modules. There might be other RSAQ_* function modules to get that information though.
I played with setting up a variant in SQ01 for my query. I added some settings in the variant that solved my problem and answered several of my questions in my post. The main thing I did was add a dynamically calculated date as part of my criteria. Here's how:
1. In SQ01, access menu "Go To" -> "Maintain Variants".
2. Choose your variant and in subobjects, choose "Attributes" and click "Change".
3. In the displayed list, find your date criterion.
4. Choose "D" in Selection Variable, choose a comparison option (mine was GT for greater than), and a "Name of a Variable" (really, this is the type of dynamic date calculation you need).
5. Go back to the Subobjects panel, choose "Values" and click "Change".
6. Enter any other criteria you need in the "Program selections" section.
7. Save the variant.
By doing this, I don't need to pass anything into the query from JCo. Also, SAP will automatically update the date criteria you entered in step #4 above.
So to to answer my questions from my original post:
1 and 4. It doesn't matter because I'm no longer passing anything in from JCo.
2. "GT" is Greater Than.
3 and 7. If anyone knows, I'd really like to find out.
5. Use the name you as it is in SAP (step #2 above).
6. I still don't know, but it's not holding me up.
I'm posting this in case anyone out there needs this type of information. Thanks to Esti and vwegert for helping me out.
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.