VB.NET经过长时间的发展,很多用户都很了解VB.NET了,这里我发表一下关于读写VB.NET INI文件个人理解,和大家分享一下。
#T#自从注册表诞生以来ini文件正在逐渐失去其市场占有率,然而基于ini文件的独立性,致使其还没有到达退出历史舞台的地步,很多应用程序的初始化和一些界面参数的设置仍然很愿意从ini文件中读取,为了保证操作需用参数对ini文件的读取的通明性,建议使用一个模块来完成此工作。注:所有操作调用标准的WinAPI函数来完成。读写VB.NET INI文件例子代码:
- DimRetAsLong
- DimStartAsLong
- PublicFileNameAsString
- ConstBufSize=10240
- DimbufAsString*BufSize
- PrivateDeclareFunctionGetPrivateProfileIntLib"kernel32"Alias"GetPrivateProfileIntA"
- (ByVallpApplicationNameAsString,ByVallpKeyNameAsString,ByValnDefaultAsLong,ByVallpFileNameAsString)AsLong
- PrivateDeclareFunctionGetPrivateProfileSectionLib"kernel32"Alias"GetPrivateProfileSectionA"
- (ByVallpAppNameAsString,ByVallpReturnedStringAsString,ByValnSizeAsLong,ByVallpFileNameAsString)AsLong
- PrivateDeclareFunctionGetPrivateProfileStringLib"kernel32"Alias"GetPrivateProfileStringA"
- (ByVallpApplicationNameAsString,ByVallpKeyNameAsAny,ByVallpDefaultAsString,ByVallpReturnedStringAsString,ByValnSizeAsLong,ByVallpFileNameAsString)AsLong
- PrivateDeclareFunctionWritePrivateProfileSectionLib"kernel32"Alias"WritePrivateProfileSectionA"
- (ByVallpAppNameAsString,ByVallpStringAsString,ByVallpFileNameAsString)AsLong
- PrivateDeclareFunctionWritePrivateProfileStringLib"kernel32"Alias"WritePrivateProfileStringA"
- (ByVallpApplicationNameAsString,ByVallpKeyNameAsAny,ByVallpStringAsAny,ByVallpFileNameAsString)AsLong
- PublicSubSetValue(ByValclsNameAsString,ByValkeyAsString,ByValVAsString)
- Ret=WritePrivateProfileString(clsName,key,V,FileName)
- EndSub
- PublicFunctionGetValue(ByValclsNameAsString,ByValkeyAsString)AsString
- Ret=GetPrivateProfileString(clsName,key,"",buf,BufSize,FileName)
- Start=1
- GetValue=RetStr()
- EndFunction
- PrivateFunctionRetStr()AsString
- DimiAsLong
- i=InStr(Start,buf,Chr(0))
- Ifi>StartThen
- RetStr=Mid(buf,Start,i-Start)
- EndIf
- Start=i+1
- EndFunction
上面就是一个读写VB.NET INI文件的例子,希望对大家有用。