| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 871 人关注过本帖, 1 人收藏
标题:VB读取和保存INI文件问题!
只看楼主 加入收藏
a6408425
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-7-9
收藏(1)
 问题点数:0 回复次数:2 
VB读取和保存INI文件问题!
ini文件保存内容为
a=123
b=456
c=789
现在把a读取到Text1
b Text2
c Text3
如果打开程序后在Text1-3中更改信息就会自动保存到ini文件相应问位置

另外最好加上只有选择了才可以保存不选择不保存!
搜索更多相关主题的帖子: INI 文件 保存 
2008-05-02 12:58
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CIniFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

''''--------classIniFile.cls  代码----------------
''''这里定义了一个classIniFile类
''''一个绝对经典的在VB中操作.ini文件的通用类源代码
''''程序编写:中国青岛·许家国
''''    2002.6.16
''''E-Mail: goj2000@
''''HomePage: http://www.
''''

''''Private  member  that  holds  a  reference  to
''''the  path  of  our  ini  file

Private strINI As String

''''Windows  API  Declares
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 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 Function MakePath(ByVal strDrv As String, ByVal strDir As String) As String

    ''''  Makes  an  INI  file:  Guarantees  a  sub  dir
    Do While Right$(strDrv, 1) = "\"
          strDrv = Mid(strDrv, 1, Len(strDrv) - 1)
    Loop
   
    Do While Mid(strDir, 1, 1) = "\"
          strDir = Mid(strDir, 2)
    Loop
   
    ''''  Return  the  path
    MakePath = strDrv & "\" & strDir
End Function

Private Sub CreateIni(strDrv As String, strDir As String)
    ''''  Make  a  new  ini  file
    strINI = MakePath(strDrv, strDir)
End Sub

Public Sub WriteIniKey(ByVal strSection As String, ByVal strKey As String, ByVal strValue As String)
    ''''  Write  to  strINI
    WritePrivateProfileString strSection, strKey, strValue, strINI
End Sub

Public Function GetIniKey(ByVal strSection As String, strKey As String) As String
    Dim strTmp As String
    Dim lngRet As String
    Dim i As Integer
    Dim strTmp2 As String
   
    strTmp = String$(1024, Chr(32))
    lngRet = GetPrivateProfileString(strSection, strKey, "", strTmp, Len(strTmp), strINI)
    strTmp = Trim(strTmp)
    strTmp2 = ""
    For i = 1 To Len(strTmp)
        If Asc(Mid(strTmp, i, 1)) <> 0 Then
            strTmp2 = strTmp2 + Mid(strTmp, i, 1)
        End If
    Next i
    strTmp = strTmp2
   
    GetIniKey = strTmp
End Function

Public Property Let INIFileName(ByVal New_IniPath As String)
    ''''  Sets  the  new  ini  path
    strINI = New_IniPath
End Property

Public Property Get INIFileName() As String
    ''''  Returns  the  current  ini  path
    INIFileName = strINI
End Property

''''***************************************清除KeyWord"键"(Sub)***********************************************
Public Function DelIniKey(ByVal SectionName As String, ByVal KeyWord As String)
    Dim retval As Integer
    retval = WritePrivateProfileString(SectionName, KeyWord, 0&, strINI)
End Function

''''如果是清除section就少写一个Key多一个""。
''''**************************************清除 Section"段"(Sub)***********************************************
Public Function DelIniSec(ByVal SectionName As String)      ''''清除section
    Dim retval As Integer
    retval = WritePrivateProfileString(SectionName, 0&, "", strINI)
End Function
2008-05-03 09:04
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
保存为cls,然后调用
2008-05-03 09:06
快速回复:VB读取和保存INI文件问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.052369 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved