Frequently Asked Questions About Caché Basic
Does Caché Basic work only on Windows platforms?
No, Caché Basic is completely platform-independent and works on any platform on which Caché runs. Caché Basic is built into the Caché kernel in the same way as ObjectScript and is not dependent on any external script engine, such as the Microsoft Scripting Host.
Is Caché Basic slower than ObjectScript?
No, Caché Basic source is compiled into the same object code as ObjectScript, so the performance of Caché Basic is the same (with minor variations) as that of ObjectScript.
On what breed of Basic is Caché Basic based?
The syntax of Caché Basic is based on Microsoft VBScript. However, since Caché Basic is a server-side scripting language, tightly integrated with the database, there are a number of differences between these two implementations. For instance, there are no MsgBox or InputBox functions in Caché Basic, but there are a number of enhancements; for example, the ability to work directly with Caché-specific data types, such as globals, lists, and so on.
Does the introduction of Caché Basic mean that InterSystems is planning to drop support of ObjectScript?
No, the main goal of Caché Basic is to ease the Caché learning curve for developers already familiar with Basic implementations such as Microsoft Visual Basic, not to replace ObjectScript. Both ObjectScript and Caché Basic will be supported and coexist indefinitely.
Are there any other goals beyond “easing the learning curve?”
Yes, with the introduction of Caché Basic, companies using Caché will gain a number of benefits, including:
Ease in hiring and educating new developers.
Ease in selling applications developed with Caché. End users do not need to study a new language to use and enhance your applications.
Re-hosting business logic of VB and ASP applications in Caché. You can migrate the business logic of existing applications from the VB client side or middle tier into Caché, achieving greater performance and scalability. The combination of CSP and Caché Basic is a good candidate for migrating Active Server Pages (ASP) applications.
Access to interesting resources. By browsing source code archives for VB, Caché developers can find a multitude of valuable and entertaining code samples (for example, games). Good starting points are: http://www.planet-source-code.com and http://www.vbcode.com.
Is there a “Caché Basic shell”?
No, but nothing prevents you from implementing your own. Contact an InterSystems representative for an example of a Caché Basic shell.
How do I work with globals in Caché Basic?
You can directly reference globals using the following syntax:
|^Global(index)="Value" Println ^Global(index)||direct access to globals|
|Exists(^a(1))||if value defined|
|Traverse(^a(""))||move to the next or previous subscript|
|EraseValue, EraseArray, Merge, Lock, Unlock, Increment()||miscellaneous functions|
l = ListBuild("blue","red") Println List(l,1) p = "blue^red" noOfItems = Len(p,"^") Println Piece(p,"^",1)
Is there any analog to $Order in Caché Basic?
The Traverse() function provides the same functionality as $Order in ObjectScript.
i = Traverse(^MyData("")) While (i <> "") Println ^MyData(i) i = Traverse(^MyData(i)) Wend
How do I work with objects in Caché Basic?
|Caché Basic syntax||Objects reference|
|"Basic.Human".ClassMethod()||call class method|
|Me.Name="Anton"||current object property/method|
|obj=New Basic.Human()||create new object|
|obj=OpenId Basic.Human(1)||open object instance|
What is the analog to $this.Method or ..Method in Caché Basic?
How do I work with SQL in Caché Basic?
Use a dynamic query object:
result = New %ResultSet() result.Prepare("SELECT Name,Age FROM Basic.Human WHERE Age<?") result.Execute(Arg1) While (result.Next()) Println result.Data("Name") & ", " & result.Data("Age") Wend
How do I work with files in Caché Basic?
Use %File object:
file = New %File("c:\test.txt") file.Open("WSN") file.WriteLine("This is a test") file.Close()
How do I trap errors in Caché Basic?
Use the On Error Goto statement:
Function ErrorTest(Arg1) On Error Goto errorhandler return 1/Arg1 errorhandler: PrintLn "Error ", Err.Number, " ", Err.Description, " ", Err.Source Err.Clear return 0 End Function
Why don’t I get an <UNDEFINED> error in Caché Basic?
In Basic, each variable is the empty string by default, so instead of an <UNDEFINED> error you get "" when referring to an undefined variable or function.
Use the Option Explicit statement to avoid inadvertently referencing undefined variables and functions.
Can I call ObjectScript programs from Caché Basic and vice versa?
Yes, you can call both methods and functions/procedures, regardless of the language they are written in.
do Procedure^BasicRoutine() do ##class(MyClass).BasicClassMethod()
In Caché Basic:
Why can’t I see local variables outside of the scope of my procedure?
This is correct behavior; the Basic language defines this functionality. The scope of all variables is limited to the procedure or function where it was defined. Exceptions are variable names that start with the % symbol, such as %myvar.
How can I convert date and time values to and from $H format?
Available conversion functions are: DateConvert(), TimeConvert(), and DateTimeConvert(). For example:
myDate = "07/15/2002" println DateConvert(myDate, vbToInternal) ' returns $H format myHDate = 59000 println DateConvert(myHDate, vbToExternal)
Can I use indirection in Caché Basic?
I suspect there is a bug in Caché Basic. What should I do?
Send a description of the bug to the InterSystems Worldwide Response Center (WRC).
I would like a particular feature in Caché Basic. Can InterSystems implement this?
Send your ideas to the InterSystems Worldwide Response Center (WRC).