CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

初级读取ini文件问题

楼主wolfwar(下雪的云)2006-03-16 14:17:02 在 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  
   
  '写出INI  
  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   mydb   As   String  
  Dim   n   As   Integer  
  n   =   GetPrivateProfileString("www",   "fff",   "aaaaaa",   mydb,   Len(mydb),   "D:\Program   Files\Microsoft   Visual   Studio\VB98\恒生配置文件修改工具\fcy.ini")  
  MsgBox   (n)  
  Text1.Text   =   mydb  
  End   Sub  
   
  这是fcy.ini文件内容  
  [www]  
  ffff   =   333  
   
  得出n的值为0   ,大家帮我看看,具体是哪里不对,谢谢各位 问题点数:20、回复次数:9Top

1 楼tztz520(午夜逛街)回复于 2006-03-16 14:19:15 得分 1

在这里搜一下吧.模块代码都有N多Top

2 楼bakw(好好潜水,天天UP)回复于 2006-03-16 14:29:03 得分 1

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   Integer,   ByVal   lpFileName   As   String)   As   Integer  
  Private   Declare   Function   WritePrivateProfileString   Lib   "kernel32"   Alias   "WritePrivateProfileStringA"   (ByVal   Appname   As   String,   ByVal   Keyname   As   Any,   ByVal   NewString   As   Any,   ByVal   FileName   As   String)   As   Integer  
  Private   Const   MAX_TEXT_LENGTH   =   1024  
   
  Private   Sub   SetIni(FileName   As   String,   Section   As   String,   Key   As   String,   Value   As   String)  
          WritePrivateProfileString   Section,   Key,   Value,   FileName  
  End   Sub  
   
  Private   Function   GetIni(FileName   As   String,   Section   As   String,   Key   As   String)   As   String  
          Dim   R   As   Integer  
          Dim   tStr   As   String  
          tStr   =   Space(MAX_TEXT_LENGTH)  
          GetPrivateProfileString   Section,   Key,   Chr(32),   tStr,   LenB(tStr),   FileName  
          tStr   =   Trim(Replace(tStr,   Chr(0),   Chr(32)))  
          GetIni   =   tStr  
  End   Function  
   
  =========================================  
  我是这么用的,这个可以Top

3 楼faysky2(出来混,迟早是要还嘀)回复于 2006-03-16 14:40:20 得分 1

Private   Sub   Command1_Click()  
   
   
          Dim   mydb   As   String   *   128  
          Dim   n   As   Integer  
          n   =   GetPrivateProfileString("www",   "fff",   "",   mydb,   Len(mydb),   "D:\Program   Files\Microsoft   Visual   Studio\VB98\恒生配置文件修改工具\fcy.ini")  
          MsgBox   (n)  
          Text1.Text   =   Trim(Left(mydb,   InStr(mydb,   Chr(0))   -   1))  
  End   Sub  
  Top

4 楼hgw520(飞天鲲鹏)回复于 2006-03-16 14:52:46 得分 3

GetPrivateProfileString语法错了  
  应该是:  
  GetPrivateProfileString("节名","项名","默认返回串","缓存",缓存大小,ini文件名)  
  这里的文件名包含完整路径!Top

5 楼hgw520(飞天鲲鹏)回复于 2006-03-16 14:54:34 得分 10

ffff   =   333  
  而你的项名是"fff"Top

