Passing array from Java to VBScript - excel

I have two questions:
1. If we can pass an array to VBSCript using java. I am able to pass single variables to VBSCript using following command
Runtime.getRuntime().exec("wscript openChartsDevice.vbs " + fileName + " " + range);
But when I pass a String array, it says type mismatch. I am catching the array passed in
Dim arr()
any Suggestions?
Edit 1 Following question has been answered
2. I am using following Vbscript to create chart in excel
Dim oExl,excelPath,objWriteSheet,objWriteWorkbook
Dim oMychartProcs
Set oExl=CreateObject("Excel.Application")
Set objWriteWorkbook = oExl.Workbooks.Open("SomeExcelfile.xlsx")
Set objWriteSheet = objWriteWorkbook.Worksheets(1)
Set oMychartProcs = objWriteWorkbook.Charts.Add
oMychartProcs.SetSourceData objWriteSheet.Range(Cells(2,1),Cells(7,6))
oMychartProcs.ChartType = 4
oMychartProcs.Name = "ChartName"
oMychartProcs.Activate
I have given the range as A2:F7. when I enter
oMychartProcs.SetSourceData objWriteSheet.Range("A2:F7")
the chart is created perfectly but when I use the
Range(Cells(2,1),Cells(7,6))
whole excel sheet is converted to chart.
I want to provide the range through parameters so I want above formula to work. I've searched a lot and could not find a definitive way for it. Thank you.

You can not pass array as an object. But you can pass its elements as string parameters to the vbscript function with a space as the delimiter.
openChartsDevice.vbs " + fileName + " " + arg[0] + " " + arg[1] + " " + arg[2].....
You can a create a method in java to pass an array and return a string
arg[0] + " " + arg[1] + " " + arg[2].....
Another Approach: Create a file with input parameters. Update your VBScript to refer to that input file to get the parameters instead of looking for command line arguments.

I don't know JScript. But the way to get in VBScript the same thing.
For Each thing in Array()
A = A & thing & " "
Next
You are actually asking how to turn an array into a delimited string not a vbscript array.
See this article which your question title implies you are interested in.
http://blogs.msdn.com/b/ericlippert/archive/2003/09/22/53061.aspx

Related

how to write query with function inside it in access vba?

Lets suppose, vba code has
Dim SQL as String
SQL ="select * from table"
I found function that helps to combine values from related rows into a single concatenated string value.But when i implemented to my code it didn't work because double quotation inside query creating errors.What could be best format to make syntax valid in vba.The function is given below and link is (Combine values from related rows into a single concatenated string value).
SELECT
i.N_ID,
i.F_Name,
i.L_Name,
ConcatRelated(
"Course_ID",
"tbl_Courses",
"N_ID = '" & [N_ID] & "'"
) AS Course_IDs
FROM tbl_Instructors AS i;
Most likely, your ID is numeric, not text, thus no single-quotes:
SELECT
i.N_ID,
i.F_Name,
i.L_Name,
ConcatRelated(
"Course_ID",
"tbl_Courses",
"N_ID = " & [N_ID] & ""
) AS Course_IDs
FROM tbl_Instructors AS i;

Importing Excel and using it for Stata do code

For example, suppose I have this Excel file.
Then, I am manually putting things on Excel into do file like this.
replace A = 1 if B>=1 & B<=6
replace A = 2 if B>=23 & B<=2
replace A = 3 if B>=3 & B<=1
replace A = 4 if B>=5 & B<=3
If this wasn't clear, please see this image to see what I am doing.
But there could be actually hundreds of lines.
How can write a short code which imports the Excel file, and another short code which replaces the manual codes I have written?
So the goal here is just to make my code succinct.
You can import excel this file. Let's suppose the headers are A and B and the import produces those as numeric variables. Then the text of a new do-file is contained within
gen text = "replace A = " + string(_n) + " if inrange(A, " + string(A) + "," + string(B) + ")"
which you must export and then run on your real data.
Not tested. I'd also suggest considering doing this in your favourite text editor.
Note that many of your comparisons in your example will always be false.

sudden change in string value during a browse value change

