Skip to main content
Previous section   

Frequently Asked Questions About Caché Basic

This question and answer set includes the following topics:

General

Question:

Does Caché Basic work only on Windows platforms?

Answer:

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.

Question:

Is Caché Basic slower than ObjectScript?

Answer:

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.

Question:

On what breed of Basic is Caché Basic based?

Answer:

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.

Question:

Does the introduction of Caché Basic mean that InterSystems is planning to drop support of ObjectScript?

Answer:

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.

Question:

Are there any other goals beyond “easing the learning curve?”

Answer:

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.

Programming

Question:

Is there a “Caché Basic shell”?

Answer:

No, but nothing prevents you from implementing your own. Contact an InterSystems representative for an example of a Caché Basic shell.

Question:

How do I work with globals in Caché Basic?

Answer:

You can directly reference globals using the following syntax:

Caché Basic Syntax Elements
Syntax element Description
^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
Question:

How do I work with Caché-specific structures such as List and Piece?

Answer:

There are a number of enhancements in Caché Basic for List and Piece support. For example:

l = ListBuild("blue","red")
Println List(l,1)

p = "blue^red"
noOfItems = Len(p,"^") 
Println Piece(p,"^",1)
Copy code to clipboard
Question:

Is there any analog to $Order in Caché Basic?

Answer:

The Traverse() function provides the same functionality as $Order in ObjectScript.

i = Traverse(^MyData(""))
While (i <> "")
    Println ^MyData(i)
    i = Traverse(^MyData(i))
Wend
Copy code to clipboard
Question:

How do I work with objects in Caché Basic?

Answer:
Caché Basic and Objects Quick Reference
Caché Basic syntax Objects reference
"Basic.Human".ClassMethod() call class method
obj.Report() instance method/property
Me.Name="Anton" current object property/method
obj=New Basic.Human() create new object
obj=OpenId Basic.Human(1) open object instance
Question:

What is the analog to $this.Method or ..Method in Caché Basic?

Answer:

Me.Method

Question:

How do I work with SQL in Caché Basic?

Answer:

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
Copy code to clipboard
Question:

How do I work with files in Caché Basic?

Answer:

Use %File object:

    file = New %File("c:\test.txt")
    file.Open("WSN")    
    file.WriteLine("This is a test")    
    file.Close()
Copy code to clipboard
Question:

How do I trap errors in Caché Basic?

Answer:

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
Copy code to clipboard
Question:

Why don’t I get an <UNDEFINED> error in Caché Basic?

Answer:

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.

Question:

Can I call ObjectScript programs from Caché Basic and vice versa?

Answer:

Yes, you can call both methods and functions/procedures, regardless of the language they are written in.

In ObjectScript:

 do Procedure^BasicRoutine()
 do ##class(MyClass).BasicClassMethod()
Copy code to clipboard

In Caché Basic:

Procedure@ObjectScriptRoutine()
"MyClass".ObjectScriptMethod()
Copy code to clipboard
Question:

Why can’t I see local variables outside of the scope of my procedure?

Answer:

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.

Question:

How can I convert date and time values to and from $H format?

Answer:

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)
Copy code to clipboard
Question:

Can I use indirection in Caché Basic?

Answer:

No.

Support

Question:

I suspect there is a bug in Caché Basic. What should I do?

Answer:

Send a description of the bug to the InterSystems Worldwide Response Center (WRC).

Question:

I would like a particular feature in Caché Basic. Can InterSystems implement this?

Answer:

Send your ideas to the InterSystems Worldwide Response Center (WRC).