玩酷之家

 找回密码
 给爷来个号
查看: 2401|回复: 0

VB.NET配置(INI)文件的读写

[复制链接]

3

主题

3

帖子

13

积分

新手上路

Rank: 1

积分
13
发表于 2018-5-31 19:55:37 | 显示全部楼层 |阅读模式


  1. Public Class Profile
  2.     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 Integer, ByVal lpFileName As String) As Long
  3.     Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  4.     Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFilename As String) As Long
  5.     Public Shared Function WriteOneString(ByVal section As String, ByVal key As String, ByVal value As String, ByVal filename As String) As Long
  6.         Dim X As Boolean
  7.         Dim Nbuff As New String(CType(" ", Char), 1000)
  8.         Nbuff = value + Chr(0)
  9.         X = WritePrivateProfileString(section, key, Nbuff, filename)
  10.         WriteOneString = X
  11.     End Function

  12.     Public Shared Function ReadOneString(ByVal section As String, ByVal key As String, ByVal Filename As String) As String
  13.         Dim X As Long, i As Integer

  14.         Dim Buffer As New String(CType(" ", Char), 1000)
  15.         X = GetPrivateProfileString(section, key, "", Buffer, 1000, Filename)
  16.         i = InStr(Buffer, Chr(0))
  17.         ReadOneString = Trim(Left(Buffer, i - 1))
  18.     End Function
  19. End Class
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 给爷来个号

本版积分规则

QQ|Archiver|手机版|小黑屋|玩酷之家 ( 鄂ICP备14012049号-1 )|

GMT+8, 2020-8-5 12:43 , Processed in 1.076401 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表