编了一个程序,使用时需要在文本框控件中输入一些字符,为了避免每次打开都重复这样的输入,如何保存当前输入的信息,以供下次再用。是不是编个.ini文件,那又怎么编呢?

解决方案 »

  1.   

    GetPrivateProfileString   
        
      【操作系统】   
      Win9X:Yes   
      WinNT:Yes   
        
      【声明】   
      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   
        
      【说明】   
        
          为初始化文件中指定的条目取得字串     
        
      【返回值】   
        
          Long,复制到lpReturnedString缓冲区的字节数量,其中不包括那些NULL中止字符。如lpReturnedString缓冲区不够大,不能容下全部信息,就返回nSize-1(若lpApplicationName或lpKeyName为NULL,则返回nSize-2)     
        
      【其它】   
        
          在vb的api文本查看器中复制的声明为: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   
        
      【参数表】   
          lpApplicationName   -     String,欲在其中查找条目的小节名称。这个字串不区分大小写。如设为vbNullString,就在lpReturnedString缓冲区内装载这个ini文件所有小节的列表   
        
          lpKeyName   ------     String,欲获取的项名或条目名。这个字串不区分大小写。如设为vbNullString,就在lpReturnedString缓冲区内装载指定小节所有项的列表   
        
          lpDefault   ------     String,指定的条目没有找到时返回的默认值。可设为空("")   
        
          lpReturnedString   -     String,指定一个字串缓冲区,长度至少为nSize   
        
          nSize   ----------     Long,指定装载到lpReturnedString缓冲区的最大字符数量   
        
          lpFileName   -----     String,初始化文件的名字。如没有指定一个完整路径名,windows就在Windows目录中查找文件   Declare   Function   GetPrivateProfileInt   Lib   "kernel32.dll"   Alias   "GetPrivateProfileIntA"   (ByVal   lpApplicationName   As   String,   ByVal   lpKeyName   As   String,   ByVal   nDefault   As   Long,   ByVal   lpFileName   As   String)   As   Long     
        
      Platforms:   Win   32s,   Win   95/98,   Win   NT     
        
      GetPrivateProfileInt   reads   an   integer   value   from   any   INI   file.   The   parameters   passed   to   the   function   specify   which   value   will   be   read   from.   If   successful,   the   function   returns   the   value   read.   If   the   value   you   specify   does   not   exist   or   is   a   string   (i.e.,   not   a   number),   the   value   specified   as   nDefault   is   returned.   Note   that   INI   file   support   is   only   provided   in   Windows   for   backwards   compatibility;   using   the   registry   to   store   information   is   preferred.     
        
      lpApplicationName   
      The   header   of   the   INI   file   section   the   value   is   in.     
      lpKeyName   
      The   name   of   the   value   to   read.     
      nDefault   
      The   value   to   return   if   a   valid   value   cannot   be   read.   Make   it   something   that   would   definitely   not   be   read,   such   as   -1.     
      lpFileName   
      The   filename   of   the   INI   file   to   read   from.     
      Example:     
        
      '   Read   the   "version"   value   under   the   "[programinfo]"   section   
      '   of   the   INI   file   C:\MyProgram\config.ini   
      Dim   version   As   Long     '   receives   the   value   returned   from   the   INI   file   
        
      '   Read   the   value   from   the   INI   file,   returning   -1   if   it   can't   find   the   value   
      version   =   GetPrivateProfileInt("programinfo",   "version",   -1,   "C:\MyProgram\config.ini")   
      '   Display   the   result   
      If   version   =   -1   Then     '   failure   
          Debug.Print   "Could   not   read   the   information   from   the   INI   file."   
      Else   
          Debug.Print   "Version   number:";   version   
      End   If   
      
      

  2.   

    用label,或者是.res文件,很方便。
      

  3.   

    还是按一楼的来个ini文件吧
    觉得ini文件挺好的
    读写也方便
    更何况很多大公司的大系统都在用
    呵呵
    一楼讲的也算详细了