求读取修改ini的源码。。。网上的看不懂

小步凡 2014-03-19 08:19:33
读取“plu.ini”查找“skiptobnet = 任意整数(0,1,2.。。。)”
如果有
修改为 “skiptobnet = 1 ” --------(如果这一步为删除skiptobnet,也帮忙写下吧)
保存(只读也能保存)
如果没有
结束程序

求大大帮写下 。。。。。。。
...全文
204 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
小步凡 2014-03-29
  • 打赏
  • 举报
回复
引用 14 楼 of123 的回复:
没有任何问题。
Option Explicit
Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long

Private Sub Command1_Click()
Dim skiptobnet_Value As Long, ActivePlugin_Value As Long

skiptobnet_Value = GetPrivateProfileInt("LAUNCHING", "skiptobnet", -1, "E:\plu.ini")
Debug.Print "skiptobnet = " & skiptobnet_Value

ActivePlugin_Value = GetPrivateProfileInt("GENERAL", "ActivePlugin", -1, "E:\plu.ini")
Debug.Print "ActivePlugin = " & ActivePlugin_Value
End Sub
skiptobnet = 1
ActivePlugin = 1
问下我运行了为什么ini没有改呢?我已经创建了一个command按钮,点了没反应。。。
of123 2014-03-27
  • 打赏
  • 举报
回复
没有任何问题。
Option Explicit
Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long

Private Sub Command1_Click()
Dim skiptobnet_Value As Long, ActivePlugin_Value As Long

skiptobnet_Value = GetPrivateProfileInt("LAUNCHING", "skiptobnet", -1, "E:\plu.ini")
Debug.Print "skiptobnet = " & skiptobnet_Value

ActivePlugin_Value = GetPrivateProfileInt("GENERAL", "ActivePlugin", -1, "E:\plu.ini")
Debug.Print "ActivePlugin = " & ActivePlugin_Value
End Sub
skiptobnet = 1
ActivePlugin = 1
小步凡 2014-03-26
  • 打赏
  • 举报
回复
引用 10 楼 of123 的回复:
检查你的文本文件的格式。或者重新写一个,要严格按照格式规范。
要不你把上面的内容复制过去试下看看。。。
小步凡 2014-03-26
  • 打赏
  • 举报
回复
引用 10 楼 of123 的回复:
检查你的文本文件的格式。或者重新写一个,要严格按照格式规范。


这是ini内容,是这种格式吗?


[LAUNCHING]
Param=
Library=PlugY.dll
skiptobnet = 1

[GENERAL]
ActivePlugin=1
ActiveLogFile=0
DllToLoad=
DllToLoad2=
ActiveCommands=1
ActiveCheckMemory=0


[LANGUAGE]
;ENG|ESP|DEU|FRA|POR|ITA|JPN|KOR|SIN|CHI|POL|RUS
ActiveChangeLanguage=1
SelectedLanguage=CHI


[SAVEPATH]
ActiveSavePathChange=1
SavePath=MDSave\
ddan 2014-03-26
  • 打赏
  • 举报
回复
自己添加一个类就好了
of123 2014-03-26
  • 打赏
  • 举报
回复
检查你的文本文件的格式。或者重新写一个,要严格按照格式规范。
小步凡 2014-03-25
  • 打赏
  • 举报
回复
引用 8 楼 of123 的回复:
Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long

Dim skiptobnet_Value As Long, ActivePlugin_Value As Long

skiptobnet_Value = GetPrivateProfileInt("LAUNCHING", "skiptobnet", -1, "E:\plu.ini")
ActivePlugin_Value = GetPrivateProfileInt("GENERAL", "ActivePlugin", -1, "E:\plu.ini")



运行了说这个 "LAUNCHING", 为无效外部过程怎么回事?ini里有这个啊
of123 2014-03-25
  • 打赏
  • 举报
回复
Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long

Dim skiptobnet_Value As Long, ActivePlugin_Value As Long

skiptobnet_Value = GetPrivateProfileInt("LAUNCHING",  "skiptobnet", -1, "E:\plu.ini")
ActivePlugin_Value = GetPrivateProfileInt("GENERAL",  "ActivePlugin", -1, "E:\plu.ini")
yiyaozjk 2014-03-24
  • 打赏
  • 举报
