473,587 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object not getting set

Greetings,

I'm running into a problem where an Object is evaluating to Nothing, even
though I'm setting it to a specific Object. Here's my code:

<code>
Private Sub CmdInventory(By Val Sender As Client, ByVal Arg As String)
'Shows the inventory of the indicated player. If the player is anyone other
than
'the Sender then the Sender must be a Wizard or Royal to see it.
Dim oPlayer As Player
Dim oTarget As Player
Dim lDBRef As Long
Dim cInv As New Hashtable()
Dim oItem As Item
Dim sMsg As New CString()
'Must be logged on.
If Sender.Status < ClientStatusEnu m.LoggedIn Then
Sender.Send("Yo u must be logged in.")
Exit Sub
End If
'If the Arg is someone other than the Sender then the Sender must be
'a Wizard or Royal.
oPlayer = cPlayers.Item(S ender.Player)
If Arg.Length > 0 Then
lDBRef = cPlayers.Player Exists(Arg)
If oPlayer.CheckNa me(Arg) = False And Arg.Compare(Arg .ToLower, "me") <>
0 Then
If Not oPlayer.CheckFl ag(FlagEnum.Wiz ard + FlagEnum.Royal) Then
Sender.Send("Yo u cannot view another player's inventory.")
Exit Sub
Else
'Check to see if the named player even exists.
If lDBRef = 0 Then
Sender.Send("Th at player does not exist; therefore, his
inventory does not exist.")
Exit Sub
End If
End If
End If
Else
lDBRef = Sender.Player
End If

'Get the Inventory and construct the Message.
oTarget = cPlayers.Item(l DBRef) <<<< This line seems to be setting oTarget
to Nothing, even though in the Debugger I can see that lDBRef
is the key
to an object in cPlayers, which is a Hashtable.
cInv = oTarget.GetInve ntory()
sMsg.Value = bRED & oTarget.Name & " Inventory:" & vbCrLf & bBLUE
If cInv.Count = 0 Then
sMsg.Append("No thing" & vbCrLf)
Else
For Each oItem In cInv.Values
sMsg.Append(oIt em.Name & " <" & oItem.DBRef & ">" & vbCrLf)
Next
End If
sMsg.Append(WHI TE)
Sender.Send(sMs g.Value)
End Sub

</code>

Any help would be appreciated.

Andrew
Nov 20 '05 #1
3 854
I just reread my post and realized that the News Reader reformatted my code
badly and that I put too much code in the post. My apologies. I've cut
down the code a bit and am going to try to format it nicely... if the News
Reader will let me do it.

I'm running into a problem where an Object is evaluating to Nothing, even
though I'm setting it to a specific Object. Here's my code:

oPlayer = cPlayers.Item(S ender.Player)
If Arg.Length > 0 Then
lDBRef = cPlayers.Player Exists(Arg)
If oPlayer.CheckNa me(Arg) = False And _
Arg.Compare(Arg .ToLower, "me") <> 0 Then

If Not oPlayer.CheckFl ag(FlagEnum.Wiz ard + FlagEnum.Royal) Then
Sender.Send("Yo u cannot view another player's inventory.")
Exit Sub
Else

'Check to see if the named player even exists.
If lDBRef = 0 Then
Sender.Send("Th at player does not exist.")
Exit Sub
End If
End If
End If
Else
lDBRef = Sender.Player
End If

'Get the Inventory and construct the Message.
'This line seems to be setting oTarget to Nothing,
'even though in the Debugger I can see that lDBRef
'is the key to an object in cPlayers, which is a Hashtable.
oTarget = cPlayers.Item(l DBRef)
cInv = oTarget.GetInve ntory()
There we go. Much better, I hope. Any help would be greatly appreciated.

Andrew
Nov 20 '05 #2
Is Sender.Player an integer? When the items are loaded are they added to the
hashtable using an integer key? I ask because lDBRef is a Long and one of
the dangers, one that most people overlook, of using a numeric key is that:

Dim Key1 as Byte = 25
Dim Key2 as Short = 25
Dim Key3 as Integer = 25
Dim Key4 as Long = 25

are all different keys since the object that is placed in the key collection
is of a different type.

So, if you are adding an item to cPlayer with an integer key of 12345 and
later you try to retrieve that item using a long key of 12345 the Hashtable
will, quite correctly, return Nothing.

"Andrew Cooper" <ae******@earth link.net> wrote in message
news:40******** **@newspeer2.td s.net...
Greetings,

I'm running into a problem where an Object is evaluating to Nothing, even
though I'm setting it to a specific Object. Here's my code:

<snip>

Nov 20 '05 #3
"Andrew Cooper" <ae******@earth link.net> schrieb

'Get the Inventory and construct the Message.
'This line seems to be setting oTarget to Nothing,
'even though in the Debugger I can see that lDBRef
'is the key to an object in cPlayers, which is a Hashtable.
oTarget = cPlayers.Item(l DBRef)
cInv = oTarget.GetInve ntory()

Do you initialize cPlayers anywhere? (cPlayers = New Hashtable)
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
3030
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less...
0
1097
by: John Perks and Sarah Mount | last post by:
I'm talk from the point of view of descriptors. Consider a.x = lambda self:None # simple function When a.x is later got, what criterion is used to see if a class (and so the func would have __get__(None, a) called on it)? Pre-metaclasses, one might assume it was isinstance(a, (types.TypeType, types.ClassType))
2
6904
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This...
1
3958
by: Bo Xu | last post by:
Object of Combination By Bo Xu Introduction A combination of n things, taken s at a time, often referred as an s-combination out of n, is a way to select a subset of size s from a given set of size n. There are n!/(s!(n-s)!) ways to do this. Donald E. Knuth gives several methods (algorithms) to generate all the s-combinations in . In such...
6
1754
by: Graham Pengelly | last post by:
Hi I'll try to spell out my problem as succinctly as possible... My database has a User table, an Organisation table, a Department table and a JobType table (amongst others) The Organisation table has a one to many relationship with the other three. The User table contains foreign keys to the Department and JobType tables (and the...
6
2551
by: solex | last post by:
Hello, I am trying to use serialization to copy objects. The object in question "Institution" inherits from a parent object "Party" both are marked as <Serializable()>. Initially I can copy an empty Institution to another empty Institution, using the following routine: Private Sub CopyObject(ByRef FromObject As Object, ByRef ToObject As...
9
3778
by: Greger | last post by:
Hi, I am building an architecture that passes my custom objects to and from webservices. (Our internal architecture requires me to use webservices to any suggestion to use other remoting techniques are not feasible) The question is; Given that I have a Person object with a private set for id. What is the recommended approac in passing...
2
1880
by: rocketfire97 | last post by:
I'm trying to call a COM object using C# but having no luck getting values back for passed in ref objects. I've tried the same call using VB.NET and can get data back. How would I implement the following in C# This is the method I am calling, which populates ref paramters with results. Sub Check_Customer(ByVal Customer As String,...
1
2670
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <script src="Dunbarlab9.js" type="text/javascript"></script> <script type="text/javascript">
0
1695
by: =?Utf-8?B?RmFicml6aW8gQ2lwcmlhbmk=?= | last post by:
I need to access classic ASP intrinsic objects and their properties from a ..net assembly wrapped to COM. The COM .net assembly is then instanciated from a classic ASP page with Server.CreateObject(). I'm trying to use the Microsoft Transaction Server this way: Type typeMtx = Type.GetTypeFromProgID("MTxAS.AppServer.1"); object mtxobject =...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.