473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

newby VB arrays

Dear all,
How can I add something to the VB arrays after the initialization.
dim _points() as System.Drawing.points
If it is not possible how can I pass into function, with VB array as an
argument the .NET array.
I.e.
sub func(byval _points() as System.Drawing.points)
....
end sub
sub Main
dim _Array as arraylist
_array.add(..)
_array.add(..)
_array.add(..)
func(_array) <---- fails

What is the correct syntax?
Thanks,
Boni
Nov 21 '05 #1
12 1239
You are not passing the same type parameter, i.e., an arraylist being passed
to a function expecting an array. Try the following:

sub func(byval _points as Arraylist)

Then in the function when you use an element of _points;

dim b as point

b=directcast(_points(1),point)

You can then use b directly as a point or cast the _points array element to
a point type each time you need to use of _points elements.
--
Dennis in Houston
"Boni" wrote:
Dear all,
How can I add something to the VB arrays after the initialization.
dim _points() as System.Drawing.points
If it is not possible how can I pass into function, with VB array as an
argument the .NET array.
I.e.
sub func(byval _points() as System.Drawing.points)
....
end sub
sub Main
dim _Array as arraylist
_array.add(..)
_array.add(..)
_array.add(..)
func(_array) <---- fails

What is the correct syntax?
Thanks,
Boni

Nov 21 '05 #2
Boni,

\\\
sub func(byval ThisPoints as Arraylist)
dim mypoint as point = DirectCast(ThisPoints(0), System.Drawing.Points)
end sub
sub Main
dim Arl as new arraylist
Arl.Add(..points)
Arl.add(..)
Arl.add(..)
func(Arl)
///
I hope this helps,

Cor
Nov 21 '05 #3
Dear Sirs,
I thing there is a missunderstanding.
I didn' said, that I can't change func. It was not written by me (example of
func is Graphics.FillPolygon(brush, _points).
But I need to create the array of points dsynamically. Is it possible
somehow?
Thanks,
Boni

"Dennis" <De****@discussions.microsoft.com> schrieb im Newsbeitrag
news:52**********************************@microsof t.com...
You are not passing the same type parameter, i.e., an arraylist being
passed
to a function expecting an array. Try the following:

sub func(byval _points as Arraylist)

Then in the function when you use an element of _points;

dim b as point

b=directcast(_points(1),point)

You can then use b directly as a point or cast the _points array element
to
a point type each time you need to use of _points elements.
--
Dennis in Houston
"Boni" wrote:
Dear all,
How can I add something to the VB arrays after the initialization.
dim _points() as System.Drawing.points
If it is not possible how can I pass into function, with VB array as an
argument the .NET array.
I.e.
sub func(byval _points() as System.Drawing.points)
....
end sub
sub Main
dim _Array as arraylist
_array.add(..)
_array.add(..)
_array.add(..)
func(_array) <---- fails

What is the correct syntax?
Thanks,
Boni

Nov 21 '05 #4
"Boni" <oilia@nospam> schrieb:
How can I add something to the VB arrays after the initialization.
dim _points() as System.Drawing.points
If it is not possible how can I pass into function, with VB array as an
argument the .NET array.
I.e.
sub func(byval _points() as System.Drawing.points)
...
end sub
sub Main
dim _Array as arraylist
=> 'As New ArrayList()'.
_array.add(..)
_array.add(..)
_array.add(..)
func(_array) <---- fails

What is the correct syntax?


The size of an array cannot be altered after the array is created. However,
you can create a new array of appropriate size and copy the data from the
old array over to the new array. This operation can be simplified by using
'ReDim Preserve' (see documentation).

In the sample above there is nothing wrong with an arraylist. You an create
an array based on the arraylist and pass the array to the function:

\\\
func(DirectCast(_array.ToArray(GetType(Point)), Point()))
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
> Dear Sirs,
I thing there is a missunderstanding.
I didn' said, that I can't change func. It was not written by me (example
of func is Graphics.FillPolygon(brush, _points).


Why are you asking than this what is bellow and not what is above.
If it is not possible how can I pass into function, with VB array as an
argument the .NET array.


Maybe can you than be more clear, if you want a variable fixed array of
points it is more work than that you want a real fixed array of points.

Cor
Nov 21 '05 #6
Boni,

This I never tried, however I got this idea, I think that it is more
eficient than we have ever showed it in this newsgroup.

\\\
Sub func(ByVal ThisPoints() As System.Drawing.Point)
End Sub
Sub test()
Dim Arl As New ArrayList
Arl.Add(New Point(1, 2))
Arl.Add(New Point(1, 2))
Dim mPoint(Arl.Count - 1) As System.Drawing.Point
Arl.CopyTo(mPoint)
func(mPoint)
End Sub
///

I hope this helps,

Cor
Nov 21 '05 #7
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
This I never tried, however I got this idea, I think that it is more
eficient than we have ever showed it in this newsgroup.

\\\
Sub func(ByVal ThisPoints() As System.Drawing.Point)
End Sub
Sub test()
Dim Arl As New ArrayList
Arl.Add(New Point(1, 2))
Arl.Add(New Point(1, 2))
Dim mPoint(Arl.Count - 1) As System.Drawing.Point
Arl.CopyTo(mPoint)
func(mPoint)
End Sub


Mhm... I still prefer this one:

\\\
Dim a As New ArrayList()
a.Add(New Point(10, 10))
a.Add(New Point(20, 20))
a.Add(New Point(30, 30))
Dim Points() As Point = DirectCast(a.ToArray(GetType(Point)), Point())
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #8
Herfried,

Than would be even better in this case

\\\
func(DirectCast(a.ToArray(GetType(Point)), Point()))
///

However maybe is my sample easier to understand.

:-)

Cor
Nov 21 '05 #9
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
Than would be even better in this case

\\\
func(DirectCast(a.ToArray(GetType(Point)), Point()))
///
ACK. This was my initial suggestion.
However maybe is my sample easier to understand.


That might be true... :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #10
Herfried,

You are right, I thought it were the parameters from the function it self.

And as you know I can say Sorry,

:-)

