玩酷之家

 找回密码
 立即注册
查看: 226|回复: 0

VB 从INI读取和保存的例子

[复制链接]
发表于 2021-1-8 16:56:30 | 显示全部楼层 |阅读模式
从INI文件读取数值到text1、text2、text3中,并将text1、text2、text3中的数值保存到INI文件中。
  1. '模块代码
  2. Declare Function WritePrivateProfileString Lib "kernel32" _
  3. Alias "WritePrivateProfileStringA" (ByVal lpApplicationName _
  4. As String, ByVal lpKeyName As Any, ByVal lpString As Any, _
  5. ByVal lpFileName As String) As Long

  6. Declare Function GetPrivateProfileString Lib "kernel32" _
  7. Alias "GetPrivateProfileStringA" (ByVal lpApplicationName _
  8. As String, ByVal lpKeyName As Any, ByVal lpDefault As String, _
  9. ByVal lpReturnedString As String, ByVal nSize As Long, _
  10. ByVal lpFileName As String) As Long

  11. '窗体代码
  12. Private Function WriteOneString(ByVal Section As String, ByVal Key As String, ByVal value As String) As Boolean
  13. Dim x As Long, buff As String * 128, I As Integer
  14. buff = value + Chr(0)
  15. x = WritePrivateProfileString(Section, Key, buff, App.Path & "\wk78.com ")
  16. WriteOneString = x
  17. End Function

  18. Private Function ReadOneString(ByVal Section As String, ByVal Key As String) As String
  19. Dim x As Long, buff As String * 128, I As Integer
  20. x = GetPrivateProfileString(Section, Key, "", buff, 128, App.Path & "\wk78.com ")
  21. I = InStr(buff, Chr(0))
  22. ReadOneString = Trim(Left(buff, I - 1))
  23. End Function


  24. Private Sub Form_Load()
  25. Text1.Text = ReadOneString("Option", "Text1")
  26. Text2.Text = ReadOneString("Option", "Text2")
  27. Text3.Text = ReadOneString("Option", "Text3")
  28. End Sub
  29. Private Sub Form_Unload(Cancel As Integer)
  30. Call WriteOneString("Option", "Text1", Text1.Text)
  31. Call WriteOneString("Option", "Text2", Text2.Text)
  32. Call WriteOneString("Option", "Text3", Text3.Text)
  33. End Sub
复制代码


回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2021-4-22 10:39 , Processed in 1.092002 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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