Results 1 to 3 of 3

Thread: [RESOLVED] [2005] 2 Classes with same Constants

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2006
    Location
    Moscato , Athens , Greece
    Posts
    60

    Resolved [RESOLVED] [2005] 2 Classes with same Constants

    Hello

    i have 2 classes with wame constants

    A.Cities_Lan_EN.vb
    Code:
    Public Class Cities_Lan_EN
     
    Public Const Literal_FormName As String  = "Cities"
    
    Public Const Literal_NavigationToolBar As String  = "Navigation ToolBar"
    Public Const Literal_MainToolBar As String  = "Basic ToolBar"
    Public Const Literal_ExtraToolBar As String  = "Extra ToolBar"
    
    End Class
    B.Cities_Lan_GR.vb

    Code:
    Public Class Cities_Lan_GR
     
    Public Const Literal_FormName As String  = "Πόλεις"
    
    Public Const Literal_NavigationToolBar As String  = "Εργαλεία Μετακίνησης"
    Public Const Literal_MainToolBar As String  = "Βασική Γραμμή Εργαλείων"
    Public Const Literal_ExtraToolBar As String  = "Πρόσθετα Εργαλεία"
    
    End Class
    At my form i have a SUB

    Code:
    Private Sub FormLanguage_Initilize()
    
    Dim CurrentLanguageLiteralsClass As New Cities_Lan_EN
    
    Select Case LanguageID
    	Case "EN"
    		CurrentLanguageLiteralsClass = New Cities_Lan_EN
    	Case "GR"
    		CurrentLanguageLiteralsClass = New Cities_Lan_GR
    End Select
    
    Me.Text = CurrentLanguageLiteralsClass.Literal_FormName
    
    Me.ToolbarManager1.Toolbars("ToolBar1").Text = CurrentLanguageLiteralsClass.Literal_NavigationToolBar
    Me.ToolbarManager1.Toolbars("ToolBar2").Text = CurrentLanguageLiteralsClass.Literal_MainToolBar
    Me.ToolbarManager1.Toolbars("ToolBar3").Text = CurrentLanguageLiteralsClass.Literal_ExtraToolBar
    
    End Sub
    I take the warning

    Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.

    What i have to change to Fix that problem

    Thanks in Advance
    Geobest

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: [2005] 2 Classes with same Constants

    Code:
    Public Interface ILanguage
        ReadOnly Property Literal_FormName() As String
        ReadOnly Property Literal_NavigationToolBar() As String
        ReadOnly Property Literal_MainToolBar() As String
        ReadOnly Property Literal_ExtraToolBar() As String
    End Interface
    
    Public Class Cities_Lan_EN
        Implements ILanguage
        Public ReadOnly Property Literal_ExtraToolBar() As String Implements ILanguage.Literal_ExtraToolBar
            Get
                Return "Extra ToolBar"
            End Get
        End Property
    
        Public ReadOnly Property Literal_FormName() As String Implements ILanguage.Literal_FormName
            Get
                Return "Cities"
            End Get
        End Property
    
        Public ReadOnly Property Literal_MainToolBar() As String Implements ILanguage.Literal_MainToolBar
            Get
                Return "Navigation ToolBar"
            End Get
        End Property
    
        Public ReadOnly Property Literal_NavigationToolBar() As String Implements ILanguage.Literal_NavigationToolBar
            Get
                Return "Basic ToolBar"
            End Get
        End Property
    End Class
    
    Public Class Cities_Lan_GR
        Implements ILanguage
        Public ReadOnly Property Literal_ExtraToolBar() As String Implements ILanguage.Literal_ExtraToolBar
            Get
                Return "Πρόσθετα Εργαλεία"
            End Get
        End Property
    
        Public ReadOnly Property Literal_FormName() As String Implements ILanguage.Literal_FormName
            Get
                Return "Πόλεις"
            End Get
        End Property
    
        Public ReadOnly Property Literal_MainToolBar() As String Implements ILanguage.Literal_MainToolBar
            Get
                Return "Βασική Γραμμή Εργαλείων"
            End Get
        End Property
    
        Public ReadOnly Property Literal_NavigationToolBar() As String Implements ILanguage.Literal_NavigationToolBar
            Get
                Return "Εργαλεία Μετακίνησης"
            End Get
        End Property
    End Class
    
    Private Sub FormLanguage_Initilize()
    
        Dim CurrentLanguageLiteralsClass As ILanguage
    
        Select Case LanguageID
            Case "EN"
                CurrentLanguageLiteralsClass = New Cities_Lan_EN
            Case "GR"
                CurrentLanguageLiteralsClass = New Cities_Lan_GR
        End Select
    
        Me.Text = CurrentLanguageLiteralsClass.Literal_FormName
    
        Me.ToolbarManager1.Toolbars("ToolBar1").Text = CurrentLanguageLiteralsClass.Literal_NavigationToolBar
        Me.ToolbarManager1.Toolbars("ToolBar2").Text = CurrentLanguageLiteralsClass.Literal_MainToolBar
        Me.ToolbarManager1.Toolbars("ToolBar3").Text = CurrentLanguageLiteralsClass.Literal_ExtraToolBar
    
    End Sub
    Also an enum of supported langues would be great for you. It protects against typos, and casing issues you get when testing strings:

    Code:
        Public Enum Languages
            EN = 1
            GR = 2
        End Enum
    
        Private Sub FormLanguage_Initilize()
    
            Select Case LanguageID
                Case Languages.EN
                    CurrentLanguageLiteralsClass = New Cities_Lan_EN
                Case Languages.GR
                    CurrentLanguageLiteralsClass = New Cities_Lan_GR
            End Select
    
        End Sub
    Last edited by wild_bill; Dec 14th, 2007 at 04:55 PM.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] 2 Classes with same Constants

    Actually..... I would go one step further, and put the above into a class with a function "GetLangOption"... then when you need something like the form name you'd call it like this:

    Code:
    txtMyText.Test = myLangClass.GetLangOption("FormName")
    then the class would look like this:
    Code:
    Public Function GetLangOption(OptionName as string) AS String
     Select Case OptionName
        Case "FormName"
            Return CurrentLanguageLiteralsClass.Literal_FormName
    ...
    
    End function
    This then hides the language enum options from the front end - making it easier to add more along the way.

    It could even be further refined, by loading everything into a Dictionary (Of Key, T) object, then you could do away with the Select Case, and use the OptionName as the key to retrieve the string to use....

    And I'm sure even then there's still MORE refinements and expansions that could be made.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width