Basic dialect, what language is this? - basic

I'm using Concerto post processing app from AVL and I'm having hard time with scripting language we use here. It looks like MS visual basic but not that much and I want to know more about what version of Basic is this, so that I can find more documentation on the web.
When I try code from MS Visual Basic documentation site, like generating int array and puting some elements to initialize it (as you can see below), I got syntax error on Concerto Scripting editor
' Declare a single-dimension array and set its 4 values.
Dim numbers = New Integer() {1, 2, 4, 8}
This is from Concerto's own documentation and I cannot find how to create a simple array but Dataset istead, which is something similar I beleive
NewDSArray
This function generates a new array.
Syntax:
A = NewDSArray([Rows], [Columns])
Parameters:
Rows (optional, 1 = default): Numeric initial number of lines
Columns (optional, 0 = default): Numeric initial number of columns
Function:
A is now a new array with which the Dataset Array class commands can be used.
thisDSMatrix=newdsarray(1,2)
FirstCol={1,2,3}
FirstCol.name="FirstCol" //.name will pass the name into the matrix
thisDSMatrix.PutCell(FirstCol,1,1)
SecondCol={4,5,6}
SecondCol.name="SecondCol"
thisDSMatrix.PutCell(SecondCol,1,2)
Mcols=thisDSMatrix.ColCount //returns 2
Mrows=thisDSMatrix.RowCount //returns 1
thisDSMatrix.AddColumn("MyNewCol") //a column is added and thisDSMatrix.ColCount will now show 3
thisDSMatrix.PutCell({7,8,9},1,thisDSMatrix.ColCount)
return thisDSMatrix
I appreciate if you can help me to spot exact version of Basic Concerto uses. Thank you.

We had basically the same issue and because I didn't want to learn a proprietary language I dicided to go with Python. AVL Concerto provides from version V5.x onwards a Python-API. Despite that the API is not perfect from my point of view, this might be an alternative to the Concerto scripting language. And learning Python will thertenly the better solution.

Related

How to retrieve non-zeroes using gurobipy?

I am using gurobipy to read LP files. The command
model=gurobipy.read("name.lp", env=env) gives me the number of rows, columns, and non-zeroes. However, I need to retrieve the number of non-zeroes. I don't believe there is a function that does this automatically (i.e. model.getnonzeros() )
Is there a way to obtain the non-zeros? How would I write python code to be able to do this if there isn't a built in function?
Consulted resources
Get constraints in matrix format from gurobipy
Ok I figured it out - perusing the Gurobi reference manual, in chapter 6, Python API overview, I see there is an attribute called "NumNZs" that can be called as:
print(model.getAttr("NumNZs"))
This will give the non-zeroes

Python - Reading File Then Adding Value to Sum?

I've been looking all around the web for this answer and can't find it.
I'm semi new to python so hoping i get an answer here,
so basically what i want to do is, access a text file "number.txt"
that has a 10 as a line, and do a sum within the python code.
Here is what i got so far:
with open('number.txt', 'r') as sum:
num = sum.readline()
clean = num.rstrip('\n')
#number.txt file only contains 1 line and is a 10
increase = "5"
adding = clean + increase
print(adding)
it doesn't do the sum, instead i get the 5 added after the 10
so instead of getting 15 i get 105.
can anyone help?
Welcome to programming. Keep aware of the concepts of data types, I suggest doing some reading on that.
The + operator behaves differently between strings, arrays, and integers.
I would give you the answer but I am guess you are doing this as an assignment of sorts, so I just wanted to point you in the right direction. Use a python debugger (like PyCharm, or Wing IDE) to determine the differences between "5" + "10" 5+10 and [5]+[10]
You need to look into what's called Type Casting

Getting the result of an excel formula in python

I need to open a .xlsx-file (without writing to it) in python, to change some fields and get the output after the formulas in some fields were calculated; I only know the input fields, the output field and the name of the sheet.
To write some code: Here is how it would look like if I would have created the library
file = excel.open("some_file.xlsx")
sheet = file[sheet_name]
for k, v in input_fields.items():
sheet[k] = v
file.do_calculations()
print(sheet[output_field])
Is there an easy way to do this? Wich library should I use to get the result of the formulas after providing new values for some fields?
Is there a better way than using something like pyoo, maybe something that doesn't require another application (a python library is clearly better) to be installed?
I'll just thank you in advance.
I now came up with a (very ugly) solution.
I am now reading the xml within the xlsx-file, and I am now using eval and some regular expressions to find out wich fields are needed; and I have defined some functions to run the calculations.
It works, but it would be great if there were a better solution.
If the resulting library is ready, and I don't forget to do this; I'll add a link to the library (that'll be hosted on Github) to this answer to my own question.

LibreOffice Basic: existing utilities for splitting strings?

I'm using the LibreOffice Basic language.
I'm wondering if there is any library anywhere I can use for splitting strings into arrays? For example, suppose I have the following string with items separated by an arbitrary number of spaces:
ABC DEF GHI
I'd like to split this string into an array called "item" with the following elements:
item(0) = "ABC"
item(1) = "DEF"
item(2) = "GHI"
I know how to produce these results in LibreOffice Basic using regular expressions or via iterating character-by-character through the original string, but I'm wondering if there are any existing functions or helper utilities I can use, so I don't have to "re-invent the wheel".
Internet searches have not yielded anything, but I could possibly have overlooked something.
Thank you in advance.
It looks like you will need to write your own function. There are several ideas at https://forum.openoffice.org/en/forum/viewtopic.php?f=9&t=33218.
If you will be doing a lot of string manipulation and the project is not too far along yet, then it might be worth considering another UNO-enabled language like Java or Python. In Python the code would be simply:
s = "ABC DEF GHI"
item = s.split()

executing user input as code

I want to step through and evaluate user defined formulas in a worksheet (i.e. they would be strings).
The text may look something like (syntax could be changed to make the vba code writing easier):
Var1('a,1') = 0.1
Var1('a,2') = 0.5
Var2('a') = Var1('a,1') + Var2('a,2')
Var3('a') = SomeFunction(Var2('a'),"SomeArg")
etc.
If I could wrap each line in something like Execute(Line) then it seems straightforward, is this possible?
The only other method I've been able to think of is having a dictionary store the variables, but then I'll need to write some (probably bug filled) code to wrap the variable names but not the function names.
VarDict("Var1('a,1')") = 0.1
VarDict("Var1('a,2')") = 0.5
VarDict("Var2('a')") = VarDict("Var1('a,1')") + VarDict("Var2('a,2')")
VarDict("Var3('a')") = SomeFunction(VarDict("Var2('a')"),"SomeArg")
etc.
Possibly a little of topic but I would suggest taking a look at pyspread it is a spreadsheet that allows each cell to be any python object up to and including a full python program - if you are not tied into Excel then you will find a lot of the work done for you.
N.B. python, pyspread and all the required tools, (wxpython for the GUI, numpy for the numeric libraries, gpg for signing spreadsheets securely, etc), are free, (including for commercial use), and will run on multiple platforms including Windows, Macintosh and Linux amongst others.

Resources