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

wangwei1980 2003-05-06 03:15:37
我要把VB.6中保存的数据写进.INI文件,请问怎么实现?
...全文
6 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
大智 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
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-06 03:15
社区公告
暂无公告