日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
迅速掌握VB.NET讀取INI文件操作方法

VB.NET做為一款***的開發(fā)平臺(tái),為開發(fā)人員帶來了很大的幫助。因?yàn)閷ML前不了解,所以對XML方式來做配置文件我都不能很好的實(shí)現(xiàn),但為了應(yīng)行,只有先使用INI的文來記錄了,也就沿用了VB6里的INI文讀取方法。#t#

下面請看VB.NET讀取INI文件的相關(guān)代碼示例:

  1. '聲明INI配置文件讀寫API函數(shù)
  2. Private Declare Function GetPrivateProfileString()
    Function GetPrivateProfileString Lib "kernel32" 
    Alias "GetPrivateProfileStringA" (ByVal 
    lpApplicationName As String, ByVal lpKeyName As 
    String, ByVal lpDefault As String, ByVal lpReturned
    String As String, ByVal nSize As Int32, ByVal 
    lpFileName As String) As Int32
  3. Private Declare Function WritePrivateProfileString()
    Function WritePrivateProfileString Lib "kernel32" 
    Alias "WritePrivateProfileStringA" (ByVal 
    lpApplicationName As String, ByVal lpKeyName As 
    String, ByVal lpString As String, ByVal lpFileName 
    As String) As Int32
  4. '定義讀取配置文件函數(shù)
  5. Public Function GetINI()Function GetINI(ByVal 
    Section As String, ByVal AppName As String, ByVal 
    lpDefault As String, ByVal FileName As String) 
    As String
  6. Dim Str As String = LSet(Str, 256)
  7. GetPrivateProfileString(Section, AppName, 
    lpDefault, Str, Len(Str), FileName)
  8. Return Microsoft.VisualBasic.Left(Str, InStr
    (Str, Chr(0)) - 1)
  9. End Function
  10. '定義寫入配置文件函數(shù)
  11. Public Function WriteINI()Function WriteINI
    (ByVal Section As String, ByVal AppName As 
    String, ByVal lpDefault As String, ByVal 
    FileName As String) As Long
  12. WriteINI = WritePrivateProfileString(Section, 
    AppName, lpDefault, FileName)
  13. End Function
  14. Private Sub Form1_Load()Sub Form1_Load(ByVal 
    sender As System.Object, ByVal e As System.
    EventArgs) Handles MyBase.Load
  15. Dim path As String
  16. path = Application.StartupPath + "\server.ini"
  17. TextBox1.Text = GetINI("Server", "IP", "", path)
  18. TextBox2.Text = GetINI("Server", "port", "", path)
  19. End Sub
  20. Private Sub Button1_Click()Sub Button1_Click
    (ByVal sender As System.Object, ByVal e As 
    System.EventArgs) Handles Button1.Click
  21. Try
  22. Dim path As String
  23. path = Application.StartupPath + "\server.ini"
  24. WriteINI("Server", "IP", TextBox1.Text, path)
  25. WriteINI("Server", "port", TextBox2.Text, path)
  26. MsgBox("配置設(shè)置已經(jīng)成功?。。。?)
  27. Me.Close()
  28. Catch ex As Exception
  29. MsgBox("錯(cuò)誤!?。?!")
  30. End Try
  31. End Sub

VB.NET讀取INI文件的相關(guān)操作就為大家介紹到這里。


當(dāng)前標(biāo)題:迅速掌握VB.NET讀取INI文件操作方法
轉(zhuǎn)載注明:http://www.5511xx.com/article/cdooshh.html