Получить имя константы или переменной - VB

Узнай цену своей работы

Формулировка задачи:

В одном из моих разрабатавемемых компонентов есть следующий набор:
можно ли получить имя константы из этого набора для того, чтоб отобразить в заголовке окна и т.п ? ✰ ✰ ✰ в идеале было бы олично чтоб имя той или иной константы можно было получить используя класс Dictionary например txt$ = dicCSIDL_RU.Item(&H30) результат: txt = "папка "Администрирование" (NT)"

Решение задачи: «Получить имя константы или переменной»

textual
Листинг программы
Option Explicit
'Default Property Values:
 
'//////////////////////////////////////////...ENUMS
Public Enum StyleBrowseFlags_ru
    [по умолчанию] = &H40
    [убрать кнопку "создать папку"] = &H200
    [отображать файлы] = &H4000
    [дополнительное текстовое поле] = &H10
End Enum
 
Public Enum TopFolderFlags_ru
    [папка "Администрирование" (NT)] = &H30
    [данные приложений] = &H1A
    [общая папка "Администрирование" (NT)] = &H2F
    [общие данные приложений] = &H23
    [общий рабочий стол] = &H19
    [общие документы] = &H2E
    [общее "Избранное"] = &H1F
    [общие программы] = &H17
    [общее меню "Пуск"] = &H16
    [общая автозагрузка] = &H18
    [общие шаблоны] = &H2D
    [соединения с сетью] = &H31
    [файлы cookie] = &H21
    [рабочий стол] = &H0
    [полный путь к рабочему столу] = &H10
    [избранное] = &H6
    [шрифты] = &H14
    [журнал] = &H22
    [кэш страниц IE] = &H20
    [локальные настройки программ] = &H1C
    [мои рисунки] = &H27
    [личная папка] = &H5
    [мои документы] = &H28
    [папка Program Files] = &H26
    [общая папка Program Files] = &H2B
    [программы] = &H2
    [недавние документы] = &H8
    [меню "Отправить"] = &H9
    [меню "Пуск"] = &HB
    [автозагрузка] = &H7
    [системная папка] = &H25
    [шаблоны] = &H15
    [папка Windows] = &H24
End Enum
 
Public Enum StyleFlags_ru
    [минимальный набор] = 0
    [дополнительный флажок] = 1
    [полный набор] = 2
End Enum
'//////////////////////////////////////////...END ENUMS
Const m_def_BackColor = &H8000000F
Const m_def_StyleBrowse = StyleBrowseFlags_ru.[по умолчанию]
Const m_def_Style = StyleFlags_ru.[минимальный набор]
Const m_def_TopFolder = TopFolderFlags_ru.[рабочий стол]
Const m_def_EnabledButton2 = 1
Const m_def_EnabledCheck = 1
'Property Variables:
Dim m_EnabledButton2 As Boolean
Dim m_EnabledCheck As Boolean
Dim m_TopFolder As TopFolderFlags_ru
Dim m_StyleBrowse As StyleBrowseFlags_ru
Dim m_Style As StyleFlags_ru
Dim m_BackColor As OLE_COLOR
Dim m_Dic As Object 'Dim m_Dic As Dictionary
'Event Declarations:
Event ClickButton2(Combo As Object) 'MappingInfo=Command2,Command2,-1,Click
Event ClickCheck(Value As Integer) 'MappingInfo=Check1,Check1,-1,Click
Event SelectPath(Path$, Combo As Object) 'MappingInfo=Combo1,Combo1,-1,Click
 
Private Sub Command1_Click()
    Dim Path$
    Path = BrowseForFolder(hwnd, Frame1.Caption, Combo1.Text, m_TopFolder, m_StyleBrowse)
 
    If Len(Path) Then
 
        If Not m_Dic.Exists(Path) Then
            Combo1.AddItem Path
        End If
        Combo1.Text = Path
        Combo1.SelLength = Len(Path)
        RaiseEvent SelectPath(Path, Combo1)
        DicComboRefresh
    End If
End Sub
 
Private Sub UserControl_Initialize()
    Set m_Dic = CreateObject("Scripting.Dictionary")
    m_Dic.CompareMode = 1
    Picture1.BorderStyle = 0
End Sub
 
Private Sub UserControl_Show()
    Dim o As Object
    On Error Resume Next
 
    For Each o In UserControl:
        If TypeName(o) <> "ComboBox" Then o.BackColor() = m_BackColor
 
        If UserControl.Enabled Then 'Выключение компонентов
 
            Select Case o.Name
            Case "Check1": o.Enabled = m_EnabledCheck
            Case "Command2": o.Enabled = m_EnabledButton2
            Case Else: o.Enabled = True
            End Select
        Else
            o.Enabled = False
        End If
    Next
End Sub
 
Private Sub UserControl_Terminate()
    Set m_Dic = Nothing
End Sub
 
Private Sub UserControl_Resize()
    Dim tx&, ty&, ogrY&
    Const c1 = 3
    On Error Resume Next
    tx = Screen.TwipsPerPixelX: ty = Screen.TwipsPerPixelY
    Height = IIf(m_Style = 0, Combo1.Height + ty * ty + ty * c1, Combo1.Height + ty * ty * c1)
    Frame1.Move 0, 0, ScaleWidth, ScaleHeight
    Picture1.Move tx, ty * ty, ScaleWidth - tx * 2, ScaleHeight - ty * ty - ty
    Label1.Caption = Command1.Caption
    Command1.Width = Label1.Width + tx * tx
    Combo1.Move tx * c1, 0, Picture1.Width - Command1.Width - tx * c1 * c1
    Command1.Move Combo1.Width + tx * c1 * 2, 0, Command1.Width, Combo1.Height
    '--------------------------
    Select Case m_Style
    Case [минимальный набор]
        Check1.Visible = False
        Command2.Visible = False
    Case [дополнительный флажок]
        Check1.Move tx * c1, Combo1.Height + ty * c1, Combo1.Width
        Check1.Visible = True
        Command2.Visible = False
    Case [полный набор]
        Label1.Caption = Command2.Caption
        Command2.Width = Label1.Width + tx * tx
        Check1.Move tx * c1, Combo1.Height + ty * c1, Picture1.Width - Command2.Width - tx * c1 * c1
        Command2.Move Picture1.Width - Command2.Width - tx * c1, Check1.Top, Command2.Width, Combo1.Height
        Check1.Visible = True
        Command2.Visible = True
    End Select
End Sub
 
'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
    m_BackColor = m_def_BackColor
    m_StyleBrowse = m_def_StyleBrowse
    m_Style = m_def_Style
    m_TopFolder = m_def_TopFolder
    m_EnabledButton2 = m_def_EnabledButton2
    m_EnabledCheck = m_def_EnabledCheck
End Sub
 
'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Frame1.Caption = PropBag.ReadProperty("Caption", "Выбор папки")
    Command1.Caption = PropBag.ReadProperty("CaptionButton1", "Обзор")
    Command2.Caption = PropBag.ReadProperty("CaptionButton2", "Дополнительно")
    Check1.Caption = PropBag.ReadProperty("CaptionCheck", "Разрешить")
    Check1.Value = PropBag.ReadProperty("Value", 0)
    UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
    Command2.Enabled = PropBag.ReadProperty("EnabledButton2", True)
    m_BackColor = PropBag.ReadProperty("BackColor", m_def_BackColor)
    m_StyleBrowse = PropBag.ReadProperty("StyleBrowse", m_def_StyleBrowse)
    m_Style = PropBag.ReadProperty("Style", m_def_Style)
    m_TopFolder = PropBag.ReadProperty("TopFolder", m_def_TopFolder)
    m_EnabledButton2 = PropBag.ReadProperty("EnabledButton2", m_def_EnabledButton2)
    m_EnabledCheck = PropBag.ReadProperty("EnabledCheck", m_def_EnabledCheck)
End Sub
 
'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Call PropBag.WriteProperty("Caption", Frame1.Caption, "Выбор папки")
    Call PropBag.WriteProperty("CaptionButton1", Command1.Caption, "Обзор")
    Call PropBag.WriteProperty("CaptionButton2", Command2.Caption, "Дополнительно")
    Call PropBag.WriteProperty("CaptionCheck", Check1.Caption, "Разрешить")
    Call PropBag.WriteProperty("Value", Check1.Value, 0)
    Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True)
    Call PropBag.WriteProperty("EnabledButton2", Command2.Enabled, True)
    Call PropBag.WriteProperty("BackColor", m_BackColor, m_def_BackColor)
    Call PropBag.WriteProperty("StyleBrowse", m_StyleBrowse, m_def_StyleBrowse)
    Call PropBag.WriteProperty("Style", m_Style, m_def_Style)
    Call PropBag.WriteProperty("TopFolder", m_TopFolder, m_def_TopFolder)
    Call PropBag.WriteProperty("EnabledButton2", m_EnabledButton2, m_def_EnabledButton2)
    Call PropBag.WriteProperty("EnabledCheck", m_EnabledCheck, m_def_EnabledCheck)
End Sub
 
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=Frame1,Frame1,-1,Caption
Public Property Get Caption() As String
    Caption = Frame1.Caption
End Property
 
