VB.NET 讀寫ini檔案
Public Class Form1
'************ini檔案內容為*************************
'*[send] *
'*send1=1 *
'*send2=4 *
'*send3=3 *
'*IsSms=1 *
'**************************************************
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim path As String
'ini檔名為 Send.ini
path = Application.StartupPath + "\Send.ini"
TextBox1.Text = GetINI("Send", "Send1", "", path)
TextBox2.Text = GetINI("Send", "Send2", "", path)
Dim IsSms As Integer = GetINI("Send", "IsSms", "", path)
If (IsSms = 1) Then
Me.RadioButton1.Checked = True
ElseIf (IsSms = 0) Then
Me.RadioButton2.Checked = True
End If
End Sub
'讀取ini檔案內容
Public Function GetINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As String
Dim Str As String = LSet(Str, 256)
GetPrivateProfileString(Section, AppName, lpDefault, Str, Len(Str), FileName)
Return Microsoft.VisualBasic.Left(Str, InStr(Str, Chr(0)) - 1)
End Function
'寫ini檔案操作
Public Function WriteINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As Long
WriteINI = WritePrivateProfileString(Section, AppName, lpDefault, FileName)
End Function
'讀ini API函式
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
'寫ini API函式
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim path As String
path = Application.StartupPath + "\Send.ini"
WriteINI("Send", "Send1", TextBox1.Text, path)
WriteINI("Send", "Send2", TextBox2.Text, path)
If (Me.RadioButton1.Checked = True) Then
WriteINI("Send", "IsSms", 1, path)
ElseIf (Me.RadioButton2.Checked = True) Then
WriteINI("Send", "IsSms", 0, path)
End If
MsgBox("配置設定已經成功!!!!")
Catch ex As Exception
MsgBox("錯誤!!!!")
End Try
End Sub
End Class
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-564905/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- java 讀寫 ini 配置檔案Java
- c#讀寫ini檔案C#
- VB讀寫ini檔案 (轉)
- 使用C#讀寫ini檔案C#
- C#關於讀寫INI檔案C#
- C# winform中讀寫ini檔案C#ORM
- linux/windows 讀寫ini配置檔案LinuxWindows
- C#中讀寫INI配置檔案C#
- 使用IniEditor讀寫INI型別配置檔案型別
- 讀寫INI檔案的四個函式 (轉)函式
- winform c#寫ini檔案ORMC#
- 建立與讀取.ini檔案
- delphi讀取ini檔案 (轉)
- C#讀取ini配置檔案C#
- Python常用配置檔案ini、json、yaml讀寫總結PythonJSONYAML
- API讀取寫入 ini檔案內容的方法函式詳解API函式
- 透過python讀取ini配置檔案Python
- 檔案讀寫
- Linux下用C讀取INI配置檔案Linux
- 檔案排版(文字檔案讀寫)
- java操作ini檔案Java
- Golang 讀、寫檔案Golang
- keras讀寫檔案Keras
- perl 讀寫檔案
- 檔案讀寫IO
- 檔案的讀寫
- Python讀取修改ini配置檔案[ConfigParser]Python
- NPM酷庫047:ini,解析INI配置檔案NPM
- 【自動化測試】Python 讀取 .ini 格式檔案Python
- 「Python」:檔案讀寫Python
- Python——檔案讀寫Python
- Python 讀寫檔案Python
- C++檔案讀寫C++
- 普通檔案的讀寫
- 【Java】讀寫文字檔案Java
- c fopen檔案讀寫
- 讀寫iOS XML檔案iOSXML
- Python讀寫檔案Python