求大神指点 vb.net 怎么读 ini 配置呢

求大神指点 vb.net 怎么读 ini 配置呢,第1张

VB.NET读写INI配置文件

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim path As String

        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

    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

    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

    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 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

Dim s As String() = System.IO.File.ReadAllLines("t.ini") '文件

For i As Integer = 0 To s.Length - 1

    Dim si As Integer = s(i).IndexOf("=")

 慧雀   If si > -1 Then

        ListBox1.Items.Add(s(i).Substring(0, si) & " = "迹芹 & 前州早s(i).Substring(si + 1))

    End If

Next

's(i).Substring(0, si)是变量名,s(i).Substring(si + 1)是值


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/8206585.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存