Scripting > mrScriptBasic overview > mrScriptBasic examples > 2: Getting a list of valid languages
 
2: Getting a list of valid languages
This mrScriptBasic example uses the MDM LanguageDefinitions object to create a list of the languages that are registered on your system.
See LanguageDefinitions object in the MDM Object Model Reference.
Code
This example is included with the UNICOM Intelligence Developer Documentation Library as a sample script called ListLanguages.mrs. See Sample mrScriptBasic files for more information.
Dim fso, txtfile, strLanguages, LanguageDefinitions, i

Set fso = CreateObject("Scripting.FileSystemObject") ' Line 3
Set txtfile = fso.CreateTextFile("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\LanguageDefinitions.csv", True)

txtfile.WriteLine("Language name" + "," + _
"3-character code" + "," + "Language and country code") ' Line 7

Set LanguageDefinitions = CreateObject("MDM.LanguageDefinitions") ' Line 9

For i = 0 To LanguageDefinitions.Count - 1 ' Line 11
txtfile.WriteLine(LanguageDefinitions.Item[i][MDMLib.LanguageConstants.langSLANGUAGE] + "," + _
LanguageDefinitions.Item[i][MDMLib.LanguageConstants.langSABBREVLANGNAME] + "," + _
LanguageDefinitions.Item[i][MDMLib.LanguageConstants.langSISO639LANGNAME] + " - " + _
LCase(LanguageDefinitions.Item[i][MDMLib.LanguageConstants.langSISO3166CTRYNAME]))
Next

txtfile.Close()

ShellExecute("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\LanguageDefinitions.csv") ' Line 20
Line 4
Creates the text file and specifies a .csv filename extension so that it is easy to read in Excel.
Line 7
This long line has been split into two using the line continuation characters, which are a space followed by _ (underscore). You cannot put a comment on a line that is continued on the next line.
Line 11
Uses the For...Next statement to iterate through the LanguageDefinitions object until the counter is one less than the LanguageDefinitions.Count property. (One less than the Count property because the counter starts at zero whereas the Count property starts at 1.)
See LanguageDefinitions object in the MDM Object Model Reference.
The MDM does not have a LanguageDefinition object, so we cannot use the For Each...Next statement to iterate through each object in the LanguageDefinitions object as we iterated through the functions in the 1: Using objects and iterating through collections.
Line 12
Writes the name, three-character code, and language and country code to the text file. LanguageDefinitions.Item is a property, so you specify its parameters using [] (brackets) and not () (parentheses) as in Visual Basic and VBScript. LanguageDefinitions.Item takes two parameters. The first is the index and the second is an enumerated value that defines the information that you want to retrieve.
The LCase function has been used to convert the last item to lower case.
Line 20
Calls the ShellExecute function to open the .csv file.
Result
Here is the .csv file viewed in Excel:
See also
3: Displaying the results of a query in Microsoft Excel
mrScriptBasic examples