Public Property Let Caption(ByVal New_Caption As String)
    Frame1.Caption() = New_Caption
    PropertyChanged "Caption"
End Property
 
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=Command1,Command1,-1,Caption
Public Property Get CaptionButton1() As String
    CaptionButton1 = Command1.Caption
End Property
 
Public Property Let CaptionButton1(ByVal New_CaptionButton1 As String)
    Command1.Caption() = New_CaptionButton1
    UserControl_Resize
    PropertyChanged "CaptionButton1"
End Property
 
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=Command2,Command2,-1,Caption
Public Property Get CaptionButton2() As String
    CaptionButton2 = Command2.Caption
End Property
 
Public Property Let CaptionButton2(ByVal New_CaptionButton2 As String)
    Command2.Caption() = New_CaptionButton2
    UserControl_Resize
    PropertyChanged "CaptionButton2"
End Property
 
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=Check1,Check1,-1,Caption
Public Property Get CaptionCheck() As String
    CaptionCheck = Check1.Caption
End Property
 
Public Property Let CaptionCheck(ByVal New_CaptionCheck As String)
    Check1.Caption() = New_CaptionCheck
    PropertyChanged "CaptionCheck"
End Property
 
Private Sub Combo1_Click()
    RaiseEvent SelectPath(Combo1.Text, Combo1)
End Sub
 
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=Check1,Check1,-1,Value
Public Property Get Value() As Integer
    Value = Check1.Value
End Property
 
Public Property Let Value(ByVal New_Value As Integer)
    On Error Resume Next
    Check1.Value() = New_Value
    If Err Then MsgBox Err.Number & vbCrLf & Err.Description, vbCritical
    PropertyChanged "Value"
End Property
 
Public Property Get Enabled() As Boolean
    Enabled = UserControl.Enabled
End Property
 
Public Property Let Enabled(ByVal New_Enabled As Boolean)
    Dim o As Object
    UserControl.Enabled() = New_Enabled
 
    For Each o In UserControl: o.Enabled = New_Enabled
    Next
    PropertyChanged "Enabled"
End Property
 
Private Sub DicComboRefresh()
    Dim f&
    On Error Resume Next
    Combo1.Refresh
    m_Dic.RemoveAll 'Обновление словаря !
 
    For f = 0 To Combo1.ListCount - 1
        m_Dic.Add Combo1.List(f), Combo1.ItemData(f)
    Next
    Combo1.SetFocus
End Sub
 
Private Sub Command2_Click()
    RaiseEvent ClickButton2(Combo1)
    DicComboRefresh
End Sub
 
Private Sub Check1_Click()
    RaiseEvent ClickCheck(Check1.Value)
End Sub
 
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=10,0,0,&H8000000F
Public Property Get BackColor() As OLE_COLOR
    BackColor = m_BackColor
End Property
 
Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
    m_BackColor = New_BackColor
    UserControl_Show
    PropertyChanged "BackColor"
End Property
 
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=25,0,0,0
Public Property Get StyleBrowse() As StyleBrowseFlags_ru
    StyleBrowse = m_StyleBrowse
End Property
 
Public Property Let StyleBrowse(ByVal New_StyleBrowse As StyleBrowseFlags_ru)
    m_StyleBrowse = New_StyleBrowse
    PropertyChanged "StyleBrowse"
End Property
 
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=23,0,0,0
Public Property Get Style() As StyleFlags_ru
    Style = m_Style
End Property
 
Public Property Let Style(ByVal New_Style As StyleFlags_ru)
    m_Style = New_Style
    UserControl_Resize
    PropertyChanged "Style"
End Property
 
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=23,0,0,0
Public Property Get TopFolder() As TopFolderFlags_ru
    TopFolder = m_TopFolder
End Property
 
Public Property Let TopFolder(ByVal New_TopFolder As TopFolderFlags_ru)
    m_TopFolder = New_TopFolder
    PropertyChanged "TopFolder"
End Property
 
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=0,0,0,1
Public Property Get EnabledButton2() As Boolean
    EnabledButton2 = m_EnabledButton2
End Property
 
Public Property Let EnabledButton2(ByVal New_EnabledButton2 As Boolean)
    m_EnabledButton2 = New_EnabledButton2
    UserControl_Show
    PropertyChanged "EnabledButton2"
End Property
 
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=0,0,0,1
Public Property Get EnabledCheck() As Boolean
    EnabledCheck = m_EnabledCheck
End Property
 
Public Property Let EnabledCheck(ByVal New_EnabledCheck As Boolean)
    m_EnabledCheck = New_EnabledCheck
    UserControl_Show
    PropertyChanged "EnabledCheck"
End Property

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

13   голосов , оценка 4 из 5
Похожие ответы