This is the most complete version of M2000. I have to revise the old English Manual, an a not too old Greek one.
Version 12 include:
Arrays with types .Previous versions use variant type internal, and have two interfaces, one with parenthesis and another with a pointer to array.
// Before Version 12 - Still in use in Version 12
Dim Alfa(10, -3 to 3)=100&
// if we paass something else because it is a variant type, take it as is.
Alfa(2, -1)=100%
Print type$(Alfa(2,-1))="Integer", type$(Alfa(9, 3))="Long"
// Version 12
Dim Beta(-2 to 2, -2 to 2) as Long Long
Beta(1,2)=100 ' 100 has the default type Double
// Cannot change type.
Print Type$(Beta(1,2))="Long Long"
// We get overflow if we try to put something which not fit.
Define variables using the type before the name, and we can omit values, (they get the default for their type). Also Variant type included for variables. Before version 12 all variables get the type from the first assignment, and there was a way to define them but only literals allowed for first value.
// old style, we can pass second time from this line, an error raised
// you have to exit the module and then you can use it (like it is a first time)
Def integer a=100, b=200
// Defining local variables when the scope is more wide, like in subs.
// also define Local arrays. We can use it for arrays with types two, look z()
// we can make strings using names without suffix S. Although suffix $ are recommented for clarity.
// Local always make new variables/arrays. So we don't include this in a Loop.
// new same names hide the old same names.
Local a1 as long=100, b1 as boolean=True, kappa(10)=10&, Z(10) as string
// Like Local, Global always make new variables, arrays.
Global K, ZZ(30) as boolean
Print type$(ZZ(2))="Boolean"
// this statement show all defined variables (but maybe not in scope with this code)
List
Variant V="Hello"
Print V+V="HelloHello", "HelloHello"=V+V // true true
V=10
Print V+V=20, 20=V+V // return true true
V=(1,2,3,4)
Print V#sum()=10
V="Now I am String Again"
Print Mid$(V, 5)="I am String Again"
V$="I am not variable V"
// With the type before, we can redefine a variable. Always Local variables.
Double M=100, N
Print Type$(M)="Double"
// Now M converted to Integer, and stay as Integer, with overflow control.
Integer M
Print Type$(M)="Integer"
Print M=100
// we can use Global and Local before
Global double M1, M2
New type of arrays (one or two dimensions but internal the first dimension is a one dimension of arrays, so each "row" can expand as we wish, and the first column to include more arrays. We can't reduce size. We have pointer and we pass it or pass a copy easy:
// new type of arrays
// this is an array of arrays
// with one type
integer ia[10][10]=100 // has 11x11 items
long lk[3]=3 // 4 items
variant vb[10]
vb[3]=lk[] // we pass a copy of ik
Print vb[3][2]=3
vb[3][2]++
Print vb[3][2]=4
Print lk[2]=3
lk[2]+=100
vb[1]=lk // we pass a pointer (object)
Print vb[1][2]=103
vb[1][2]+=200
Print vb[1][2]=303
Print lk[2]=303 // so now ik[2] has the same value
Epression Evaluator.
Version 12 is more VB6 like, on expression evaluation. This break a little the compatibility with older versions. The differences are two:
The minus sign as unary operator behave different before power, so -2^2=2^2 (same as -2**2-2**2, M2000 has the two operators for power) , now return -8, and the older versions return 0 (because the - sign was unary to 2 so we get (-2)^2-(-2)^2 or 4-4 or 0. But the new one do something else -(2^2)-(2^2), because power operator has higher priority from unary minus.
Here we see that the unary minus change the type of second integer value (in hexadecimal format).
Print 0x8000%, -0x8000%
def typename(x)=type$(x)
Print typename(0x8000%)="Integer", typename(-0x8000%)="Long"
Print 0x8000%^2, -0x8000%^2 // Overflow error
We get overflow error because power for integer (16bit), long (32bit) and Long Long (64bit) always use internal fast multiplication and return same type or overflow. This is different from VB6 which always return a Double value.
Print 0x8000%, -0x8000%
def typename(x)=type$(x)
Print typename(0x8000%)="Integer", typename(-0x8000%)="Long"
//Print 0x8000%^2, -0x8000%^2 // Overflow error
LLz=0x8000_0000_0000_0000&&
clipboard LLz
Print LLz=-9223372036854775808&&
LLz=2&&^63&&
// Long Long return negative number (same bits with unsigned long long)
// at the 2^63
Print LLz=-9223372036854775808
Literals for different type/use:
Print 10% // Integer
Print 10& // Long
Print 10&& // Long Long
Print 10~ // Single (float 4 bytes)
Print 10 // double (8 bytes)
Print 10# // Currency (8 bytes integer X1000 - has 4 decimal digits)
Print 10@ // Decimal 29 digits (96bit) without sign and the position of decimal point
Print True, False // -1 0 (they are double values - from version 1 of M2000)
//we can define boolean, and all comparisons return boolean (Except <=>)
// a non zero value is true.
boolean k=True
def string a1$="Hello there"
string a="hello"
Print 0x100 ' Currency type used as unsigned long
Print 0x100& ' long
Print 0x100% ' Integer
Print 0x100&& ' Long Long
Print 0x0_1000_1000 ' Decimal used for unsigned Long Long
// we can use _ character inside hexadecimal value
Hex 233% ' we have the Hex as Print but for Hexadecimal values. Return 0x00E9
Print &hFFFF& ' this is long type, using the VB6 &H
Pen #AA88FF // this is a Html Color (has a negative value, 1 to 15 are the standard colors, 0 for black)
We can use { } for block of codes and for string literals using line breaks, Depending the code Interpreter find where a block is code or string (also the syntax coloring system for M2000 editor, which included in M2000 environment can be colorized the code using the same technic (from the statement before the block).
Enum constants now take string values too.
Many other improvements. The Test form (for executing step by step code) now has list of errors. So when we trap errors we have the list which can be open in the help pad form, and see them in real time.
There is a stop statement which can stop the execution, and writing from console we can alter local variables, define new variables, alter functions etc.
Version 12 can load controls which are register as OCX, on user forms. There are 5 controls including the base for the controls for forms (button, combo, checkbox, textbox, editbox, listbox, Image) which I design and programmed them. These are the UCPieChart, UCChart, NineButtons, ShapeEx, Radial.
The button can be used as a timer for blinkig, combo used as menu too, textbox as spinbox, editbox for numeric/text one line input with multiple undo, as well for multiple lines, using an internal system for adjusting the coloring code procedure. Image box can be used as a frame to hold other controls, and can be used as console (There is a demo, Ver11 in info file). Listbox can be used as a multicolumn box, but isn't like Flex. Although can be used for virtual list (not included in the control but handle it with interrupt, and feeding it when ask for it. Combo boxes are a textbox with a list, and we can use it with textbox for editing with autocomplete, sorting the drop down list, or as a button with a dropdown list, or just as a list we change the caption of the button, like a split button. All the controls can be used with transparency (and the EditBox), and are unicode.
I am looking for new controls (there are some objects for different tasks, not controls such as for zip files, json files, xml files).
Here is a program to interact with internet, calling remote functions, using WinHttpRequest. The idea was from a Bulgarian friend. You have to register as user in Microsoft
global string DEF_ENDPOINT="https://api.cognitive.microsofttranslator.com"
declare Request "WinHttp.WinHttpRequest.5.1"
Module TranslateInit(Req, sKey as string, sRegion as String, sFromLang as String="gr", ToLang as String="en") {
Method Req, "Open", "POST", DEF_ENDPOINT+"/translate?api-version=3.0&from="+ sFromLang + "&to=" + ToLang
Method Req,"SetRequestHeader", "Ocp-Apim-Subscription-Key", sKey
Method Req,"SetRequestHeader", "Ocp-Apim-Subscription-Region", sRegion
Method Req,"SetRequestHeader", "Content-Type", "application/json"
}
Function TranslateText(Req, vTexts as variant) {
declare Json JsonArray
with json, "json" as json.format$()
if type$(vTexts)="String" then
method json, "assignpath", "0.text", vTexts
else.if type$(vTexts)="mArray" then
k=each(vTexts)
while k
method json, "assignpath", str$(k^,0)+".text", array$(k)
end while
end if
/report json.format$(4)
Method Req, "Send", json.format$(0)
with Req, "ResponseText" as r$
method json, "parser", r$ as resp
=resp
}
TranslateInit Request, "SorryYourPasswordHere", "westeurope", "bg","en"
words_bg_en=("Здравейте", "Лека нощ")
json= TranslateText(Request, words_bg_en)
'json= TranslateText(Request, "Лека нощ")
with json, "json" as json.format$(), "count" as count
with json, "itempath" as json.path(), "itempath" as json.path$()
report json.format$(4)
if count>0 then
for i=0 to count-1
Print words_bg_en#val$(i)+" = "+json.path$(str$(i,0)+".translations.0.text")
next
end if
{
"translations" : [
{
"text" : "Hello",
"to" : "en"
}
]
},
{
"translations" : [
{
"text" : "Good night",
"to" : "en"
}
]
}
]
Здравейте = Hello
Лека нощ = Good night
There is an Info file with over 300 modules. Because M2000 use modules in modules, we load all of them and we can use any of them (we can run multiple programs each one with showing or hidden environment (the console).
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.