MSFN Forum: vb.NET Object/Array problem - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

vb.NET Object/Array problem VB.net Rate Topic: -----

#1 User is offline   phiban 

  • Newbie
  • Group: Members
  • Posts: 17
  • Joined: 01-October 06

Posted 24 November 2006 - 08:41 PM

hi all,

Basically I need your advice on some programming issues. I have class called Create_Packet which takes in values from the Main Form. The information is a mix of three Integers, a Byte array(The byte array has a string stored in it) and a Long. Is there a way that i could take all these values and store them in an object(or what ever would be best) and place it in a Queue once its removed from the queue, read back the information in another class called Read_Packet? If it would be possible for the other class to read the information back, how would it retrieve the information, any examples would go a long way

(Please bear in mind im just getting into programming now so if an object is what should be used here, please let me know why)

Any help would be most welcome

This post has been edited by phiban: 24 November 2006 - 08:44 PM



#2 User is offline   tap52384 

  • nLite Lover
  • PipPipPip
  • Group: Members
  • Posts: 331
  • Joined: 11-August 04

Posted 24 November 2006 - 09:36 PM

Why not use an arraylist as the queue? That way you can store the objects as objects and then cast them when you need to use them.

#3 User is offline   jcarle 

  • MSFN Master
  • Group: Developers
  • Posts: 2,569
  • Joined: 14-August 04

Posted 24 November 2006 - 09:38 PM

An even better approach would be to create a struct of the data you want to store, then create a generic list of that struct, essentially creating an arraylist that's typed to a custom struct.

#4 User is offline   phiban 

  • Newbie
  • Group: Members
  • Posts: 17
  • Joined: 01-October 06

Posted 24 November 2006 - 09:42 PM

yeah i was under the impression that a struct was the way to due to the diffrent data types, how would i make a generic list. Also just for my information, how will the other class Read_Packet be able to extract the diffrent data types?

#5 User is offline   jcarle 

  • MSFN Master
  • Group: Developers
  • Posts: 2,569
  • Joined: 14-August 04

Posted 24 November 2006 - 10:49 PM

http://weblogs.asp.net/cfranklin/archive/2...1/14/37503.aspx

And as long as you read and write the same Struct, everything will be fine.

#6 User is offline   LLXX 

  • MSFN Junkie
  • PipPipPipPipPipPipPipPipPip
  • Group: Banned
  • Posts: 3,399
  • Joined: 04-December 05

Posted 24 November 2006 - 11:47 PM

I'd just allocate a byte array and use pointers of various types, pointing to different locations within the array, to read the data. This is the most flexible approach, as structs, which seem to be encouraged much for this type of work, fail for strings of variable length, data that can be in different formats depending on other values in the array, etc.

#7 User is offline   phiban 

  • Newbie
  • Group: Members
  • Posts: 17
  • Joined: 01-October 06

Posted 25 November 2006 - 11:11 PM

Cool, Thanks for all the help guys :)

#8 User is offline   Colonel 

  • Newbie
  • Group: Members
  • Posts: 35
  • Joined: 28-November 06

Posted 29 November 2006 - 01:19 AM

jcarle was right on. I must disagree with LLXX though, pointers go against the entire idea of managed code and OOP.

A structure is the way to go because your data type has no functionality, no methods, etc. IE: Other objects use this data, this data doesn't do anything on its own.

Your structure should look something like this.
Public Structure PacketData
	Public IntegerOne as Integer
	Public IntegerTwo as Integer
	Public IntegerThree as Integer
	Public StringBytes as Byte()
	Public OtherNumber as Long
End Structure
Warning: I'm a C# guy myself, so some of this syntax may be a tad bit off.

If you are using .Net 2.0 you can use a System.Collections.Generic.Queue(Of PacketData) to strongly type your queue (See jcarle's post). So to get a set of data out of the queue, would could simply go:
Dim ReadData as PacketData = MyQueue.Dequeue()


If you are still using 1.0 or 1.1 you would need to use a System.Collections.Queue and cast the object from the Dequeue method back to PacketData like"
Dim ReadData as PacketeData = CType(MyQueue.Dequeue(), PacketData)


#9 User is offline   LLXX 

  • MSFN Junkie
  • PipPipPipPipPipPipPipPipPip
  • Group: Banned
  • Posts: 3,399
  • Joined: 04-December 05

Posted 29 November 2006 - 03:55 AM

View PostColonel, on Nov 29 2006, 02:19 AM, said:

I must disagree with LLXX though, pointers go against the entire idea of managed code and OOP.
Have fun trying to parse varying-format data efficiently :lol:

First example I can think of is TCP/IP packet header/trailers. Some fields are there, some are not, depending on other fields (which themselves may not be present and are dependent on bits in other fields, etc.)

This post has been edited by LLXX: 29 November 2006 - 03:56 AM


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy