vb.net 读写ini文件

前端之家收集整理的这篇文章主要介绍了vb.net 读写ini文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

'*********************************
'****INIファイル操作クラス********
'*********************************
Public Class INIOper


'[PATH]
'TempPath=C:\Temp\Temp.pdf
'[XXXX]
'xxxxPath=C:\Temp\xxx.xls



Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String,ByVal lpKeyName As String,ByVal lpDefault As String,ByVal lpReturnedString As String,ByVal nSize As Int32,ByVal lpFileName As String) As Int32
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String,ByVal lpString As String,ByVal lpFileName As String) As Int32


'Ini Keyを読み込む
Public Shared Function GetINI(ByVal Section As String,ByVal AppName As String) As String
Dim Str As String = LSet(Str,256)
GetPrivateProfileString(Section,AppName,"",Str,Len(Str),System.Windows.Forms.Application.StartupPath + "\\Health.ini")
Return Microsoft.VisualBasic.Left(Str,InStr(Str,Chr(0)) - 1)
End Function


'Iniファイルに書く
Public Shared Function WriteINI(ByVal sectionName As String,ByVal keyName As String,ByVal setValue As String) As Integer
Dim rc As Integer

rc = WritePrivateProfileString(sectionName,keyName,setValue,System.Windows.Forms.Application.StartupPath + "\\Health.ini")

If rc Then
'ok
rc = 1
Else
rc = 0
End If
End Function


End Class

●呼び出し方法

Private fn As String = INIOper.GetINI("PATH","TempPath")



猜你在找的VB相关文章