Cor
Nov 21 '05 #11
Dear Cor,
Let's have following concrete example.
I want to create an array of points dynamically and than use it in
FillPolygon.The signature of FillPolygon is(brush, point())
How can I convert dynamic array of poins into an array which is required by
FillPolygone?
Did I understand you correctly, that it is not possible to use FillPolygon
if the number of points is not known at compile time?
Thank you very much for your help,
Boni
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb im Newsbeitrag
news:OC**************@TK2MSFTNGP12.phx.gbl...
Dear Sirs,
I thing there is a missunderstanding.
I didn' said, that I can't change func. It was not written by me (example
of func is Graphics.FillPolygon(brush, _points).


Why are you asking than this what is bellow and not what is above.
If it is not possible how can I pass into function, with VB array as an
argument the .NET array.


Maybe can you than be more clear, if you want a variable fixed array of
points it is more work than that you want a real fixed array of points.

Cor

Nov 21 '05 #12
Dear Sirs,
thank you for your great help! Now the solution is very clear.
Boni
Nov 21 '05 #13

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

Similar topics

9
by: Damien | last post by:
I have just built a simple stopwatch application, but when i f5 to get things goings i get this message, An unhandled exception of type 'System.ArithmeticException' occurred in...
0
by: Pete | last post by:
Hi All, A total Newby with, possibly, a daft question? However, until I can get a reasonable explanation I am disinclined towards going further. Here goes: I recently downloaded the latest...
0
by: marco | last post by:
I'm trying to parse a xml bookmarkpage with php. I found a very useful example script about how you can parse a xml document with php. The scriptworks really smooth. The xml test document (See...
9
by: CeyloR | last post by:
Hello everyone, I just started with the language C and it's very interesting. I bought the book 'The C Programming Language' from Brian W. Kernighan and Dennis M. Ritchie. While reading...
7
by: Fred Nelson | last post by:
Hi: I'm more than a little confused with this question: I need to create a char type from the first letter in a string - for example: string mystring; char mychar;
10
by: Fred Nelson | last post by:
Hi: I have programmed in VB.NET for about a year and I'm in the process of learing C#. I'm really stuck on this question - and I know it's a "newby" question: In VB.NET I have several...
4
by: Boni | last post by:
Hi, How do I create an array of 2 to object pointers? i.e. dim a as object(2) Thanks, Boni
7
by: maria | last post by:
Hi all I used to work with VB, and now I am trying C# and can't get it start for example in VB Dim Items() as tItems dim NumberOfitems as long obj.GetAllItems(NumberOfitems, Items()) for i=0...
5
by: alexrixhardson | last post by:
Hi guys, I am a newby in the C/C++ world, and I am beginning to work on a rather simple TCP/IP proxy application which must be able to handle large volume of data as quickly as possible. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.