读书人

新手学VB文件写操作的有关问题

发布时间: 2012-02-17 17:50:42 作者: rapoo

新手学VB,文件写操作的问题
例如c:\config.ini文件中数据如下:
BackupTime=12:30:00
PATH1=c:\ET\
PATH2=d:\AWVV\
Type=2

现程序中有4个text文本框,通过command1按钮对以上内容更改其时间、路径、及类型,这个程序如何写?
新手上路,多多关照

[解决办法]
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 Sub Command1_Click()
Dim Ret As String, NC As Long
Ret = vbNullString
WritePrivateProfileString "TEST ", "BackupTime ", Text1(0).Text, App.Path & "\test.ini "
WritePrivateProfileString "TEST ", "PATH1 ", Text1(1).Text, App.Path & "\test.ini "
WritePrivateProfileString "TEST ", "PATH2 ", Text1(2).Text, App.Path & "\test.ini "
WritePrivateProfileString "TEST ", "Type ", Text1(3).Text, App.Path & "\test.ini "

Ret = String(255, 0)
NC = GetPrivateProfileString( "TEST ", "BackupTime ", "Default ", Ret, 255, App.Path & "\test.ini ")
NC = GetPrivateProfileString( "TEST ", "PATH1 ", "Default ", Ret, 255, App.Path & "\test.ini ")
NC = GetPrivateProfileString( "TEST ", "PATH2 ", "Default ", Ret, 255, App.Path & "\test.ini ")
NC = GetPrivateProfileString( "TEST ", "Type ", "Default ", Ret, 255, App.Path & "\test.ini ")
If NC <> 0 Then Ret = Left$(Ret, NC)

End Sub


这个是写好的 可能有点不太精简 自己稍改一下吧 不过功能已经实现了!

读书人网 >VB

热点推荐