?? common.bas
字號:
' Add a trailing URL path separator (forward slash) to the
' end of a URL unless one (or a back slash) already exists
'
' IN/OUT: [strPathName] - path to add separator to
'-----------------------------------------------------------
'
Sub AddURLDirSep(strPathName As String)
If Right(Trim(strPathName), Len(gstrSEP_URLDIR)) <> gstrSEP_URLDIR And _
Right(Trim(strPathName), Len(gstrSEP_DIR)) <> gstrSEP_DIR Then
strPathName = Trim(strPathName) & gstrSEP_URLDIR
End If
End Sub
'-----------------------------------------------------------
' FUNCTION: FileExists
' Determines whether the specified file exists
'
' IN: [strPathName] - file to check for
'
' Returns: True if file exists, False otherwise
'-----------------------------------------------------------
'
Function FileExists(ByVal strPathName As String) As Integer
Dim intFileNum As Integer
On Error Resume Next
'
' If the string is quoted, remove the quotes.
'
strPathName = strUnQuoteString(strPathName)
'
'Remove any trailing directory separator character
'
If Right$(strPathName, 1) = gstrSEP_DIR Then
strPathName = Left$(strPathName, Len(strPathName) - 1)
End If
'
'Attempt to open the file, return value of this function is False
'if an error occurs on open, True otherwise
'
intFileNum = FreeFile
Open strPathName For Input As intFileNum
FileExists = IIf(Err = 0, True, False)
Close intFileNum
Err = 0
End Function
'-----------------------------------------------------------
' FUNCTION: DirExists
'
' Determines whether the specified directory name exists.
' This function is used (for example) to determine whether
' an installation floppy is in the drive by passing in
' something like 'A:\'.
'
' IN: [strDirName] - name of directory to check for
'
' Returns: True if the directory exists, False otherwise
'-----------------------------------------------------------
'
Public Function DirExists(ByVal strDirName As String) As Integer
Const strWILDCARD$ = "*.*"
Dim strDummy As String
On Error Resume Next
AddDirSep strDirName
strDummy = Dir$(strDirName & strWILDCARD, vbDirectory)
DirExists = Not (strDummy = vbNullString)
Err = 0
End Function
'-----------------------------------------------------------
' FUNCTION: GetDriveType
' Determine whether a disk is fixed, removable, etc. by
' calling Windows GetDriveType()
'-----------------------------------------------------------
'
Function GetDriveType(ByVal intDriveNum As Integer) As Integer
'
' This function expects an integer drive number in Win16 or a string in Win32
'
Dim strDriveName As String
strDriveName = Chr$(Asc("A") + intDriveNum) & gstrSEP_DRIVE & gstrSEP_DIR
GetDriveType = CInt(GetDriveType32(strDriveName))
End Function
'-----------------------------------------------------------
' FUNCTION: ReadProtocols
' Reads the allowable protocols from the specified file.
'
' IN: [strInputFilename] - INI filename from which to read the protocols
' [strINISection] - Name of the INI section
'-----------------------------------------------------------
Function ReadProtocols(ByVal strInputFilename As String, ByVal strINISection As String) As Boolean
Dim intIdx As Integer
Dim fOk As Boolean
Dim strInfo As String
Dim intOffset As Integer
intIdx = 0
fOk = True
Erase gProtocol
gcProtocols = 0
Do
strInfo = ReadIniFile(strInputFilename, strINISection, gstrINI_PROTOCOL & Format$(intIdx + 1))
If strInfo <> vbNullString Then
intOffset = InStr(strInfo, gstrCOMMA)
If intOffset > 0 Then
'The "ugly" name will be first on the line
ReDim Preserve gProtocol(intIdx + 1)
gcProtocols = intIdx + 1
gProtocol(intIdx + 1).strName = Left$(strInfo, intOffset - 1)
'... followed by the friendly name
gProtocol(intIdx + 1).strFriendlyName = Mid$(strInfo, intOffset + 1)
If (gProtocol(intIdx + 1).strName = "") Or (gProtocol(intIdx + 1).strFriendlyName = "") Then
fOk = False
End If
Else
fOk = False
End If
If Not fOk Then
Exit Do
Else
intIdx = intIdx + 1
End If
End If
Loop While strInfo <> vbNullString
ReadProtocols = fOk
End Function
'-----------------------------------------------------------
' FUNCTION: ResolveResString
' Reads resource and replaces given macros with given values
'
' Example, given a resource number 14:
' "Could not read '|1' in drive |2"
' The call
' ResolveResString(14, "|1", "TXTFILE.TXT", "|2", "A:")
' would return the string
' "Could not read 'TXTFILE.TXT' in drive A:"
'
' IN: [resID] - resource identifier
' [varReplacements] - pairs of macro/replacement value
'-----------------------------------------------------------
'
Public Function ResolveResString(ByVal resID As Integer, ParamArray varReplacements() As Variant) As String
Dim intMacro As Integer
Dim strResString As String
strResString = LoadResString(resID)
' For each macro/value pair passed in...
For intMacro = LBound(varReplacements) To UBound(varReplacements) Step 2
Dim strMacro As String
Dim strValue As String
strMacro = varReplacements(intMacro)
On Error GoTo MismatchedPairs
strValue = varReplacements(intMacro + 1)
On Error GoTo 0
' Replace all occurrences of strMacro with strValue
Dim intPos As Integer
Do
intPos = InStr(strResString, strMacro)
If intPos > 0 Then
strResString = Left$(strResString, intPos - 1) & strValue & Right$(strResString, Len(strResString) - Len(strMacro) - intPos + 1)
End If
Loop Until intPos = 0
Next intMacro
ResolveResString = strResString
Exit Function
MismatchedPairs:
Resume Next
End Function
'-----------------------------------------------------------
' SUB: GetLicInfoFromVBL
' Parses a VBL file name and extracts the license key for
' the registry and license information.
'
' IN: [strVBLFile] - must be a valid VBL.
'
' OUT: [strLicKey] - registry key to write license info to.
' This key will be added to
' HKEY_CLASSES_ROOT\Licenses. It is a
' guid.
' OUT: [strLicVal] - license information. Usually in the
' form of a string of cryptic characters.
'-----------------------------------------------------------
'
Public Sub GetLicInfoFromVBL(strVBLFile As String, strLicKey As String, strLicVal As String)
Dim fn As Integer
Const strREGEDIT = "REGEDIT"
Const strLICKEYBASE = "HKEY_CLASSES_ROOT\Licenses\"
Dim strTemp As String
Dim posEqual As Integer
Dim fLicFound As Boolean
fn = FreeFile
Open strVBLFile For Input Access Read Lock Read Write As #fn
'
' Read through the file until we find a line that starts with strLICKEYBASE
'
fLicFound = False
Do While Not EOF(fn)
Line Input #fn, strTemp
strTemp = Trim(strTemp)
If Left$(strTemp, Len(strLICKEYBASE)) = strLICKEYBASE Then
'
' We've got the line we want.
'
fLicFound = True
Exit Do
End If
Loop
Close fn
If fLicFound Then
'
' Parse the data on this line to split out the
' key and the license info. The line should be
' the form of:
' "HKEY_CLASSES_ROOT\Licenses\<lickey> = <licval>"
'
posEqual = InStr(strTemp, gstrASSIGN)
If posEqual > 0 Then
strLicKey = Mid$(Trim(Left$(strTemp, posEqual - 1)), Len(strLICKEYBASE) + 1)
strLicVal = Trim(Mid$(strTemp, posEqual + 1))
End If
Else
strLicKey = vbNullString
strLicVal = vbNullString
End If
End Sub
'-----------------------------------------------------------
' FUNCTION GetLongPathName
'
' Retrieve the long pathname version of a path possibly
' containing short subdirectory and/or file names
'-----------------------------------------------------------
'
Function GetLongPathName(ByVal strShortPath As String) As String
On Error GoTo 0
MakeLongPath (strShortPath)
GetLongPathName = StripTerminator(strShortPath)
End Function
'-----------------------------------------------------------
' FUNCTION GetShortPathName
'
' Retrieve the short pathname version of a path possibly
' containing long subdirectory and/or file names
'-----------------------------------------------------------
'
Function GetShortPathName(ByVal strLongPath As String) As String
Const cchBuffer = 300
Dim strShortPath As String
Dim lResult As Long
On Error GoTo 0
strShortPath = String(cchBuffer, Chr$(0))
lResult = OSGetShortPathName(strLongPath, strShortPath, cchBuffer)
If lResult = 0 Then
'Error 53 ' File not found
'Vegas#51193, just use the long name as this is usually good enough
GetShortPathName = strLongPath
Else
GetShortPathName = StripTerminator(strShortPath)
End If
End Function
'-----------------------------------------------------------
' FUNCTION: GetTempFilename
' Get a temporary filename for a specified drive and
' filename prefix
' PARAMETERS:
' strDestPath - Location where temporary file will be created. If this
' is an empty string, then the location specified by the
' tmp or temp environment variable is used.
' lpPrefixString - First three characters of this string will be part of
' temporary file name returned.
' wUnique - Set to 0 to create unique filename. Can also set to integer,
' in which case temp file name is returned with that integer
' as part of the name.
' lpTempFilename - Temporary file name is returned as this variable.
' RETURN:
' True if function succeeds; false otherwise
'-----------------------------------------------------------
'
Function GetTempFilename(ByVal strDestPath As String, ByVal lpPrefixString As String, ByVal wUnique As Integer, lpTempFilename As String) As Boolean
If strDestPath = vbNullString Then
'
' No destination was specified, use the temp directory.
'
strDestPath = String(gintMAX_PATH_LEN, vbNullChar)
If GetTempPath(gintMAX_PATH_LEN, strDestPath) = 0 Then
GetTempFilename = False
Exit Function
End If
End If
lpTempFilename = String(gintMAX_PATH_LEN, vbNullChar)
GetTempFilename = GetTempFilename32(strDestPath, lpPrefixString, wUnique, lpTempFilename) > 0
lpTempFilename = StripTerminator(lpTempFilename)
End Function
'-----------------------------------------------------------
' FUNCTION: GetDefMsgBoxButton
' Decode the flags passed to the MsgBox function to
' determine what the default button is. Use this
' for silent installs.
'
' IN: [intFlags] - Flags passed to MsgBox
'
' Returns: VB defined number for button
' vbOK 1 OK button pressed.
' vbCancel 2 Cancel button pressed.
' vbAbort 3 Abort button pressed.
' vbRetry 4 Retry button pressed.
' vbIgnore 5 Ignore button pressed.
' vbYes 6 Yes button pressed.
' vbNo 7 No button pressed.
'-----------------------------------------------------------
'
Function GetDefMsgBoxButton(intFlags) As Integer
'
' First determine the ordinal of the default
' button on the message box.
'
Dim intButtonNum As Integer
Dim intDefButton As Integer
If (intFlags And vbDefaultButton2) = vbDefaultButton2 Then
intButtonNum = 2
ElseIf (intFlags And vbDefaultButton3) = vbDefaultButton3 Then
intButtonNum = 3
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -