我要把VB.6中保存的数据写进.INI文件,请问怎么实现?在线等待

wangwei1980 2003-05-06 03:15:37
我要把VB.6中保存的数据写进.INI文件,请问怎么实现?
...全文
45 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
大智 Kevin 2003-05-06
  • 打赏
  • 举报
回复
Option Explicit
Public InifileName As String
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

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 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
'从ini文件里读取字符串
Public Function GetIniS(ByVal SectionName As String, ByVal KeyWord As String, _
ByVal DefString As String) As String
Dim ResultString As String * 256
Dim Temp As Integer
Temp = GetPrivateProfileString(SectionName, KeyWord, "", ResultString, 256, InifileName)
If Temp > 0 Then
ResultString = Trim(ResultString)
Else
ResultString = DefString
End If
GetIniS = delspace(ResultString)
End Function
'从ini文件里读取数字
Function GetIniN(ByVal SectionName As String, ByVal KeyWord As String, _
ByVal DefValue As Integer) As Integer
GetIniN = GetPrivateProfileInt(SectionName, KeyWord, DefValue, InifileName)
End Function
'写字符串入ini文件里
Public Sub SetIniS(ByVal SectionName As String, ByVal KeyWord As String, _
ByVal ValStr As String)
Dim res As Integer
res = WritePrivateProfileString(SectionName, KeyWord, ValStr, InifileName)
End Sub
'写数字入ini文件里
Public Sub SetIniN(ByVal SectionName As String, ByVal KeyWord As String, _
ByVal ValInt As Integer)
Dim res As Integer, s As String
s = Str$(ValInt)
res = WritePrivateProfileString(SectionName, KeyWord, s$, InifileName)
End Sub
'例
'用ini文件保存窗体属性
Public Sub SFP(frmname As Form)
On Error Resume Next
SetIniN frmname.name, "top", frmname.Top
SetIniN frmname.name, "left", frmname.Left
SetIniN frmname.name, "width", frmname.width
SetIniN frmname.name, "height", frmname.Height
SetIniN frmname.name, "windowstate", frmname.WindowState
End Sub
'从ini文件中读取窗体属性
Public Sub GfP(frmname As Form)
On Error Resume Next
Dim itemp As Integer

itemp = GetIniN(frmname.name, "width", 0)
If itemp <> 0 Then
frmname.width = GetIniN(frmname.name, "width", 0)
End If
itemp = GetIniN(frmname.name, "height", 0)
If itemp <> 0 Then
frmname.Height = GetIniN(frmname.name, "height", 0)
End If
frmname.Top = GetIniN(frmname.name, "top", (Screen.Height - frmname.Height) / 2)
frmname.Left = GetIniN(frmname.name, "left", (Screen.width - frmname.width) / 2)
frmname.WindowState = GetIniN(frmname.name, "windowstate", 0)
End Sub

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