Representing Dynamic Arrays in VB.NET

This is a discussion on Representing Dynamic Arrays in VB.NET within the Pick Database forums in Other Databases category; Does anyone have any good ideas about the best way to represent a dynamic array in VB.NET? I'm looking to use it as a temporary, in memory store, not as a complex database. At first I thought to use a three-dimensional array, but that quickly fell apart (redimensioning doesn't work the way MV needs). Then I thought of using some kind of collection, but that looks complex to implement as a three-dimensional store. mv.NET is not an option in this project. Does anyone have any ideas? Or better yet, has anyone actually done it? ...

Go Back   Database Forum > Other Databases > Pick Database

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-08-2008, 03:33 PM
Default Representing Dynamic Arrays in VB.NET

Does anyone have any good ideas about the best way to represent a
dynamic array in VB.NET?

I'm looking to use it as a temporary, in memory store, not as a complex
database.

At first I thought to use a three-dimensional array, but that quickly
fell apart (redimensioning doesn't work the way MV needs). Then I
thought of using some kind of collection, but that looks complex to
implement as a three-dimensional store.

mv.NET is not an option in this project.

Does anyone have any ideas? Or better yet, has anyone actually done it?

Thanks.
Reply With Quote
  #2  
Old 08-08-2008, 04:52 PM
Default Re: Representing Dynamic Arrays in VB.NET

You can use "array of arrays" (not to be confused with multi-
dimensioned arrays) or "collection of collections" to nest your data
any number of levels deep.

I assume, though, you'll want to somehow be able to serialize/
deserialize dynamic array data as well. In that case, you'll need to
build your own functions to do so.

rex
Reply With Quote
  #3  
Old 08-08-2008, 05:54 PM
Default Re: Representing Dynamic Arrays in VB.NET



sh wrote:
> Does anyone have any good ideas about the best way to represent a
> dynamic array in VB.NET?
>
> I'm looking to use it as a temporary, in memory store, not as a complex
> database.
>
> At first I thought to use a three-dimensional array, but that quickly
> fell apart (redimensioning doesn't work the way MV needs). Then I
> thought of using some kind of collection, but that looks complex to
> implement as a three-dimensional store.
>
> mv.NET is not an option in this project.
>
> Does anyone have any ideas? Or better yet, has anyone actually done it?
>
> Thanks.


According to the UniObjects for .Net Developer's Guide you would use the
UniDynArray Class. This is if you are a UniVerse or UniData developer.

Ron White

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Reply With Quote
  #4  
Old 08-08-2008, 06:55 PM
Default Re: Representing Dynamic Arrays in VB.NET

Rex Gozar wrote:
> You can use "array of arrays" (not to be confused with multi-
> dimensioned arrays) or "collection of collections" to nest your data
> any number of levels deep.
>
> I assume, though, you'll want to somehow be able to serialize/
> deserialize dynamic array data as well. In that case, you'll need to
> build your own functions to do so.
>
> rex


Have you ever done it? It looks like it would be quite complicated to
implement, or am I just imagining it.

It looks to me like collections would be the way to go - no need to keep
track of dimensions and having to redim them.
Reply With Quote
  #5  
Old 08-08-2008, 07:59 PM
Default Re: Representing Dynamic Arrays in VB.NET

On Aug 8, 7:33 pm, sh wrote:
> Does anyone have any good ideas about the best way to represent a
> dynamic array in VB.NET?
>
> I'm looking to use it as a temporary, in memory store, not as a complex
> database.
>
> At first I thought to use a three-dimensional array, but that quickly
> fell apart (redimensioning doesn't work the way MV needs). Then I
> thought of using some kind of collection, but that looks complex to
> implement as a three-dimensional store.
>
> mv.NET is not an option in this project.
>
> Does anyone have any ideas? Or better yet, has anyone actually done it?
>
> Thanks.


ROFL

why bother?
Reply With Quote
  #6  
Old 08-08-2008, 08:02 PM
Default Re: Representing Dynamic Arrays in VB.NET

"sh" wrote in message
news:VNKdnTKK8I_5DAHVnZ2dnUVZ_u2dnZ2d-at-earthlink.co m...
> Does anyone have any good ideas about the best way to represent a dynamic
> array in VB.NET?
>
> I'm looking to use it as a temporary, in memory store, not as a complex
> database.
>
> At first I thought to use a three-dimensional array, but that quickly fell
> apart (redimensioning doesn't work the way MV needs). Then I thought of
> using some kind of collection, but that looks complex to implement as a
> three-dimensional store.
>
> mv.NET is not an option in this project.
>
> Does anyone have any ideas? Or better yet, has anyone actually done it?
>
> Thanks.



Just to create dynamic array-like functionality, create an "object" with
these properties (or something similar)

public xRec as string =vbnullstring ' define dynamic array somewhere
public default overloads property AVS()
get
try
return xrec
catch ex as exception
return vbnullstring
end try
end get
set (byval value as string)
try
xrec = value
catch ex as exception
end try
end set
end property
public overloads property AVS(byVal iAttr as integer)
dim XX(1) as string
get
try
xx = split(xrec,Chr(254))
return xx(iAttr-1) ' zero-relative
catch ex as exception
return vbnullstirng ' outside range of existing attributes
end try
end get
set(byval value as string)
try
xx = split(xrec,chr(254)) ' split the array into segments
' if they replace a value higher than we have, build up to it
if iAttr-1 > ubound(xx) then redim xx(iAttr-1) ' redimension
the array bigger
xx(iAttr-1) = value ' replace value
xrec = join(xx,Chr(254)) ' put it back together again
catch ex as exception
end try
end set
end property
public overloads property AVS(byVal iAttr as Integer, byval iVal as Integer)
dim XX(1) as string, YY(1) as string
get
try
XX = split(xrec,Chr(254))
YY = split(xx(iAttr-1),Chr(253))
return YY(iVal-1) ' zero-relative
catch ex as exception
return vbnullstirng ' outside range of existing attributes
end try
end get
set(byval value as string)
try
XX = split(xrec,chr(254)) ' split the array into segments
if iAttr-1 > ubound(XX) then redim xx(iAttr-1) ' redimension
the array bigger
YY = split(XX(iAttr-1),Chr(253))
if iVal-1 > ubound(YY) then redim YY(iVal-1)
YY(iVal -1) = value ' replace value
XX(iAttr-1) = join(YY,Chr(253))
xrec = join(xx,Chr(254)) ' put it back together again
catch ex as exception
end try
end set
end property

You get the idea. You can carry this on to as many levels as you want to
define delimiters (chr(251), ~, \ etc etc)


Mark

Reply With Quote
  #7  
Old 08-11-2008, 11:07 AM
Default Re: Representing Dynamic Arrays in VB.NET

Mark

Looks interesting. I never thought of it this way. I'll give it a look.

When I did a copy & paste into a new class, I got a load of error
messages. I guess you posted it quickly. I'll have to clean it up to see
how it works.

Thanks

Mark Brown wrote:
> "sh" wrote in message
> news:VNKdnTKK8I_5DAHVnZ2dnUVZ_u2dnZ2d-at-earthlink.co m...
>> Does anyone have any good ideas about the best way to represent a
>> dynamic array in VB.NET?
>>
>> I'm looking to use it as a temporary, in memory store, not as a
>> complex database.
>>
>> At first I thought to use a three-dimensional array, but that quickly
>> fell apart (redimensioning doesn't work the way MV needs). Then I
>> thought of using some kind of collection, but that looks complex to
>> implement as a three-dimensional store.
>>
>> mv.NET is not an option in this project.
>>
>> Does anyone have any ideas? Or better yet, has anyone actually done it?
>>
>> Thanks.

>
>
> Just to create dynamic array-like functionality, create an "object" with
> these properties (or something similar)
>
> public xRec as string =vbnullstring ' define dynamic array somewhere
> public default overloads property AVS()
> get
> try
> return xrec
> catch ex as exception
> return vbnullstring
> end try
> end get
> set (byval value as string)
> try
> xrec = value
> catch ex as exception
> end try
> end set
> end property
> public overloads property AVS(byVal iAttr as integer)
> dim XX(1) as string
> get
> try
> xx = split(xrec,Chr(254))
> return xx(iAttr-1) ' zero-relative
> catch ex as exception
> return vbnullstirng ' outside range of existing attributes
> end try
> end get
> set(byval value as string)
> try
> xx = split(xrec,chr(254)) ' split the array into segments
> ' if they replace a value higher than we have, build up to it
> if iAttr-1 > ubound(xx) then redim xx(iAttr-1) '
> redimension the array bigger
> xx(iAttr-1) = value ' replace value
> xrec = join(xx,Chr(254)) ' put it back together again
> catch ex as exception
> end try
> end set
> end property
> public overloads property AVS(byVal iAttr as Integer, byval iVal as
> Integer)
> dim XX(1) as string, YY(1) as string
> get
> try
> XX = split(xrec,Chr(254))
> YY = split(xx(iAttr-1),Chr(253))
> return YY(iVal-1) ' zero-relative
> catch ex as exception
> return vbnullstirng ' outside range of existing attributes
> end try
> end get
> set(byval value as string)
> try
> XX = split(xrec,chr(254)) ' split the array into segments
> if iAttr-1 > ubound(XX) then redim xx(iAttr-1) '
> redimension the array bigger
> YY = split(XX(iAttr-1),Chr(253))
> if iVal-1 > ubound(YY) then redim YY(iVal-1)
> YY(iVal -1) = value ' replace value
> XX(iAttr-1) = join(YY,Chr(253))
> xrec = join(xx,Chr(254)) ' put it back together again
> catch ex as exception
> end try
> end set
> end property
>
> You get the idea. You can carry this on to as many levels as you want
> to define delimiters (chr(251), ~, \ etc etc)
>
>
> Mark

Reply With Quote
  #8  
Old 08-11-2008, 07:19 PM
Default Re: Representing Dynamic Arrays in VB.NET

"sh" wrote in message
news:QtednaCnFsoM2j3VnZ2dnUVZ_g2dnZ2d-at-earthlink.co m...
> Mark
>
> Looks interesting. I never thought of it this way. I'll give it a look.
>
> When I did a copy & paste into a new class, I got a load of error
> messages. I guess you posted it quickly. I'll have to clean it up to see
> how it works.
>
> Thanks
>



Let me know if you need more specific help. I typed it in from memory and
didn't add all the properties and methods.


Mark

Reply With Quote
  #9  
Old 08-12-2008, 10:34 AM
Default Re: Representing Dynamic Arrays in VB.NET

sh,

Here's a link with some how-to info on VB.NET collections:

http://www.java2s.com/Tutorial/VB/01...Collection.htm

If you really are trying to create temporary storage, collections is
probably the way to go.

But it seems that you are unintentionally constrained by "multi-value
thinking". You didn't say whether or not your need to serialize/
deserialize the data; since it's temporary I'm going to assume "no".
That being the case, it might be better to think of your data in terms
of "structures within a structure".

Instead of associating {name, name, name} with {city, city, city}, try
thinking in terms of { {name, city}, {name, city}, {name, city} }
storing the associated data together as separate structures (i.e.
collections).

rex
Reply With Quote
  #10  
Old 08-12-2008, 11:01 AM
Default Re: Representing Dynamic Arrays in VB.NET

Mark

Thanks so much for your code snippet. I took the snippet, and created a
whole class, including Insert, Delete, and DCount methods and functions.
I'd be glad to post it, but I'm not sure a post here is the best way to
go with it.

I'd be happy to e-mail it to whoever is interested, or perhaps post it
to some multi-value site. However, I wrote it the "quick and dirty" way.
I'm not so happy with some of the syntax (some of it doesn't feel Pickie
or VB). I can see some places that can use some tightening up, or
perhaps better ideas of how to implement it, so I'd first like to get
some "peer review" of it. But it's really just an extension of your
ideas, Mark. Can I e-mail it to you first, Mark? Anyone else interested
in looking at it?

BTW Mark, I wasn't able to get those "default" methods to work. On the
first method, I got an error message saying that you cannot default a
method that has no parameter list. So I'm left with mvRec.Item as the
necessary syntax. Maybe you have a better way of doing it.

Sholom

Mark Brown wrote:
> "sh" wrote in message
> news:QtednaCnFsoM2j3VnZ2dnUVZ_g2dnZ2d-at-earthlink.co m...
>> Mark
>>
>> Looks interesting. I never thought of it this way. I'll give it a look.
>>
>> When I did a copy & paste into a new class, I got a load of error
>> messages. I guess you posted it quickly. I'll have to clean it up to
>> see how it works.
>>
>> Thanks
>>

>
>
> Let me know if you need more specific help. I typed it in from memory
> and didn't add all the properties and methods.
>
>
> Mark
>

Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 09:35 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.