回复
值得学习,用.ini与文本文件 OPEN AS #1有什么区别 吗?我没有具体运用过。。 楼上的能说一下区别吗?下次我也用
小步凡 2014-03-24
  • 打赏
  • 举报
回复
引用 5 楼 NotBack 的回复:
类方法说明: ini内格式: [类别名] 键=键值 SetFileName(参数为ini文件的全路径文件名) GetValue(类别名,键) 返回键值 SetValue(类别名,键,键值)
大神,写这么多辛苦了,能不能按我2楼说的那个例子写下,小白很无力。。。。。。。。
notback 2014-03-24
  • 打赏
  • 举报
回复
类方法说明: ini内格式: [类别名] 键=键值 SetFileName(参数为ini文件的全路径文件名) GetValue(类别名,键) 返回键值 SetValue(类别名,键,键值)
notback 2014-03-24
  • 打赏
  • 举报
回复
开一个文本本文件,复制以下代码:

VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "INIFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Dim Ret As Long
Dim Start As Long
Private FileName As String
Const BufSize = 10240
Dim buf As String * BufSize

Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, 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
Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, 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


Public Sub SetFileName(ArgFileName As String)
    FileName = ArgFileName
End Sub


 

Public Sub SetValue(ByVal clsName As String, ByVal key As String, ByVal V As String)
    Ret = WritePrivateProfileString(clsName, key, V, FileName)
End Sub

 

Public Function GetValue(ByVal clsName As String, ByVal key As String) As String
    Ret = GetPrivateProfileString(clsName, key, "", buf, BufSize, FileName)
    Start = 1
    GetValue = RetStr()
End Function

 

Private Function RetStr() As String
     Dim i As Long
     i = InStr(Start, buf, Chr(0))
     If i > Start Then
       RetStr = Mid(buf, Start, i - Start)
     End If
     Start = i + 1
End Function
保存为inifile.cls 这是我自己写的ini读取写入类模块,可以直接引用到工程中去。
小步凡 2014-03-23
  • 打赏
  • 举报
回复
有人会啊。。。。。。。。。。。。。。。。。
小步凡 2014-03-20
  • 打赏
  • 举报
回复
引用 1 楼 manpuku 的回复:

Declare Function GetPrivateProfileInt Lib "Kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFilename As String) As Long
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
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

dim IniString As String * 255, I%
Dim x As Variant
dim tmpInt as intger
dim tmpStr as string
'读int类型ini,格式(段名,字段名,默认值,路径)
 tmpIni = GetPrivateProfileInt("KeyUse", "skiptobnet ", 0, Path$)
'读string类型ini格式(段名,字段名,默认值,用于储存字段值的变量,字符长度,路径)
 I = GetPrivateProfileString("KeyUse", "skiptobnet ", "*", IniString, 255, Path$)
'写ini格式(段名,字段名,需要写入的值,注意必须先转换为string,路径)
 x = WritePrivateProfileString("KeyUse", "skiptobnet ", CStr(skiptobnet ), Path$)



vb说 Dim tmpInt As intger这一句用户定义类型未定义。。。 能不能写的傻瓜点,就是按我说的写下,就是写好能运行的代码? ini文件有这些: [LAUNCHING] skiptobnet = 1 [GENERAL] ActivePlugin=1 读取“E:\plu.ini” 查找“skiptobnet “ ”ActivePlugin“ 如果有 删除“skiptobnet “ ”ActivePlugin“ 保存(只读也能保存) 如果没有 结束程序
manpuku 2014-03-20
  • 打赏
  • 举报
回复

Declare Function GetPrivateProfileInt Lib "Kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFilename As String) As Long
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
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

dim IniString As String * 255, I%
Dim x As Variant
dim tmpInt as intger
dim tmpStr as string
'读int类型ini,格式(段名,字段名,默认值,路径)
 tmpIni = GetPrivateProfileInt("KeyUse", "skiptobnet ", 0, Path$)
'读string类型ini格式(段名,字段名,默认值,用于储存字段值的变量,字符长度,路径)
 I = GetPrivateProfileString("KeyUse", "skiptobnet ", "*", IniString, 255, Path$)
'写ini格式(段名,字段名,需要写入的值,注意必须先转换为string,路径)
 x = WritePrivateProfileString("KeyUse", "skiptobnet ", CStr(skiptobnet ), Path$)



7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