During a Value-Change inside a browse, my string value suddenly changes, specifically the string(9) will change to string(0).
sample:
in my combo-box, i used a list-item-pair with following code:
cb-name:LIST-ITEM-PAIRS = ?.
cb-name:DELIMITER = '?'.
FOR EACH employee WHERE employee.date-resigned = ? NO-LOCK BY employee.employee-no.
cb-name:ADD-LAST(TRIM(STRING(employee.employee-no, '99999999') + " - " + employee.last-name + ", " + employee.first-name + " " + SUBSTRING(employee.middle-name,1,1)) + ".",employee.employee-no).
END.
cb-name:SCREEN-VALUE = cb-name:ENTRY(1).
in the value-changed of browse:
ASSIGN cb-name:SCREEN-VALUE =
STRING(TRIM(STRING(employee.employee-no, '99999999') + " - " + employee.last-name + ", " + employee.first-name + " " + SUBSTRING(employee.middle-name,1,1)) + "." ,
STRING(employee.employee-no, '99999999')).
if the employee no has a string value of 9, progress will change it to 0.. producing an error message that has an invalid value..
ex: from 819001 /*correct*/ to 810001 /*incorrect*/
if there is no string(9), it will display like:818002
if i message the STRING(employee.employee-no, '99999999')), it will display the correct string value
Version doesn't matter in this case, apparently. I just simulated it in 10.2B08 using a temp-table with the named tables. The problem is when you're assigning the screen-value to the combo you're trying to convert the whole string (employee-no + names + separators) into format 99999999.
Since your combo is list-item-pairs
('Whatever I want it to display','the real value',
'and so on display' , 'and so forth value')
your solution is to assign the screen value just to the real value, disregard the label. In other words, as simple as changing your value-changed code to
ASSIGN cb-name:SCREEN-VALUE = STRING(employee.employee-no, '99999999') .
It worked for me. Let me know if you are still having trouble with it.

Finding multiple instance of a variable length string in a string

I'm trying to extract my parameters from my SQL query to build my xml for an SSRS report. I want to be able to copy/paste my SQL into Excel, look through the code and find all instances of '#' and the appropriate parameter attached to it. These paramaters will ultimately be copied and pasted to another sheet for further use. So for example:
where DateField between #FromDate and #ToDate
and (BalanceFiled between #BalanceFrom and #BalanceTo
OR BalancdField = #BalanceFrom)
I know I can use Instr to find the starting position of the first '#' in a line but how then do I go about extracting the rest of the parameter name (which varies) and also, in the first two lines of the example, finding the second parameter and extracting it's variable lenght? I've also tried using the .Find method which I've been able to copy the whole line over but not just the parameters.
I might approach this problem like so:
Remove characters that are not surrounded by spaces, but do not
belong. In your example, the parentheses need to be removed.
Split the text using the space as a delimiter.
For each element in the split array, check the first character.
If it is "#", then the parameter is found, and it is the entire value in that part of the array.
My user-defined function looks something like this:
Public Function GetParameters(ByRef rsSQL As String) As String
Dim sWords() As String
Dim s As Variant
Dim sResult As String
'remove parentheses and split at space
sWords = Split(Replace(Replace(rsSQL, ")", ""), "(", ""), " ")
'find parameters
For Each s In sWords
If Left$(s, 1) = "#" Then
sResult = sResult & s & ", "
End If
Next s
'remove extra comma from list
If sResult <> "" Then
sResult = Left$(sResult, Len(sResult) - 2)
End If
GetParameters = sResult
End Function

Excel VBA Object Required ERROR

I have two lines of code that seems extremely easy, but excel keeps giving me this Compile error telling me that object is required?
So basically I want to get the current time, and replace the spaces with underscores so I can use this string as the name of my log fime.
Dim name As String
'EXCEL GIVE ME compile error: object required
name = Replace(FormatDateTime(Now, DateFormat.LONGTIME), " ", "_")
What's wrong?!!
Replacing DateFormat.LONGTIME to 'vbLongTime' works for me.
name = Replace(FormatDateTime(Now, vbLongTime), " ", "_")
You need to invoke Now as it is not a variable but a procedure
var now = str(Now());
name = Replace(FormatDateTime(now, DateFormat.LONGTIME), " ", "_")
should fix it

Resources