欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > DOCX文档下载  

    VB 操作INI文件方法.docx

    • 资源ID:3168255       资源大小:37.33KB        全文页数:5页
    • 资源格式: DOCX        下载积分:6.99金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要6.99金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    VB 操作INI文件方法.docx

    VB 操作INI文件方法1.定义一些变量 Public IniFileName As String, vbNullString As String, maxSize As Long, section1 As String, section2 As String 2.初始话这些变量 Public Function initial IniFileName = App.Path & "" & "config.ini" vbNullString = "" maxSize = 255 section1 = "basics" section2 = "others" temp_str = String(255, 0) '建立缓冲区 End Function 3.声明INI函数 Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" ( _ ByVal lpApplicationName As String, _ ByVal lpKeyName As String, _ ByVal nDefault As Long, _ ByVal lpFileName As String) As Long Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" ( _ ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, _ ByVal lpDefault As String, _ ByVal lpReturnedString As String, _ ByVal nSize As Long, _ ByVal lpFileName As String) As Long Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" ( _ ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, _ ByVal lpString As Any, _ ByVal lpFileName As String) As Long 4.调用函数 dim source as string GetPrivateProfileString section1, "source", vbNullString, temp_str, maxSize, IniFileName source = Mid(temp_str, 0, 5) '缓冲区长度249,直接去匹配是不可以的,需要首先提取出有效字符 xpos.Text = GetPrivateProfileInt(section1, "xpos", 1, IniFileName) dim a as interger a = GetPrivateProfileInt(section1, "auto", 1, IniFileName) WritePrivateProfileString section1, "auto", "0", IniFileName 下一个例子 Option Explicit Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" ( _ ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, _ ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" ( _ ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, _ ByVal lpFileName As String) As Long Private Function GetIni(ByVal ApplicationName As String, ByVal KeyName As String, ByVal FileName As String) As String Dim Buff As String, TmpStr As String Buff = String(1024, 0) Call GetPrivateProfileString(ApplicationName, KeyName, "", Buff, Len(Buff) + 1, FileName) If Asc(Mid(Buff, 1, 1) = 0 Then GetIni = "": Exit Function Dim I As Integer For I = 2 To Len(Buff) If Asc(Mid(Buff, I, 1) = 0 Then TmpStr = Mid(Buff, 1, I - 1) Next If TmpStr = "" Then TmpStr = Buff GetIni = TmpStr End Function Private Function PutIni(ByVal ApplicationName As String, ByVal KeyName As String, ByVal Str As String, ByVal FileName As String) As Long WritePrivateProfileString ApplicationName, KeyName, Str, FileName End Function Private Function DelIni(ByVal ApplicationName As String, ByVal KeyName As String, ByVal FileName As String) As Long WritePrivateProfileString ApplicationName, KeyName, 0&, FileName End Function Private Sub Form_Load Shell (GetIni("lujing", "pa", "INI文件的路径及名称.ini") & "" & GetIni("lujing", "pa1", "INI文件的路径及名称.ini") End Sub 再次讲解 这是API函数,使用前必须在公共部分定义,可以建公共模块,也可以在窗体最上面写. 代码: Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long 然后GetPrivateProfileString WritePrivateProfileString 这两个函数就可以用了. 读取和写入代码如下 Private Sub SetIniS(ByVal SectionName As String, ByVal KeyWord As String, ByVal ValStr As String) Dim res% res% = WritePrivateProfileString(SectionName, KeyWord, ValStr, "C:123.ini") End Sub Private Function GetIniS(ByVal SectionName As String, ByVal KeyWord As String, ByVal DefString As String) As String Dim llLen As Long Dim ResultString As String ResultString = Space(100) llLen = GetPrivateProfileString(SectionName, KeyWord, DefString, ResultString, 100, "C:123.ini") GetIniS = Mid(ResultString, 1, llLen) End Function

    注意事项

    本文(VB 操作INI文件方法.docx)为本站会员(小飞机)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开