Skip to main content

Read a value into a global variable

Is it possible with IDEA scripting to read a specific value of a field into a global variable?

Brian Element Thu, 01/30/2020 - 18:53

Here is an example for you:

 


'*******************************************************
'* Author:	Brian Element
'* Date:		Jan 30, 2020
'* Purpose:	Demonstation to obtain a specific value in a certain row and field
'*			Script obtains the PROD_CODE from row 10
'******************************************************

Option Explicit

Dim sFilename As String
Dim sGlobalValue As String

Sub Main
	sFilename = "Sample-Detailed Sales.IMD"
	Call getGlobalValue()
	MsgBox sGlobalValue
End Sub

Function getGlobalValue()
	Dim db As database
	Dim rs As RecordSet
	Dim rec As Record
	
	Set db = Client.OpenDatabase(sFilename)

		Set rs = db.RecordSet

			' Obtain the tenth record from the RecordSet.
			rs.GetAt(10)

			'obtain the value in the PROD_CODE field from the 10th row
			'and place it in a variable that has been defined as a global variable
			Set rec = rs.ActiveRecord
				sGlobalValue = rec.GetCharValue("PROD_CODE")
			Set rec = Nothing
		Set rs = Nothing
	Set db = Nothing
End Function