急求 TEXTBOX 保存内容,VB读写INI的代码(范例也行)

koolook 2008-03-26 04:15:43
一个textbox,要求在里面填写格式大约如"08:09:10"
一个command,为保存到INI...求以上代码及读写INI的代码,
不要有多余的码,哪位大哥帮帮手...万分感激...
...全文
101 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
barenx 2008-03-29

VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsIniFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' Ini File Functions Class
' Copyright (C) 1996, Jens Balchen
'
' Uses
'
' Exposes
' Function GetSetting
' Function SaveSetting
' Function GetSection
'
' Comments

Option Explicit

' --------
' Public
' --------
'
' Property for file to read
Public File As String

' ---------
' Private
' ---------
'
' API to read/write ini's
#If Win32 Then
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 Integer, ByVal lpFileName As String) As Integer
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal Appname As String, ByVal KeyName As Any, ByVal NewString As Any, ByVal Filename As String) As Integer
#Else
Private Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
Private Declare Function WritePrivateProfileString Lib "Kernel" (ByVal Appname As String, ByVal KeyName As Any, ByVal NewString As Any, ByVal Filename As String) As Integer
#End If

Sub DeleteSection(ByVal Section As String)

Dim retval As Integer

retval = WritePrivateProfileString(Section, 0&, "", File)

End Sub
Public Function SaveSetting(ByVal Section$, ByVal Key$, ByVal Value$)

Dim retval As Integer

SaveSetting = WritePrivateProfileString(Section$, Key$, Value$, File)

End Function

Public Function GetSetting(ByVal Section As String, ByVal KeyName As String) As String

Dim retval As Integer
Dim t As String * 255

' Get the value
retval = GetPrivateProfileString(Section, KeyName, "unknown value", t, Len(t), File)

' If there is one, return it
If retval > 0 Then
GetSetting = Left$(t, retval)
Else
GetSetting = vbNullString
End If

End Function

Public Function GetSection(ByVal Section As String, KeyArray() As String) As Integer

Dim retval As Integer
' Allocate space for return value
Dim t As String * 2500
Dim lastpointer As Integer
Dim nullpointer As Integer
Dim ArrayCount As Integer
Dim keystring As String

ReDim KeyArray(0)

' Get the value
retval = GetPrivateProfileString(Section, 0&, "", t, Len(t), File)

' If there is one, return it
If retval > 0 Then
'
' Separate the keys and store them in the array
nullpointer = InStr(t, Chr$(0))
lastpointer = 1
Do While (nullpointer <> 0 And nullpointer > lastpointer + 1)
'
' Extract key string
keystring = Mid$(t, lastpointer, nullpointer - lastpointer)
'
' Now add to array
ArrayCount = ArrayCount + 1
ReDim Preserve KeyArray(ArrayCount)
KeyArray(ArrayCount) = keystring
'
' Find next null
lastpointer = nullpointer + 1
nullpointer = InStr(nullpointer + 1, t, Chr$(0))
Loop
End If
'
' Return the number of array elements
GetSection = ArrayCount

End Function

回复
cbm6666 2008-03-26
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 String, ByVal lpFileName As String) As Long
Dim t1$, ininame$, Num1&, s
Private Sub Form_Load()
t1 = Space(1000)
ininame = "c:\kkk.INI"
Call GetPrivateProfileString("info", "name1", "", t1, 20, ininame)
s = Split(t1, " ")
Text1.Text = s(1)
End Sub

Private Sub Command1_Click()
Call WritePrivateProfileString("info", "name1", "1 " & Text1.Text, ininame)
Me.Caption = "已更新"
End Sub

回复
nixnybf69 2008-03-26
Public Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lplFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetunedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Public Function GetFromINI(AppName As String, KeyName As String, FileName As String) As String
Dim RetStr As String
RetStr = String(255, Chr(0))
GetFromINI = Left(RetStr, GetPrivateProfileString(AppName, ByVal KeyName, "", RetStr, Len(RetStr), FileName))
End Function
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7490

社区成员

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