请选择 进入手机版 | 继续访问电脑版

玩酷之家

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 536|回复: 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
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2018-12-12 15:35 , Processed in 0.162137 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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