下面是个简单易学的vb建立与读取.ini文件教程,图老师小编详细图解介绍包你轻松学会,喜欢的朋友赶紧get起来吧!
【 tulaoshi.com - 编程语言 】
虽然进入win95之後,一般读写ini文件被读写Registry所取代,但我们还是可以透过
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)win31的传统方式读写ini文件,以存程式目前的相关设定,而於下一次程式执行时再读回来。目前建议使用GetSetting SaveSetting的方式存於Registry中,不用目前的方式。 储存程式的设定
'请於form中放3个TextBox,一个CommandBoxPrivate 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 LongPrivate Declare Function WritePrivateProfileString Lib "kernel32" _ Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, ByVal lpString As Any, _ ByVal lpFileName As String) As LongPrivate Sub Command1_Click()Dim success As Longsuccess = WritePrivateProfileString("MyApp", "text1", Text1.Text, "c:aa.ini")'叁数一 Section Name'叁数二 於.ini中的项目'叁数三 项目的内容'叁数四 .ini文件的名称success = WritePrivateProfileString("MyApp", "text2", Text2.Text, "c:aa.ini")success = WritePrivateProfileString("MyApp2", "text3", Text3.Text, "c:aa.ini")End SubPrivate Sub Form_load()Dim ret As LongDim buff As Stringbuff = String(255, 0)ret = GetPrivateProfileString("Myapp", "text1", "text1", buff, 256, "c:aa.ini")'若.ini MyApp中无text1,则采用叁数三的值Text1.Text = buffbuff = String(255, 0)ret = GetPrivateProfileString("Myapp", "text2", "text2", buff, 256, "c:aa.ini")Text2.Text = buffbuff = String(255, 0)ret = GetPrivateProfileString("Myapp2", "text3", "text3", buff, 256, "c:aa.ini")Text3.Text = buffEnd Sub(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
来源:http://www.tulaoshi.com/n/20160219/1613346.html
看过《vb建立与读取.ini文件》的人还看了以下文章 更多>>