VB 函数收集

'自定义函数从字符串中分离出路径

Function ParsePath (sPathIn As String) As String
  Dim I As Integer
  For I = Len(sPathIn) To 1 Step -1
   If InStr(":", Mid$(sPathIn, I, 1)) Then Exit For
  Next
  ParsePath = Left$(sPathIn, I)
End Function



'自定义函数从字符串中分离出文件名

Function ParseFileName (sFileIn As String) As String
  Dim I As Integer
  For I = Len(sFileIn) To 1 Step -1
   If InStr("", Mid$(sFileIn, I, 1)) Then Exit For
  Next
  ParseFileName = Mid$(sFileIn, I + 1, Len(sFileIn) - I)
End Function



'自定义函数从字符串中分离出文件扩展名

Function GetFileExt (sFileName As String) As String
  Dim P As Integer
  For P = Len(sFileName) To 1 Step -1
   If InStr(".", Mid$(sFileName, P, 1)) Then Exit For
  Next
  GetFileExt = Right$(sFileName, Len(sFileName) - P)
End Function


'**************************************
'INI 读写模块
'FieldMAX 2006-11-16
'
'值 = GetINI(标题, 变量, [默认], [文件名])
'WriteINI(标题, 变量, 值, [文件名])
'**************************************

'INI 文件 API 函数
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
                (ByVal LpApplicationName As String, ByVal LpKeyName As Any, ByVal lpDefault As String, _
                ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public 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
'---------------------------------------------------------------------------------
'API函数变量说明
    'LpApplicationName: 被读写段的段名?
    'LpKeyName: 被读写的条目的关键字名?
    'LpString:写入INI文件的值(当进行写操作时)。
    'lpDefault::段中的默认返回值以及(或者)读操作时关键字未找到时的默认返回值。
    'lpReturnedString:从INI文件读到的数据(当进行读操作时)。
    'nSize: 返回的最大字符数?设置为 lpReturnedString的长度?
    'lpFileName:INI文件的文件名,包括完整的路径名。
'--------------------------------------------------------------------------------
Public Function GetINI(ByVal ApplicationName As String, ByVal KeyName As String, Optional ByVal Default As String = "", Optional ByVal FileName As String = "config.ini") As String
    Dim Retval As Long
    Dim Value As String
    FileName = IIf(Mid(FileName, 2, 2) = ":\", FileName, AppPath & FileName)
    Value = Space(128)
    Retval = GetPrivateProfileString(ApplicationName, KeyName, Default, Value, Len(Value), FileName)
    GetINI = Left(Trim(Value), Len(Trim(Value)) - 1)
End Function

Public Sub WriteINI(ByVal ApplicationName As String, ByVal KeyName As String, ByVal Value As String, Optional ByVal FileName As String = "config.ini")
    Dim Retval As Long
    FileName = IIf(Mid(FileName, 2, 2) = ":\", FileName, AppPath & FileName)
    Retval = WritePrivateProfileString(ApplicationName, KeyName, Value, FileName)
End Sub

[本日志由 Admin 于 2009-05-24 10:43 PM 编辑]
上一篇: 117 个 Flash 光影火等素材[7Z][SWF]
下一篇: VBA 生成一个CorelDRAW工具栏 的代码
文章来自: 网络
引用通告: 查看所有引用 | 我要引用此文章
Tags: VB VisaulBasic vbscript
相关日志:
评论: 0 | 引用: 0 | 查看次数: 6675
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 500 字 | UBB代码 关闭 | [img]标签 关闭