VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Referring to unbounded arrays or where limit is undefined. Posted by DrMarten on 9 May 2006 at 2:40 PM
This message was edited by DrMarten at 2006-5-9 14:42:40


Hi,
myarray()
is not the same as

myarray

is it?

So to do something with myarray() i guess you need a special procedure or function that fills the elements otherwise what happens?

Does the array stop at one element or null?

Regards,

Dr M.

Report
Re: Referring to unbounded arrays or where limit is undefined. Posted by rlc on 10 May 2006 at 7:34 AM
I might not be getting you right so you might have to clarify... If you use () after a declaration you saying the object is an array, if you size it in declaration this should be allocated in the stack.

Dim Foo as String()  'no instance
Dim Foo2() as String  ' no instance
Dim Foo3(9)  '10 item array    'instance


If the array is not sized there is no instance of the array object and it will have no instance. You can of course resize an array which would then be on heap...

Redim Foo(9) '10 items


Until items are given references the array is emtpy so all items in it are nothing, although the array itself has an instance.

foo(0) = "Item One"
foo(1) = "Item Two"

Redim Preserve foo(19) ' keep references in array
Redim foo(19)          ' releases all references


Might not be what you were asking hope it helps.

~rlc

Report
Re: Referring to unbounded arrays or where limit is undefined. Posted by dokken2 on 10 May 2006 at 7:43 AM
: I might not be getting you right so you might have to clarify... If you use () after a declaration you saying the object is an array, if you size it in declaration this should be allocated in the stack.
:
:
: Dim Foo as String()  'no instance
: Dim Foo2() as String  ' no instance
: Dim Foo3(9)  '10 item array    'instance
: 

:
: If the array is not sized there is no instance of the array object and it will have no instance. You can of course resize an array which would then be on heap...
:
:
: Redim Foo(9) '10 items
: 

:
: Until items are given references the array is emtpy so all items in it are nothing, although the array itself has an instance.
:
:
: foo(0) = "Item One"
: foo(1) = "Item Two"
: 
: Redim Preserve foo(19) ' keep references in array
: Redim foo(19)          ' releases all references
: 

:
: Might not be what you were asking hope it helps.
:
: ~rlc
:
:

there is also a distinction between a static array - MyArray(8) of 9 elements, a dynamic array - MyArray() which can be redimed, and the array class - MyArray as Array
Report
Re: Referring to unbounded arrays or where limit is undefined. Posted by rlc on 10 May 2006 at 9:07 AM
Right 'Static' and 'Dynamic' are terms referring to the where the memory for the object is allocated, a static array will be allocated in the stack since the size is known, and a dynamic array in heap when the size is determined during runtime. Note, that a static array can become a dynamic array.

I did not think of the Array class itself, which is probally where the question is really coming from! Good thought. You can access the funcitons on the array class without an instance although I believe in every case you must pass areference of an instance into the functions.

~rlc
Report
Hi, everyone thanks so far but i was referring to.>> Posted by DrMarten on 10 May 2006 at 11:38 AM
This message was edited by DrMarten at 2006-5-10 11:43:41

: Hi,
: myarray()
: is not the same as
:
: myarray
:
: is it?
:
: So to do something with myarray() i guess you need a special procedure or function that fills the elements otherwise what happens?
:
: Does the array stop at one element or null?
:
: Regards,
:
: Dr M.
======================================================================

Hi,

Dim x() As Byte
        Dim y As Integer
        If iInit = 1 Then
            x = PB_Serial.receive(y)
            Me.rcvtext.Text = x.ToString
        End If

From this thread.>>
http://www.programmersheaven.com/c/msgboard/read.asp?Board=39&MsgID=336611&Setting=A9999F0001

The PB_serial is from 3rd party software and i've been trying to help user>> rhprogrammer <<.

Apparently the receive routine fills the x() array with bytes and i've never seen a statement like>>

x = PB_Serial.receive(y)

where this happens.
Will this be calling a custom CLASS which will have a RECEIVE sub or function i presume?

Thanks for your answers.


Regards,

Dr M.

Report
Re: Hi, everyone thanks so far but i was referring to.>> Posted by rlc on 10 May 2006 at 12:02 PM
Not knowing exactly what the COM component is doing it appears as though the 'Receive' function on the COM object takes in a parameter or flag 'newVal' which dicates some option, whatever work it does it creates a buffer with a byte array. When it is finished, most likely only if it finishes correctly, it will return the results of the action(whatever it is) in a byte array. Since I don't know what the action is or what type of output it might produce saying how to do display it would be difficult. If it is a text value I might try. Encoding.ASCII.GetString() or Convert.ToBase64String.

~rlc

Report
Thanks rlc. :-) Posted by DrMarten on 10 May 2006 at 12:26 PM
This message was edited by DrMarten at 2006-5-10 12:27:3

: Not knowing exactly what the COM component is doing it appears as though the 'Receive' function on the COM object takes in a parameter or flag 'newVal' which dicates some option, whatever work it does it creates a buffer with a byte array. When it is finished, most likely only if it finishes correctly, it will return the results of the action(whatever it is) in a byte array. Since I don't know what the action is or what type of output it might produce saying how to do display it would be difficult. If it is a text value I might try. Encoding.ASCII.GetString() or Convert.ToBase64String.

======================================================================

Hi,

Thanks for your answers.
I've passed code to>> rhprogrammer << to display the contents of the array in a textbox.

It just looked very unusual to me to have.>>

Dim x() As Byte 'followed not long after by>>
x=PB_Serial.Receive(y)

Regards,

Dr M.



Report
Re: Thanks rlc. :-) Posted by rlc on 10 May 2006 at 12:37 PM
Well when you are dealing with a third party object most likely you will have no access to the actual code (obviously). But depending on the tool, and the function, many times the return value will be in basic form so the tool does not do processing on the data (Usually tools are bought for some specific or complicated functoin/design). A) because it could make the tool slower. B) the end user of the tool would not have flexibility in optimizing the return data fully(reduce flexibliity.

It makes some sence for this, sometimes what will happen instead of returning an object, the maker of the tool will make a Public member on the COM object lets call it 'ReceiveBuffer' byte() and after you run the function this member will hold the result. This makes it somewhat simplier, but it then requires the COM object (often ActiveX controls also) to be larger. And possible requires added logic for managing the return values, instead of letting the user create their own structure for that.

~rlc



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.