The GetINIValue method returns a value from an INI file. This method, along with SetINIValue, is useful if you need to store a custom value in an INI file and retrieve it for any purpose.

Syntax

GetINIValue(INIFile as String, Section as String, 
    Entry as String [, DefaultValue as String]) as String

Parameters
INIFile
The fully-qualified path to the INI file. Pass an empty string for this parameter to use Data.ini in the Data subdirectory.

Section
The section in the INI file where the value can be found.

Entry
The name of the entry to return the value for.

DefaultValue
The value to return if the specified entry isn't found. Optional; if it isn't specified and the entry doesn't exist, an empty string is returned.

Return Value
The value in the INI file if it was found or a blank string (or the value of DefaultValue if it's specified) if not.

Example
Here's an example that retrieves the location for the AR tables from the AR Location entry in the [Custom Settings] section of the SFQUERY.INI file for the project. If the entry is blank (such as when this code is executed for the first time), the user is prompted for the value and it's stored in the INI file. This code goes into the DataEngine.GetCustomMetaData script.

Visual FoxPro

lparameters toApplication as SQApplication
local lcINIFile, lcLocation, lnI, loTable as Table
lcINIFile  = toApplication.ProjectDirectory + 'SFQUERY.INI'
lcLocation = toApplication.GetINIValue(lcINIFile, ;
  'Custom Settings', 'AR Location')
if empty(lcLocation)
  lcLocation = toApplication.PromptUserForValue('Location of AR Tables')
  toApplication.SetINIValue(lcINIFile, ;
    'Custom Settings', 'AR Location', lcLocation)
endif
if not empty(lcLocation)
  for lnI = 1 to toApplication.DataEngine.Tables.Count
    loTable = toApplication.DataEngine.Tables.Item(lnI)
    do case
      case left(loTable.Alias, 2) <> 'AR'
      case lcValue = 'Y'
        loTable.Location = lcLocation
      otherwise
        loTable.Reportable = .F.
    endcase
  next
endif

VBScript

function Main(Application)
dim Table
INIFile  = Application.ProjectDirectory + "SFQUERY.INI"
Location = Application.GetINIValue(INIFile, "Custom Settings", _
  "AR Location")
if Location = "" then
  Location = Application.PromptUserForValue("Location of AR Tables")
  Application.SetINIValue INIFile, _
    "Custom Settings", "AR Location", Location
end if
if Location <> "" then
  for I = 1 to Application.DataEngine.Tables.Count
    set Table = Application.DataEngine.Tables.Item(I)
    if left(Table.Alias, 2) = "AR" then
      if Value = "Y" then
        Table.Location = Location
      else
        Table.Reportable = False
      end if
    end if
  next
end if
end function

JavaScript

function Main(Application) {
var INIFile, Location, I, Table ;
INIFile  = Application.ProjectDirectory + 'SFQUERY.INI' ;
Location = Application.GetINIValue(INIFile, 'Custom Settings', 
  'AR Location') ;
if (Location = '') {
  Location = Application.PromptUserForValue('Location of AR Tables') ;
  Application.SetINIValue(INIFile, 
    'Custom Settings', 'AR Location', Location) ;
}
if (Location <> '') {
  for (I = 1; I <= Application.DataEngine.Tables.Count; I++) {
    Table = Application.DataEngine.Tables.Item(I) ;
    if (left(Table.Alias, 2) = 'AR') {
      if (Value = 'Y') {
        Table.Location = Location ;
        }
      else {
        Table.Reportable = false ;
        }
    }
  }
}
}

C#

public static bool DataEngine_GetCustomMetaData(SFQApplication sfqApplication)
{	
  string iniFile = sfqApplication.ProjectDirectory + "SFQUERY.INI";
  string location = sfqApplication.GetINIValue(iniFile, "Custom Settings", 
    "AR Location");
  string value = sfqApplication.GetRegistryValue("AR Data");
    
  if(location == String.Empty)
  {
    location = sfqApplication.PromptUserForValue("Location of AR Tables");
    sfqApplication.SetINIValue(iniFile, "Custom Settings", "AR Location", location);
  }
    
  if(location != String.Empty)
  {
    foreach(Table table in sfqApplication.DataEngine.Tables)
    {
      if (table.Alias.Substring(0, 2) == "AR") 
      {
        if (value == "Y") 
        {
          table.Location = location;
        }
        else 
        {
          table.Reportable = false;
        }
      }
    }
  }
 
  return true;
}

VB.NET

public shared function DataEngine_GetCustomMetaData(sfqApplication as SFQApplication)
    as Boolean
  Dim iniFile As String = sfqApplication.ProjectDirectory + "SFQUERY.INI"
  Dim location As String = sfqApplication.GetINIValue(iniFile, "Custom Settings",
    "AR Location")
  Dim value As String = sfqApplication.GetRegistryValue("AR Data")

  If location = String.Empty Then
    location = sfqApplication.PromptUserForValue("Location of AR Tables")
    sfqApplication.SetINIValue(iniFile, "Custom Settings", "AR Location", location)
  End If

  If location <> String.Empty Then
    For Each table As Table In sfqApplication.DataEngine.Tables
      If table.Alias.Substring(0, 2) = "AR" Then
        If value = "Y" Then
          table.Location = location
        Else
          table.Reportable = False
        End If
      End If
    Next
  End If

  Return True
End Function

See also

Application Object | GetRegistryValue | SetINIValue

© Stonefield Software Inc., 2024 • Updated: 10/03/18
Comment or report problem with topic