Consulting

Results 1 to 4 of 4

Thread: Global Variabiles

  1. #1
    VBAX Newbie
    Joined
    May 2014
    Posts
    2
    Location

    Global Variabiles

    I'm tring to use a global variable, but I got some problems.
    here the architeture of my VBA.

    1. I create a Class Module named DatiVent
    Option Explicit
      Private m_Famiglia     As    String
      private m_Name         As    string
      .....
    
    Public Property Get GetFamiglia() As String
        Famiglia = m_Famiglia
     End Property
    
     Public Property Set SetFamiglia(value)
        m_Famiglia = value
      End Property
    .....

    2. then I create a Module named VarVENT where I create a public variable

    Public VARIABILI As DatiVent
    3. I'm tring to use the variable in a Form object:

    VARIABILI.SetFamiglia ("PIPPO")

    it dosen't work, I'm not an expert, This is the first time I'm using a more complex architeture, someone could help me?
    thank you in advance
    Last edited by Bob Phillips; 05-27-2014 at 03:39 AM. Reason: Added VBA tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Clas

    Option Explicit
    
    Private m_Famiglia As String
    Private m_Name As String
    
    
    Public Property Get Famiglia() As String
    Famiglia = m_Famiglia
    End Property
    
    Public Property Let Famiglia(value As String)
    m_Famiglia = value
    End Property
    managing module

        Set VARIABILI = New DatiVent
        VARIABILI.Famiglia = "PIPPO"
        MsgBox VARIABILI.Famiglia
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    May 2014
    Posts
    2
    Location
    Thank you XLD,

    your suggestion works, but in that way the variables "VARIABILI" is only available in the object where I made the "SET", have you any ideas to made possible to read and write in the "VARIABILI" even outside his object?

    thank you in advance

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You do read/write it outside of is object, as I showed in the managing module code, but you have to reference it via the object. That is the whole rationale of objects.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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