I am trying to read an ini file. This is the way is setup. The comments refer to the value obtained for the variable in question.
Private Declare Function GetPrivateProfileStringKey Lib "kernel32" Alias _
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString _
As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Sub Main()
Dim r as Long
r = GetWindowsDirectory(Buffer, Len(Buffer))
WinPath = Left(Trim(Buffer), r)
WinPath = WinPath & "\" & "epay.ini"
'WinPath = "c:\winnt\epay.ini" which is correct
Buffer = ""
Dim TempStr As String
TempStr = New String(CChar(" ", 255)
r = GetPrivateProfileStringKey("SchCrystal", "bPrinter", "", TempStr, Len(TempStr), WinPath)
'the value of TempStr should be "1" yet the value on debugging is "". I have read ini in VB before using similar code but do not seem to be able to do it for first time in VB Net. Can anybody help? Thanks in advance.
By the way I would like to dispense with reading ini if possible. I just need to pass six parameters to the app but I am not an expert in VB and have never declared incoming parameters into a VB App. If anybody can help me by looking at the code to read the ini and giving me some advice on how to fix it or telling me how to declare the incoming parameters I will be grateful. My starting and only sub is Main(). Should it be Public Sub Main(Param1 as string, Param2 as string.....)
Thanks
Private Declare Function GetPrivateProfileStringKey Lib "kernel32" Alias _
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString _
As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Sub Main()
Dim r as Long
r = GetWindowsDirectory(Buffer, Len(Buffer))
WinPath = Left(Trim(Buffer), r)
WinPath = WinPath & "\" & "epay.ini"
'WinPath = "c:\winnt\epay.ini" which is correct
Buffer = ""
Dim TempStr As String
TempStr = New String(CChar(" ", 255)
r = GetPrivateProfileStringKey("SchCrystal", "bPrinter", "", TempStr, Len(TempStr), WinPath)
'the value of TempStr should be "1" yet the value on debugging is "". I have read ini in VB before using similar code but do not seem to be able to do it for first time in VB Net. Can anybody help? Thanks in advance.
By the way I would like to dispense with reading ini if possible. I just need to pass six parameters to the app but I am not an expert in VB and have never declared incoming parameters into a VB App. If anybody can help me by looking at the code to read the ini and giving me some advice on how to fix it or telling me how to declare the incoming parameters I will be grateful. My starting and only sub is Main(). Should it be Public Sub Main(Param1 as string, Param2 as string.....)
Thanks