Results 1 to 7 of 7

Thread: Classes Vb6

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    76

    Classes Vb6

    Hi,

    need help on a small application i am creating.... i created two classes however when i set them in one form i cant seem to access them in a different one.. experimented a bit... but dont really know how :d

    pls help
    VB Code:
    1. Option Explicit
    2. Dim player(5) As New player
    3. Dim area(5) As New area
    4. Dim base1, base2 As String
    5.  
    6. Public Sub setclass()
    7. Set player(1) = New player
    8. Set area(1) = New area
    9. Set area(2) = New area
    10.  
    11. player(1).SetUp 4,0,0,0,0
    12.  
    13. area(1).SetUp "player", 1, 0, 0, 0  // each has value reps a different property
    14. area(2).SetUp "enemy", 2, 0, 0, 0
    15. End Sub
    16. Private Sub Form_Load()
    17.  
    18. base1 = area(1).GetDescription
    19. base2 = area(2).GetDescription
    20.  
    21. If base1 <> base2 Then
    22. MsgBox "you fight"
    23. Else
    24. MsgBox "you love each other"
    25. End If
    26.  
    27. End Sub
    that all works... just if i wanna find out what area(1).getdescription in form2.


    thanks in advance


    steve
    Last edited by Hack; Mar 22nd, 2006 at 01:18 PM. Reason: Added [vbcode] [/vbcode] tags for more clarity.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Classes Vb6

    Anything that you define in the Declarations section of the form will be local to that form (and BTW you should use Private there rather than Dim). If you want them to be global the add a code module to your application and define them as Public there.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    76

    Re: Classes Vb6

    hi im new to classes.. so could u or someone else please give me a little more info on how?

    would be great thanx


    steve

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Classes Vb6

    Do: Project/Add Module

    Cut your code from its current location and paste it into the module.

    Change all Dim statements to Public.

  5. #5
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: Classes Vb6

    add this to your form2 and pass this information from form1
    before form2 is loaded;

    private pAreaDescription as String

    public property get AreaDescription() as string
    AreaDescription= pAreaDescription
    end property

    public property let AreaDescription(byval value as string)
    pAreaDescription= value
    end property

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    76

    Re: Classes Vb6

    thanx it worked perfectly..

    ciao

    steve
    Last edited by Stevanicus; Mar 22nd, 2006 at 01:59 PM.

  7. #7
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Classes Vb6

    also, you havent declared base1 as anything so its automatically a variant.
    so if you want base1 and base2 as string then youll need to do
    VB Code:
    1. Public Base1 As String
    2. Public Base2 As String
    Quote Originally Posted by Stevanicus
    Hi,

    need help on a small application i am creating.... i created two classes however when i set them in one form i cant seem to access them in a different one.. experimented a bit... but dont really know how :d

    pls help
    VB Code:
    1. Option Explicit
    2. Dim player(5) As New player
    3. Dim area(5) As New area
    4. Dim base1, base2 As String
    5.  
    6. Public Sub setclass()
    7. Set player(1) = New player
    8. Set area(1) = New area
    9. Set area(2) = New area
    10.  
    11. player(1).SetUp 4,0,0,0,0
    12.  
    13. area(1).SetUp "player", 1, 0, 0, 0  // each has value reps a different property
    14. area(2).SetUp "enemy", 2, 0, 0, 0
    15. End Sub
    16. Private Sub Form_Load()
    17.  
    18. base1 = area(1).GetDescription
    19. base2 = area(2).GetDescription
    20.  
    21. If base1 <> base2 Then
    22. MsgBox "you fight"
    23. Else
    24. MsgBox "you love each other"
    25. End If
    26.  
    27. End Sub
    that all works... just if i wanna find out what area(1).getdescription in form2.


    thanks in advance


    steve

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