CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
花落谁家,你作主! 盛大widget设计大赛英雄榜
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

发生声名错误

楼主moleboy(薄荷糖)2001-01-25 12:01:00 在 VB / 基础类 提问

如下声明:  
  Public   Declare   Function   GetTempFileName   Lib   "kernel32"   Alias   "GetTempFileNameA"   (ByVal   lpszPath   As   String,   ByVal   lpPrefixString   As   String,   ByVal   wUnique   As   Long,   ByVal   lpTempFileName   As   String)   As   Long  
  但是我在运行时VB总提示错误!请高手指正错误!  
  还有如何使用! 问题点数:20、回复次数:5Top

1 楼zyx29(Taburiss)回复于 2001-01-25 12:11:00 得分 10

GetTempFileName   Function  
  Declare   Function   GetTempFileName   Lib   "kernel32.dll"   Alias   "GetTempFileNameA"   (ByVal   lpszPath   As   String,   ByVal   lpPrefixString   As   String,   ByVal   wUnique   As   Long,   ByVal   lpTempFileName   As   String)   As   Long    
   
  Platforms:   Win   32s,   Win   95/98,   Win   NT    
   
  GetTempFileName   generates   a   filename   for   a   temporary   file   and   optionally   creates   it   for   you.   Temporary   files   are   used   to   store   data   for   short   periods   of   time   on   the   hard   drive.   The   full   filename,   including   the   path,   is   put   into   the   string   variable   passed   as   lpTempFileName.   The   format   of   the   generated   filename   is   path\xxxuuuu.TMP.   path   is   the   path   to   put   the   file   in,   preferably   the   temporary   directory   supplied   by   Windows,   which   can   be   gotten   through   GetTempPath.   xxx   is   the   string   specified   in   lpPrefixString.   uuuu   is   a   hexadecimal   number   between   0000   and   FFFF.   If   wUnique   is   non-zero,   uuuu   is   the   rightmost   four   digits   of   the   number   (in   hexadecimal),   and   the   file   is   not   created.   This   method   will   work   even   if   a   file   with   that   name   already   exists.   If   wUnique   is   zero,   uuuu   is   a   random   number   generated   by   Windows,   and   the   file   is   created.   Temporary   files   always   have   a   .TMP   extension.   The   function   returns   the   value   used   for   uuuu   if   successful,   or   0   if   an   error   occured.    
   
  lpszPath  
  The   path   to   put   the   temporary   file   into.   This   is   preferably   the   same   path   gotten   from   GetTempPath.    
  lpPrefixString  
  The   first   three   characters   of   the   filename.    
  wUnique  
  If   non-zero,   this   number's   last   four   digits   in   hexidecimal   are   the   last   four   characters   in   the   filename,   and   the   file   is   not   created.   If   zero,   the   last   four   characters   are   generated   by   Windows,   and   the   file   is   created.    
  lpTempFileName  
  A   string   that   receives   the   path   and   filename   of   the   temporary   file.    
  Example:    
   
  '   Generate   a   temporary   file   (path)\api????.TMP,   where   (path)  
  '   is   Windows's   temporary   file   directory   and   ????   is   a   randomly   assigned   unique   value.  
  '   Then   display   the   name   of   the   created   file   on   the   screen.  
  Dim   temppath   As   String     '   receives   name   of   temporary   file   path  
  Dim   tempfile   As   String     '   receives   name   of   temporary   file  
  Dim   slength   As   Long     '   receives   length   of   string   returned   for   the   path  
  Dim   lastfour   As   Long     '   receives   hex   value   of   the   randomly   assigned   ????  
   
  '   Get   Windows's   temporary   file   path  
  temppath   =   Space(255)     '   initialize   the   buffer   to   receive   the   path  
  slength   =   GetTempPath(255,   temppath)     '   read   the   path   name  
  temppath   =   Left(temppath,   slength)     '   extract   data   from   the   variable  
   
  '   Get   a   uniquely   assigned   random   file  
  tempfile   =   Space(255)     '   initialize   buffer   to   receive   the   filename  
  lastfour   =   GetTempFileName(temppath,   "api",   0,   tempfile)     '   get   a   unique   temporary   file   name  
  '   (Note   that   the   file   is   also   created   for   you   in   this   case.)  
  tempfile   =   Left(tempfile,   InStr(tempfile,   vbNullChar)   -   1)     '   extract   data   from   the   variable  
  Debug.Print   "Temporary   filename:   ";   tempfile  
  Top

2 楼haor(一个好人)回复于 2001-01-25 13:55:00 得分 0

错误提示是否为:“常数、固定长度字符串、数组、自定义类型与   Declare   语句不能是对象模块中的   Public   成员”?  
  请在Module中声明。Top

3 楼haor(一个好人)回复于 2001-01-25 13:55:00 得分 10

