
 |
Ejemplos para Programadoras de Visual Basic::
Getting a termporary file name from Windows:
'Instructions:
' 1) Create a new project with one form and one module.
' 2) Add a text box and command button to the form.
' 3) Set the following properties (optional)
' Text1.MaxLength = 3
' 4) Paste to code into the form and module as indicated.
' 5) Run the project. Press the command key. A message box will
' display a unique temp file name.
' Note: Anything entered in the text box up to the
' first three characters will serve as the prefix
' to the temp file name.
' ------------- Paste this code into Module1 -------------
' This sample code is presented as is.
' Although every reasonable effort has been
' made to insure the correctness of the example
' below, Idianna Software Inc. makes no warranty
' of any kind with regard to this program sample
' either implicitly or explicitly.
' This program example may be freely distributed for the
' use of writing computer programs only. Any other use of
' this material requires written permission from Idianna Software inc.
' (c) 2000 Idianna Software inc. All rights reserved.
' Title: String Search/Replace
' Platform: Visual Basic - 32 bit
' Author: Jon Vote
' Contact: jon@idioma-software.com
' Date: 02/00
Option Explicit
Declare Function GetTempPath Lib "Kernel32" _
Alias "GetTempPathA" _
(ByVal nBufferLength As Long _
, ByVal lpBuffer As String) As Long
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 GetTempName(sPrefix As String) As String
Dim TempFileName As String
Dim sPath As String
Dim rc As Long
If sPrefix = "" Then
sPrefix = "~"
End If
TempFileName = Space$(255)
sPath = Space$(255)
rc = GetTempPath(255, sPath)
rc = GetTempFileName(sPath, sPrefix, 0, TempFileName)
GetTempName = TempFileName
End Function
' ------------- End code for Module1 -------------
' ------------- Paste this code into Form1 -------------
Option Explicit
Private Sub Command1_Click()
MsgBox "Temp file name is: " & GetTempName(Text1.Text)
End Sub
' ------------- End code for Form1 -------------
|