vb 如何读取 inifile 文件 10
想要把最后shell打开的txt文档部分的路径通过inifile里的logpath指定的路径加上既存的strpath打开。求ini的指定方法和最后一段shell部分的代码...
想要把最后shell 打开的txt文档部分的路径 通过inifile 里的logpath 指定的路径 加上既存的strpath 打开。求ini的指定方法 和最后一段shell 部分的代码写法。
iniflie 存在路径是 C:\abc.ini
想要链接这个ini 里面的 关键词 logpath = C:\abc\log\
Private Sub grdTorikomiRireki_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdTorikomiRireki.CellClick
Dim strpath As String
If grdTorikomiRireki.Columns(e.ColumnIndex).Name = "ErrorLogPath" Then
strpath = Me.grdTorikomiRireki.CurrentCell.Value
Shell("notepad " + strpath)
End If 展开
iniflie 存在路径是 C:\abc.ini
想要链接这个ini 里面的 关键词 logpath = C:\abc\log\
Private Sub grdTorikomiRireki_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdTorikomiRireki.CellClick
Dim strpath As String
If grdTorikomiRireki.Columns(e.ColumnIndex).Name = "ErrorLogPath" Then
strpath = Me.grdTorikomiRireki.CurrentCell.Value
Shell("notepad " + strpath)
End If 展开
展开全部
利用系统API函数 GetPrivateProfileString 可以方便地读取ini文件。使用方法如下
(1)MyApp.INI文件的内容为
VB程序读取这个ini文件,将窗口的标题换为Title指定的字符串
(2)新建一个VB工程
(3)Form1窗体代码
Option Explicit
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringW" _
(ByVal lpApplicationName As Long, _
ByVal lpKeyName As Long, _
ByVal lpDefault As Long, _
ByVal lpReturnedString As Long, _
ByVal nSize As Long, _
ByVal lpFileName As Long) As Long
'------------
'读INI文件
'------------
Private Function GetValueFromINIFile(ByVal SectionName As String, _
ByVal KeyName As String, _
ByVal IniFileName As String) As String
Dim strBuf As String
'128个字符,初始化时用 0 填充
strBuf = String(128, 0)
GetPrivateProfileString StrPtr(SectionName), _
StrPtr(KeyName), _
StrPtr(""), _
StrPtr(strBuf), _
128, _
StrPtr(IniFileName)
'去除多余的 0
strBuf = Replace(strBuf, Chr(0), "")
GetValueFromINIFile = strBuf
End Function
Private Sub Form_Load()
Dim title As String
'读取INI文件中指定的节和节/键
'节的名称:AppName
'键名称:Title
title = GetValueFromINIFile("AppName", "Title", "c:\MyApp.INI")
Me.Caption = title
End Sub
(4)运行效果
窗口的标题被设置Ini文件指定的字符串!
(1)MyApp.INI文件的内容为
VB程序读取这个ini文件,将窗口的标题换为Title指定的字符串
(2)新建一个VB工程
(3)Form1窗体代码
Option Explicit
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringW" _
(ByVal lpApplicationName As Long, _
ByVal lpKeyName As Long, _
ByVal lpDefault As Long, _
ByVal lpReturnedString As Long, _
ByVal nSize As Long, _
ByVal lpFileName As Long) As Long
'------------
'读INI文件
'------------
Private Function GetValueFromINIFile(ByVal SectionName As String, _
ByVal KeyName As String, _
ByVal IniFileName As String) As String
Dim strBuf As String
'128个字符,初始化时用 0 填充
strBuf = String(128, 0)
GetPrivateProfileString StrPtr(SectionName), _
StrPtr(KeyName), _
StrPtr(""), _
StrPtr(strBuf), _
128, _
StrPtr(IniFileName)
'去除多余的 0
strBuf = Replace(strBuf, Chr(0), "")
GetValueFromINIFile = strBuf
End Function
Private Sub Form_Load()
Dim title As String
'读取INI文件中指定的节和节/键
'节的名称:AppName
'键名称:Title
title = GetValueFromINIFile("AppName", "Title", "c:\MyApp.INI")
Me.Caption = title
End Sub
(4)运行效果
窗口的标题被设置Ini文件指定的字符串!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询