注册 登录
Office中国论坛/Access中国论坛 返回首页

zhuyiwen的个人空间 http://www.office-cn.net/?625 [收藏] [复制] [分享] [RSS]

日志

在模块中使用Property Get语句

已有 864 次阅读2012-10-7 09:40 |个人分类:VBA| 模块, 属性过程

通常,一般只在类模块使用属性过程,我从来没想过在模块中使用属性过程。这两天学习 VB_SGrid2 例程,发现在模块中一样可以使用属性过程。

如:在模块 mGrid 中
[code]
' System detection
Private Declare Function GetVersion Lib "kernel32" () As Long

' Private variables
Private m_bIsXp As Boolean
Private m_bIsNt As Boolean
Private m_bInit As Boolean

''' <summary>
''' 返回当前系统是否为 Windows XP 以上版本.
''' </summary>
''' <returns><c>True</c> if the system is running XP or above.</returns>
Public Property Get isXp() As Boolean
   If Not (m_bInit) Then
      VerInitialise
   End If
   isXp = m_bIsXp
End Property

Public Property Get IsNt() As Boolean
   If Not (m_bInit) Then
      VerInitialise
   End If
   IsNt = m_bIsNt
End Property

''' <summary>
''' 获取 Windows 版本并设置 m_bIsXp
''' </summary>
Private Sub VerInitialise()
   Dim lMajor As Long
   Dim lMinor As Long
   GetWindowsVersion lMajor, lMinor
   If (lMajor > 5) Then
      m_bIsXp = True
   ElseIf (lMajor = 5) And (lMinor >= 1) Then
      m_bIsXp = True
   End If
   m_bInit = True
End Sub

''' <summary>
''' 返回当前运行的 Windows 版本
''' </summary>
''' <param name="lMajor">
''' Windows 主版本号
''' </param>
''' <param name="lMinor">
''' Windows 次版本号
''' </param>
''' <param name="lRevision">
''' Windows 修订号
''' </param>
''' <param name="lBuildNumber">
''' Windows 版本号
''' </param>
Private Sub GetWindowsVersion( _
      Optional ByRef lMajor = 0, _
      Optional ByRef lMinor = 0, _
      Optional ByRef lRevision = 0, _
      Optional ByRef lBuildNumber = 0 _
   )
Dim lR As Long
   lR = GetVersion()
   lBuildNumber = (lR And &H7F000000) \ &H1000000
   If (lR And &H80000000) Then lBuildNumber = lBuildNumber Or &H80
   lRevision = (lR And &HFF0000) \ &H10000
   lMinor = (lR And &HFF00&) \ &H100
   lMajor = (lR And &HFF)
   m_bIsNt = ((lR And &H80000000) = 0)
End Sub
[/code]

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-17 12:11 , Processed in 0.093513 second(s), 17 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部