永发信息网

vb中怎么创建ini文件

答案:3  悬赏:20  手机版
解决时间 2021-03-20 00:14
  • 提问者网友:呐年旧曙光
  • 2021-03-19 07:51
vb中怎么创建ini文件
最佳答案
  • 五星知识达人网友:迷人又混蛋
  • 2021-03-19 09:29
VB操作INI文件示例:

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 A As Long
Dim B As String
B = App.Path
'写信息
'修改SET.INI文件中MAIN字段中HP的值为当前程序路径
'如果该文件不存在会自动建立,当函数返回值为0时说明修改不成功
A = WritePrivateProfileString("MAIN", "HP", B, App.Path & "\SET.INI")
If A = 0 Then MsgBox ("写文件时出错")
End Sub

Private Sub Command2_Click()
Dim A As Long
Dim T As String
'读取信息
T = Space$(1000) '事先定义读取值的字串宽度
'读取SET.INI文件中TIP字段中MAIN的值并打印出来
'当函数返回值为0时说明读取数据出错
A = GetPrivateProfileString("MAIN", "HP", "", T, 1000, App.Path & "\SET.INI")
If A = 0 Then MsgBox "找不到所需字段": Exit Sub
Print Left$(T, Len(Trim$(T)) - 1)
End Sub
全部回答
  • 1楼网友:舍身薄凉客
  • 2021-03-19 10:36

dim testline as string private sub form_load() if dir("f:\test.ini") = "" then else open "f:\test.ini" for input as #1 input #1, testline close #1 text1.text = testline end if end sub

private sub form_unload(cancel as integer) open "f:\test.ini" for output as #1 print #1, text1.text, option1.value, option2.value, check1.value close #1 end sub

  • 2楼网友:七十二街
  • 2021-03-19 10:25
Open App.Path + "E:\test.ini" For Output As #1 Print #1, 你需要存的信息 Close #1
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