Config Helper
GetPrivateProfileInt Method
Example 



KellermanSoftware.ConfigHelper Namespace > IniReaderWriter Class : GetPrivateProfileInt Method
The INI Section Name. Use GLOBAL for the global section.
The INI Setting Name
The default value if there is no value
The path to the INI file
Managed version of GetPrivateProfileInt
No COM Interop is used
If the file does not exist or the value is not in the file, the defaultValue is used.
See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724348%28v=vs.85%29.aspx
Syntax
Public Shared Function GetPrivateProfileInt( _
   ByVal sectionName As String, _
   ByVal settingName As String, _
   ByVal defaultValue As Integer, _
   ByVal filePath As String _
) As Integer
Dim sectionName As String
Dim settingName As String
Dim defaultValue As Integer
Dim filePath As String
Dim value As Integer
 
value = IniReaderWriter.GetPrivateProfileInt(sectionName, settingName, defaultValue, filePath)
public static int GetPrivateProfileInt( 
   string sectionName,
   string settingName,
   int defaultValue,
   string filePath
)
public:
static int GetPrivateProfileInt( 
   String^ sectionName,
   String^ settingName,
   int defaultValue,
   String^ filePath
) 

Parameters

sectionName
The INI Section Name. Use GLOBAL for the global section.
settingName
The INI Setting Name
defaultValue
The default value if there is no value
filePath
The path to the INI file

Return Value

The integer
Exceptions
ExceptionDescription
Occurs when sectionName, settingName or filePath is null
Example
int expectedValue = 7;
IniReaderWriter.WritePrivateProfileString("MySection", "MySettingName", expectedValue.ToString(), "MySettingsFile.ini");
 
int actualValue = IniReaderWriter.GetPrivateProfileInt("MySection", "MySettingName", 0, "MySettingsFile.ini");
Console.WriteLine(actualValue);
Dim expectedValue As Integer = 7
IniReaderWriter.WritePrivateProfileString("MySection", "MySettingName", expectedValue.ToString(), "MySettingsFile.ini")
 
Dim actualValue As Integer = IniReaderWriter.GetPrivateProfileInt("MySection", "MySettingName", 0, "MySettingsFile.ini")
Console.WriteLine(actualValue)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

IniReaderWriter Class
IniReaderWriter Members