Read a value into a global variable

5 posts / 0 new
Last post
Robert van den ...
Offline
Joined: 08/08/2018 - 07:37
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's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

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
Robert van den ...
Offline
Joined: 08/08/2018 - 07:37

How is this line "rec.GetCharValue" when the field is a numeric field?

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Change it to rec.GetNumValue for a numeric field.

joma
Offline
Joined: 10/24/2022 - 12:30

Thanks