使用方法:  
   
  GetTempFileName  
  The   GetTempFileName   function   creates   a   name   for   a   temporary   file.   The   filename   is   the   concatenation   of   specified   path   and   prefix   strings,   a   hexadecimal   string   formed   from   a   specified   integer,   and   the   .TMP   extension.  
   
  The   specified   integer   can   be   nonzero,   in   which   case,   the   function   creates   the   filename   but   does   not   create   the   file.   If   you   specify   zero   for   the   integer,   the   function   creates   a   unique   filename   and   creates   the   file   in   the   specified   directory.  
   
  UINT   GetTempFileName(  
      LPCTSTR   lpPathName,     //   pointer   to   directory   name   for   temporary    
                                                //   file  
      LPCTSTR   lpPrefixString,     //   pointer   to   filename   prefix  
      UINT   uUnique,                 //   number   used   to   create   temporary   filename  
      LPTSTR   lpTempFileName    
                                                //   pointer   to   buffer   that   receives   the   new    
                                                //   filename  
  );  
     
  Parameters  
  lpPathName    
  Pointer   to   a   null-terminated   string   that   specifies   the   directory   path   for   the   filename.   This   string   must   consist   of   characters   in   the   ANSI   character   set.   Applications   typically   specify   a   period   (.)   or   the   result   of   the   GetTempPath   function   for   this   parameter.   If   this   parameter   is   NULL,   the   function   fails.    
  lpPrefixString    
  Pointer   to   a   null-terminated   prefix   string.   The   function   uses   the   first   three   characters   of   this   string   as   the   prefix   of   the   filename.   This   string   must   consist   of   characters   in   the   ANSI   character   set.    
  uUnique    
  Specifies   an   unsigned   integer   that   the   function   converts   to   a   hexadecimal   string   for   use   in   creating   the   temporary   filename.    
  If   uUnique   is   nonzero,   the   function   appends   the   hexadecimal   string   to   lpPrefixString   to   form   the   temporary   filename.   In   this   case,   the   function   does   not   create   the   specified   file,   and   does   not   test   whether   the   filename   is   unique.    
   
  If   uUnique   is   zero,   the   function   uses   a   hexadecimal   string   derived   from   the   current   system   time.   In   this   case,   the   function   uses   different   values   until   it   finds   a   unique   filename,   and   then   it   creates   the   file   in   the   lpPathName   directory.    
   
  lpTempFileName    
  Pointer   to   the   buffer   that   receives   the   temporary   filename.   This   null-terminated   string   consists   of   characters   in   the   ANSI   character   set.   This   buffer   should   be   at   least   the   length,   in   bytes,   specified   by   MAX_PATH   to   accommodate   the   path.    
  Return   Values  
  If   the   function   succeeds,   the   return   value   specifies   the   unique   numeric   value   used   in   the   temporary   filename.   If   the   uUnique   parameter   is   nonzero,   the   return   value   specifies   that   same   number.    
   
  If   the   function   fails,   the   return   value   is   zero.   To   get   extended   error   information,   call   GetLastError.    
   
  Remarks  
  The   GetTempFileName   function   creates   a   temporary   filename   of   the   following   form:  
   
  path\preuuuu.TMP  
   
  The   following   table   describes   the   filename   syntax:    
   
  Component   Meaning    
  path   Path   specified   by   the   lpPathName   parameter    
  pre   First   three   letters   of   the   lpPrefixString   string    
  uuuu   Hexadecimal   value   of   uUnique    
   
   
  When   the   system   shuts   down,   temporary   files   whose   names   have   been   created   by   this   function   are   not   automatically   deleted.    
   
  To   avoid   problems   resulting   when   converting   an   ANSI   string,   an   application   should   call   the   CreateFile   function   to   create   a   temporary   file.    
   
  If   the   uUnique   parameter   is   zero,   GetTempFileName   attempts   to   form   a   unique   number   based   on   the   current   system   time.   If   a   file   with   the   resulting   filename   exists,   the   number   is   increased   by   one   and   the   test   for   existence   is   repeated.   Testing   continues   until   a   unique   filename   is   found.   GetTempFileName   then   creates   a   file   by   that   name   and   closes   it.   When   uUnique   is   nonzero,   no   attempt   is   made   to   create   and   open   the   file.    
  Top

4 楼blademan(不累得慢)回复于 2001-01-25 18:32:00 得分 0

你应该把Public声明写在模块中。  
  选择“工程”->“添加模块”即可。Top

5 楼lujianjian(老农)回复于 2001-01-25 20:09:00 得分 0

haor(一个好人) 写得挺清楚的吧,你是不是把它写在Form里了?Top

相关问题

  • 创建存储过程 137 错误: 必须声名变量'@fromtype'
  • 发生不明错误。错误码=080004005
  • iis发生意外错误
  • 网页发生错误
  • 为什么会出现"分页发生错误"的错误?
  • 当错误发生时如何撤销?
  • 打开Excel文件发生错误。
  • vfp--'写文件发生错误',救我!
  • 我的socket为啥会发生错误?
  • 声明函数时,发生的错误

关键词

  • gettempfilename
  • lptempfilename
  • lpprefixstring
  • temporary
  • byval
  • filename
  • specifies
  • pointer
  • path
  • create

得分解答快速导航

  • 帖主:moleboy
  • zyx29
  • haor

相关链接

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

广告也精彩

反馈

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