|
-
Jun 15th, 2000, 04:03 PM
#1
Thread Starter
Addicted Member
I have created a class which has a public property consisting of another class (which in turn contains another property referencing a third class), something like this (I have simplified it because I have used the VB Class Builder to create the classes):
Class 1 -- ZipCode:
Public Zip As String
Public Suffx As String
Class 2 -- Address:
Public Ad1 As String
. . .
Public AdZip As ZipCode
. . .
Class 3 -- Contact:
Public Name As String
. . .
Public HomeAd As Address
Public WorkAd As Address
. . .
I have declared a Public instance of Contact in a Module named MyContact.
Now, for example, when I want to assign a new value to a ZipCode, I have had to do the following:
Sub Text1_LostFocus()
Dim TempAd As Address
Set TempAd = MyContact.WorkAd
Dim TempZip As ZipCode
Set TempZip = TempAd.AdZip
TempZip.Zip = Text1.Text
Set TempAd.AdZip = TempZip
Set MyContact.WorkAd = TempAd
End Sub
When I try to do the following, I draw an error:
Sub Text1_LostFocus()
MyContact.WorkAd.AdZip.Zip = Text1.Text
End Sub
Is there a short hand that I am missing here? Why can't I get access to the properties directly?
Can some one help?
[Edited by New2VB on 06-16-2000 at 08:06 AM]
-
Jun 15th, 2000, 05:37 PM
#2
I'm guessing that you get a Object variable or With block not set.
If that is the case then it is because you didn't assign the classes to the variables that hold the classes
You will have to assign each of the nested classes to either a new or an existing class.
Example:
Code:
'This will give an error
MyContract.WorkAd.ZipCode = "BLABLA"
'This should work
'Assign classes to the classes ;)
Set MyContract = new Contract 'or Existing Contract
Set MyContract.WorkAd = new Address 'or Existing Adress
Set MyContract.WorkAd.ZipCode = new ZipCode 'or Existing ZipCode
'Now we can assig the variable to the zipcode
MyContract.WorkAd.ZipCode = "BLABLA"
Hope it helps.
-
Jun 17th, 2000, 09:07 AM
#3
Fanatic Member
your code seems to missing some bits
and maybe ought to look like below:
'--> class 1 declaration
Type MyZipCodeInfo
Zip As String
Suffx As String
End Type
Public MyZipCode
'--> class 2 declaration
Type MyAddressInfo
Add1 As String
AdZip As MyZipCode
End Type
Public MyAddress as MyAddressInfo
'--> class 3 declaration
Type MyContactInfo
myName As String
'NAME maybe be keyword and require square brackets
'but its easier to to prefix it with something
HomeAd As MyAddress
WorkAd As MyAddress
End Type
Public MyContact as MyContactInfo
and you ought to be able to use it straight away without having to SET it
DocZaf
{;->
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
|