我已经看了那个贴子,但我如何获得临时文件名呢? 比如image.picture=loadpicture("临时文件名") 我是个初学者,还烦请楼上的告之, 以这个函数为例吧. '将任何文件从数据库中下载到本地: Public Function LoadFile(ByVal col As ADODB.Field, ByVal FileName As String) As Boolean '获得binary数据 On Error GoTo myerr: Dim arrBytes() As Byte Dim FreeFileNumber As Integer lngsize = col.ActualSize arrBytes = col.GetChunk(lngsize) FreeFileNumber = FreeFile Open FileName For Binary Access Write As #FreeFileNumber Put #FreeFileNumber, , arrBytes Close #FreeFileNumber LoadFile = True myerr: If Err.Number <> 0 Then LoadFile = False Err.Clear End If End Function
'Call TempFile(False) to get a unique temporary filename or 'Call TempFile(True) to create a temporary file (0 bytes)'**************** Code Start ********************** 'This code was originally written by Terry Kreft. 'It is not to be altered or distributed, 'except as part of an application. 'You are free to use it in any application, 'provided the copyright notice is left unchanged. ' 'Code Courtesy of 'Terry KreftPrivate Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _ (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long Private 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 Function TempDir() As String Dim lngRet As Long Dim strTempDir As String Dim lngBuf As Long strTempDir = String$(255, 0) lngBuf = Len(strTempDir) lngRet = GetTempPath(lngBuf, strTempDir) If lngRet > lngBuf Then strTempDir = String$(lngRet, 0) lngBuf = Len(strTempDir) lngRet = GetTempPath(lngBuf, strTempDir) End If TempDir = Left(strTempDir, lngRet) End Function 'Creates and/or returns the name of a unique temp file 'Create determines whether to just return a filename or to crete the file. 'lpPrefixString defines the first three letters of the temp filename 'if left blank will use "tmp" 'lpszPath defines the directory path to the temporary file, if left blank will 'use the system temp directory setting Function TempFile(Create As Boolean, Optional lpPrefixString As Variant, _ Optional lpszPath As Variant) As String Dim lpTempFileName As String * 255 Dim strTemp As String Dim lngRet As Long If IsMissing(lpszPath) Then lpszPath = TempDir End If If IsMissing(lpPrefixString) Then lpPrefixString = "tmp" End If lngRet = GetTempFileName(lpszPath, lpPrefixString, 0, lpTempFileName) strTemp = lpTempFileName lngRet = InStr(lpTempFileName, Chr$(0)) strTemp = Left(lpTempFileName, lngRet - 1) If Create = False Then Kill strTemp Do Until Dir(strTemp) = "": DoEvents: Loop End If TempFile = strTemp End Function'**************** Code End **********************
比如image.picture=loadpicture("临时文件名")
我是个初学者,还烦请楼上的告之,
以这个函数为例吧.
'将任何文件从数据库中下载到本地:
Public Function LoadFile(ByVal col As ADODB.Field, ByVal FileName As String) As Boolean '获得binary数据
On Error GoTo myerr:
Dim arrBytes() As Byte
Dim FreeFileNumber As Integer
lngsize = col.ActualSize
arrBytes = col.GetChunk(lngsize)
FreeFileNumber = FreeFile
Open FileName For Binary Access Write As #FreeFileNumber
Put #FreeFileNumber, , arrBytes
Close #FreeFileNumber
LoadFile = True
myerr:
If Err.Number <> 0 Then
LoadFile = False
Err.Clear
End If
End Function
'Call TempFile(True) to create a temporary file (0 bytes)'**************** Code Start **********************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Terry KreftPrivate Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private 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
Function TempDir() As String
Dim lngRet As Long
Dim strTempDir As String
Dim lngBuf As Long
strTempDir = String$(255, 0)
lngBuf = Len(strTempDir)
lngRet = GetTempPath(lngBuf, strTempDir)
If lngRet > lngBuf Then
strTempDir = String$(lngRet, 0)
lngBuf = Len(strTempDir)
lngRet = GetTempPath(lngBuf, strTempDir)
End If
TempDir = Left(strTempDir, lngRet)
End Function
'Creates and/or returns the name of a unique temp file
'Create determines whether to just return a filename or to crete the file.
'lpPrefixString defines the first three letters of the temp filename
'if left blank will use "tmp"
'lpszPath defines the directory path to the temporary file, if left blank will
'use the system temp directory setting
Function TempFile(Create As Boolean, Optional lpPrefixString As Variant, _
Optional lpszPath As Variant) As String
Dim lpTempFileName As String * 255
Dim strTemp As String
Dim lngRet As Long
If IsMissing(lpszPath) Then
lpszPath = TempDir
End If
If IsMissing(lpPrefixString) Then
lpPrefixString = "tmp"
End If
lngRet = GetTempFileName(lpszPath, lpPrefixString, 0, lpTempFileName)
strTemp = lpTempFileName
lngRet = InStr(lpTempFileName, Chr$(0))
strTemp = Left(lpTempFileName, lngRet - 1)
If Create = False Then
Kill strTemp
Do Until Dir(strTemp) = "": DoEvents: Loop
End If
TempFile = strTemp
End Function'**************** Code End **********************