读书人

奇怪的后缀名有关问题这到底是肿么了

发布时间: 2013-06-25 23:45:42 作者: rapoo

奇怪的后缀名问题,请教大家这到底是肿么了




'读写ini调用的API
Private Declare Function GetPrivateProfileString Lib _
"kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
lpKeyName As Any, ByVal lpDefault As String, ByVal lpretunedstring As String, ByVal nSize As Long, _
ByVal lpFileName As String) As Long

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias _
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

'读INI文件函数
Public Function GetFromINI(Appname As String, Keyname As String, _
FileName As String) As String
Dim RetStr As String
RetStr = String(255, Chr(0))
GetFromINI = Left(RetStr, GetPrivateProfileString(Appname, ByVal Keyname, "", RetStr, Len(RetStr), FileName))
End Function
'**************************************************************

'写INI文件函
Public Function WriteINI(inipath As String, Appname As String, Keyname As String, value As String)
Dim stemp As String
stemp = value
Call WritePrivateProfileString(Appname, Keyname, stemp, inipath)
End Function

'从全路径中返回文件的扩展名
Public Function strFileShortNameSuf(strFilePath As String) As String
Dim temp
If InStr(strFilePath, ".") = 0 Then Exit Function
temp = Split(strFilePath, ".")
strFileShortNameSuf = temp(UBound(temp))
End Function

Private Sub Command1_Click()
Dim processPath As String, ssName As String
processPath = "D:\吃饭.exe"

ssName = strFileShortNameSuf(processPath)
MsgBox ssName '此时弹出窗口显示文件扩展名为exe

If ssName = "exe" Then '结果显示Error
MsgBox "OK"
Else
MsgBox "Error"
End If

a = WriteINI(App.Path & "\config.ini", "设置", "扩展名", ssName) '注意我把变量ssName值写入ini文件
a = GetFromINI("设置", "扩展名", App.Path & "\config.ini") '从ini文件读取刚才写入的值

If a = "exe" Then '结果显示OK
MsgBox "OK"
Else
MsgBox "Error"
End If

Select Case ssName '这是我最终目的,根据后缀名的不同运行的运行方式
Case "exe"
Shell processPath
Case "vbs"
Shell "explorer " & processPath


Case "bat"
Shell "CMD.exe /c " & processPath
End Select
End Sub



[解决办法]
If ucase(ssName) = "EXE" Then '结果显示Error
MsgBox "OK"
Else
MsgBox "Error"
End If


exe<>EXE<>Exe.....
[解决办法]
如果那么渴望是小写,改一下函数:

Public Function strFileShortNameSuf(strFilePath As String) As String
Dim temp
If InStr(strFilePath, ".") = 0 Then Exit Function
temp = Split(strFilePath, ".")
strFileShortNameSuf = lcase(temp(UBound(temp)) )
End Function

读书人网 >VB

热点推荐