VB2010 如何创建txt或ini文档,并进行读写功能
关于一个ini自动配置的问题。首先是自动判断该文档存在不存在,如果不存在自动创建。然后,我有一个ComboBox1,第一次打开的时候自己动手写进去,后面每次打开界面就会自...
关于一个ini自动配置的问题。
首先是自动判断该文档存在不存在,如果不存在自动创建。
然后,我有一个ComboBox1,第一次打开的时候自己动手写进去,后面每次打开界面就会自动读出来,当更改以后,点击Button1又写进ini文件里面.还有一个要求,要具体读到哪一行,比如:我的第三行;SetTing3=8,,然后就可以读出8.。也就是能够读写,并且具体要读写到冒一行。
回答精彩再加分!!! 展开
首先是自动判断该文档存在不存在,如果不存在自动创建。
然后,我有一个ComboBox1,第一次打开的时候自己动手写进去,后面每次打开界面就会自动读出来,当更改以后,点击Button1又写进ini文件里面.还有一个要求,要具体读到哪一行,比如:我的第三行;SetTing3=8,,然后就可以读出8.。也就是能够读写,并且具体要读写到冒一行。
回答精彩再加分!!! 展开
2014-06-30
展开全部
Option Explicit
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 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
Dim iniFileName As String
Private Sub Form_Load()
Dim myUser As String
If Right(App.Path, 1) <> "\" Then
iniFileName = App.Path & "\" & "1.ini"
Else
iniFileName = App.Path & "1.ini"
End If
myUser = Trim$(ReadIni(iniFileName, "USER", "UserName"))
If myUser <> "" Then
Combo1.AddItem myUser
End If
End Sub
Private Sub Command1_Click()
Dim myUser As String
myUser = Text1.Text
WriteIniFile iniFileName, "USER", "UserName", myUser
End Sub
Private Sub WriteIniFile(ByVal Filename As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
Call WritePrivateProfileString(Section, Key, Value, Filename)
End Sub
Private Function ReadIni(ByVal Filename As String, ByVal Section As String, ByVal Key As String) As String
Dim x As Long, Buff As String * 256, i As Integer
x = GetPrivateProfileString(Section, Key, "", Buff, 256, Filename)
i = InStr(Buff, Chr(0))
ReadIni = Trim$(Left(Buff, i - 1))
End Function
想读写哪项,指定 Section,Key,等
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 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
Dim iniFileName As String
Private Sub Form_Load()
Dim myUser As String
If Right(App.Path, 1) <> "\" Then
iniFileName = App.Path & "\" & "1.ini"
Else
iniFileName = App.Path & "1.ini"
End If
myUser = Trim$(ReadIni(iniFileName, "USER", "UserName"))
If myUser <> "" Then
Combo1.AddItem myUser
End If
End Sub
Private Sub Command1_Click()
Dim myUser As String
myUser = Text1.Text
WriteIniFile iniFileName, "USER", "UserName", myUser
End Sub
Private Sub WriteIniFile(ByVal Filename As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
Call WritePrivateProfileString(Section, Key, Value, Filename)
End Sub
Private Function ReadIni(ByVal Filename As String, ByVal Section As String, ByVal Key As String) As String
Dim x As Long, Buff As String * 256, i As Integer
x = GetPrivateProfileString(Section, Key, "", Buff, 256, Filename)
i = InStr(Buff, Chr(0))
ReadIni = Trim$(Left(Buff, i - 1))
End Function
想读写哪项,指定 Section,Key,等
追问
这个是vb6吧 !我想要的是2010vb。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询