6 楼cuizm(射天狼 http://www.j2soft.cn/)回复于 2006-03-16 15:08:45 得分 1

'************************************************************************  
  '文件名:     clsOA.cls  
  '功能用途:读取OA配置文件内容,取得数据连接的有关信息  
  '创建人:     崔占民  
  '创建日期:2006-02-28  
  '修改人:  
  '修改日期:  
  '版权:  
  '函数说明:  
  '类说明:  
  '  
  '************************************************************************  
   
  'INI文件操作函数  
  Private   Declare   Function   GetPrivateProfileStringByKeyName&   Lib   "kernel32"   Alias   "GetPrivateProfileStringA"   (ByVal   lpApplicationName$,   ByVal   lpszKey$,   ByVal   lpszDefault$,   ByVal   lpszReturnBuffer$,   ByVal   cchReturnBuffer&,   ByVal   lpszFile$)  
  Private   Declare   Function   GetPrivateProfileStringKeys&   Lib   "kernel32"   Alias   "GetPrivateProfileStringA"   (ByVal   lpApplicationName$,   ByVal   lpszKey&,   ByVal   lpszDefault$,   ByVal   lpszReturnBuffer$,   ByVal   cchReturnBuffer&,   ByVal   lpszFile$)  
  Private   Declare   Function   GetPrivateProfileStringSections&   Lib   "kernel32"   Alias   "GetPrivateProfileStringA"   (ByVal   lpApplicationName&,   ByVal   lpszKey&,   ByVal   lpszDefault$,   ByVal   lpszReturnBuffer$,   ByVal   cchReturnBuffer&,   ByVal   lpszFile$)  
  Private   Declare   Function   WritePrivateProfileStringByKeyName&   Lib   "kernel32"   Alias   "WritePrivateProfileStringA"   (ByVal   lpApplicationName   As   String,   ByVal   lpKeyName   As   String,   ByVal   lpString   As   String,   ByVal   lplFileName   As   String)  
  Private   Declare   Function   WritePrivateProfileStringToDeleteKey&   Lib   "kernel32"   Alias   "WritePrivateProfileStringA"   (ByVal   lpApplicationName   As   String,   ByVal   lpKeyName   As   String,   ByVal   lpString   As   Long,   ByVal   lplFileName   As   String)  
  Private   Declare   Function   WritePrivateProfileStringToDeleteSection&   Lib   "kernel32"   Alias   "WritePrivateProfileStringA"   (ByVal   lpApplicationName   As   String,   ByVal   lpKeyName   As   Long,   ByVal   lpString   As   Long,   ByVal   lplFileName   As   String)  
   
  '***************************************************  
  '名称:GetIniStringValue  
  '功能:读取INI文件内容  
  '输入:Section:扇区;Key:键值;File:文件全路径  
  '输出:  
  '返回:键值数据  
  '***************************************************  
  Public   Function   GetIniStringValue(Section   As   String,   Key   As   String,   File   As   String)   As   String  
          Dim   KeyValue   As   String  
          Dim   characters   As   Long  
                   
          KeyValue$   =   String$(128,   0)  
          characters   =   GetPrivateProfileStringByKeyName(Section$,   Key$,   "",   KeyValue$,   127,   File$)  
           
          If   characters   >   1   Then  
                KeyValue$   =   Left$(KeyValue$,   characters)  
          End   If  
                   
          GetPrivateStringValue   =   KeyValue$  
  End   Function  
   
   
  ╭════════════════════════════╮  
  ║                            ║  
  ║  免费的学习、交流、源码、工具网站,欢迎大家访问!  ║  
  ║  http://www.j2soft.cn/                  ║  
  ╰════════════════════════════╯Top

7 楼51365133(渊海)回复于 2006-03-16 15:15:52 得分 1

Private   Declare   Function   GetPrivateProfileString   Lib   "kernel32"   Alias   "GetPrivateProfileStringA"   (ByVal   lpApplicationName   As   String,   lpKeyName   As   Any,   ByVal   lpDefault   As   String,   ByVal   lpRetunedString   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   lplFileName   As   String)   As   Long  
   
   
  Public   Function   GetINI(AppName   As   String,   KeyName   As   String,   FileName   As   String)   As   String  
    Dim   RetStr   As   String  
    RetStr   =   String(255,   Chr(0))  
    GetINI   =   Left(RetStr,   GetPrivateProfileString(AppName,   ByVal   KeyName,   "",   RetStr,   Len(RetStr),   FileName))  
  End   Function  
   
  Public   Function   WriteIni(AppName   As   String,   KeyName   As   String,   InString   As   String,   FilePath   As   String)   As   String  
    Dim   r   As   Integer  
    r   =   WritePrivateProfileString(AppName,   KeyName,   InString,   FilePath)  
  End   Function  
  操作代码  
  Private   Sub   Write_Click()  
  Call   WriteIni("hoho",   Text1.Text,   Text2.Text,   "d:\a.ini")  
  End   Sub  
   
  Private   Sub   Read_Click()  
  Text2.Text   =   GetINI("hoho",   Text1.Text,   "d:\a.ini")  
  End   Sub  
  Top

8 楼cxianfa(含笑)回复于 2006-03-16 21:44:49 得分 1

想问下大家,一般s什么文件会用到Ini文件?Top

9 楼51365133(渊海)回复于 2006-03-16 22:18:23 得分 1

需要配置的   引用程序,只是提供给用户更好的文件结构.Top

相关问题

  • 关于读取.ini文件?
  • 读取.INI文件出错
  • 如何读取INI文件
  • 怎么读取.ini文件
  • 关于读取ini文件
  • 关于INI文件读取
  • 关于ini文件读取
  • 读取ini文件问题!
  • 菜鸟问题!读取.ini文件
  • 如何在asp中读取ini文件??

关键词

  • 文件
  • byval
  • retstr
  • lpapplicationname
  • getprivateprofilestringa
  • lpkeyname
  • getprivateprofilestring
  • keyvalue
  • appname
  • kernel32

得分解答快速导航

  • 帖主:wolfwar
  • tztz520
  • bakw
  • faysky2
  • hgw520
  • hgw520
  • cuizm
  • 51365133
  • cxianfa
  • 51365133

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo