|
-
Mar 21st, 2006, 07:14 PM
#1
Thread Starter
Lively Member
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:
Option Explicit
Dim player(5) As New player
Dim area(5) As New area
Dim base1, base2 As String
Public Sub setclass()
Set player(1) = New player
Set area(1) = New area
Set area(2) = New area
player(1).SetUp 4,0,0,0,0
area(1).SetUp "player", 1, 0, 0, 0 // each has value reps a different property
area(2).SetUp "enemy", 2, 0, 0, 0
End Sub
Private Sub Form_Load()
base1 = area(1).GetDescription
base2 = area(2).GetDescription
If base1 <> base2 Then
MsgBox "you fight"
Else
MsgBox "you love each other"
End If
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.
-
Mar 21st, 2006, 08:22 PM
#2
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.
-
Mar 22nd, 2006, 01:09 PM
#3
Thread Starter
Lively Member
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
-
Mar 22nd, 2006, 01:20 PM
#4
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.
-
Mar 22nd, 2006, 01:22 PM
#5
Fanatic Member
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
-
Mar 22nd, 2006, 01:55 PM
#6
Thread Starter
Lively Member
Re: Classes Vb6
thanx it worked perfectly..
ciao
steve
Last edited by Stevanicus; Mar 22nd, 2006 at 01:59 PM.
-
Mar 22nd, 2006, 01:57 PM
#7
PowerPoster
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:
Public Base1 As String
Public Base2 As String
 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:
Option Explicit
Dim player(5) As New player
Dim area(5) As New area
Dim base1, base2 As String
Public Sub setclass()
Set player(1) = New player
Set area(1) = New area
Set area(2) = New area
player(1).SetUp 4,0,0,0,0
area(1).SetUp "player", 1, 0, 0, 0 // each has value reps a different property
area(2).SetUp "enemy", 2, 0, 0, 0
End Sub
Private Sub Form_Load()
base1 = area(1).GetDescription
base2 = area(2).GetDescription
If base1 <> base2 Then
MsgBox "you fight"
Else
MsgBox "you love each other"
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|