|
-
Sep 7th, 2000, 03:09 AM
#1
Thread Starter
Lively Member
Hello World,
Once again I'm in need for your help....
I've built a collection of my own class which also holds a collection with onather class.
so i can do something like this :
colalfa(2).colbeta(3).text = "test"
from a db I read a lot of records with data like this:
alfanr betanr strtext
1 4 aaa
56 78 bbb
46 2 ccc
I want to add this data to my collection.
something like:
colalfa(alfanr).colbeta(betanr).text=strtext
how can i check if the colalfa(alfanr).colbeta(betanr) is already created ???
because if it does not exist yet i have to add it to my collection.
Greetinx,
Don
-
Sep 7th, 2000, 04:00 AM
#2
You can simply try to access it. If it doesn't exist you will get a trappable error.
Code:
'this code assumes you've read the db
'and that the result is in a RecordSet object
'called rs
On Error Resume Next
colalfa(rs!alfanr).colbeta(rs!betanr).Text = rs!strtext
If Err Then
'the item doesn't exist so create it here
End If
Good luck!
-
Sep 7th, 2000, 04:09 AM
#3
transcendental analytic
Without errorhandling, you can try to compare with IS
Code:
IF colalfa(rs!alfanr).colbeta(rs!betanr) Is nothing then
'does not exist
end if
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 7th, 2000, 04:09 AM
#4
Thread Starter
Lively Member
kedaman's solution:
when trying this error occurs in the following code:
Code:
Public Property Get Item(vntIndexKey As Variant) As colbeta
'used when referencing an element in the collection
'vntIndexKey contains either the Index or Key to the collection,
'this is why it is declared as a Variant
'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
Set Item = mCol(vntIndexKey)
End Property
how should i handle this ???
[Edited by Kersey on 09-07-2000 at 05:25 AM]
-
Sep 7th, 2000, 04:25 AM
#5
No! You don't have to catch the error within the class.
VB will raise an error when you're trying to access an item that doesn't exist.
-
Sep 7th, 2000, 04:34 AM
#6
Thread Starter
Lively Member
to Joachim
thanx
think YOUR solution will work just fine...
actually i was trying Kedaman's solution alredy but couldn't fix this error so if anyone would still reply ????....
Don
-
Sep 7th, 2000, 04:47 AM
#7
Conquistador
Re: to Joachim
Originally posted by Kersey
thanx
think YOUR solution will work just fine...
actually i was trying Kedaman's solution alredy but couldn't fix this error so if anyone would still reply ????....
Don
why wouldn't you be going for guru?
-
Sep 7th, 2000, 04:53 AM
#8
transcendental analytic
The problem is that Joacims solution resumes everytime an error occur, which is probably why the error didn't appear at all.
Now in the property get statement, put the set statement in the else part of a if statement comparing the reference with nothing again. 
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 7th, 2000, 05:11 AM
#9
Thread Starter
Lively Member
so I'll check for an error in
Code:
Public Property Get Item(vntIndexKey As Variant) As colbeta
'used when referencing an element in the collection
'vntIndexKey contains either the Index or Key to the collection,
'this is why it is declared as a Variant
'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
Set Item = mCol(vntIndexKey)
End Property
and set it to nothing if the err occurs.
so the object = nothing
to a_silvy :
I'm already working as a professional VB-developper, all that counts on your CV (at the end of the month this equals some amount of money in your wallet) is your MSDN & other diploma's , project experience ( finish them WELL & in time).
Who on earth cares if you're a vb-world guru (with respect to them who have the time skill and knowledge to reach this)??? ( I don't have the time !!!!)
When your good you will have to prove it in real life,
where other skills or even more important than programming Vb.
This does not mean I'm only here to ask question get the answer a go my own way ( Cashing in others peoples solutions).
Instead for every question I ask i try to answer at least one person as good as possible.
Because Togheter we can make better app's than each of us alone !
-
Sep 7th, 2000, 05:49 AM
#10
transcendental analytic
Again: No error checkin needed
You just use the same technique again:
Code:
if not mcol(vntindexkey) is nothing then
set item=mcol(vntindexkey)
end if
the item will remain nothing if theres no reference
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 7th, 2000, 07:03 AM
#11
Thread Starter
Lively Member
Error when not error checking
Dear Kedaman,
using following code (as suggested):
Code:
Public Property Get Item(vntIndexKey As Variant) As Gas
'used when referencing an element in the collection
'vntIndexKey contains either the Index or Key to the collection,
'this is why it is declared as a Variant
'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
If Not mCol(vntIndexKey) Is Nothing Then
Set Item = mCol(vntIndexKey)
End If
End Property
does generate following error
run-time error 5 : invalid procedure call or argument
at the line
Code:
If Not mCol(vntIndexKey) Is Nothing Then
because You cant use mcol(vntIndexKey) when vntIndexKey does not exist in the collection !!!!
So I think, I have to check for an error right here....
Unless someone else disagrees with me and supplies a solution for this
IT MIGHT BE YOU.....POST IT (please ?)
greetinx,
Don
-
Sep 7th, 2000, 07:16 AM
#12
transcendental analytic
You mean that you pass a key, instead of a index? eh, the error should be with block or variable not set, but i'm not sure, so anyway as it didn't work, you could use error trapping instead, to be sure use:
on local error resume next
shouldn't affect any error handling outside the class.
The property will still return an empty reference so you should use the is comparation method out there.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 7th, 2000, 07:33 AM
#13
Thread Starter
Lively Member
when passing a not existing index I get a subscript out of range !!!!
still testing da lot
so far this works fine:
Code:
Public Property Get Item(vntIndexKey As Variant) As Gas
'used when referencing an element in the collection
'vntIndexKey contains either the Index or Key to the collection,
'this is why it is declared as a Variant
'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
On Local Error Resume Next
Set Item = mCol(vntIndexKey)
End Property
Thanks for your Contribution !!!
(especially : KeDaMaN & JoAcHiM A.)
Don.
-
Sep 7th, 2000, 07:41 AM
#14
transcendental analytic
That should avoid everything, you could use ubound, lbound, abs and int to avoid the SOOR error, but this time errorhandling wins the game
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
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
|