Hello,
I have this for loop:
For i = 1 to 10
....
Next
I want to use the size of an array instead of 10.
How to determine the size of an array?
Thanks,
Miguel 7 1084
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eJ**************@TK2MSFTNGP14.phx.gbl... Hello,
I have this for loop:
For i = 1 to 10 ... Next
I want to use the size of an array instead of 10.
How to determine the size of an array?
Thanks, Miguel
Dim myArray As String() = New String() { "This", "is", "a", "string",
"array" }
For i = 0 To myArray.GetUpperBounds(0)
' Do something.
Next
NOTE: Can't remember if GetUpperBounds returns a 0 based index...it
probably does so you may need myArray.GetUpperBounds(0) - 1 instead.
Mythran
For i = 0 to UBound(MyArray)-1
....
Next
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eJ**************@TK2MSFTNGP14.phx.gbl... Hello,
I have this for loop:
For i = 1 to 10 ... Next
I want to use the size of an array instead of 10.
How to determine the size of an array?
Thanks, Miguel
hmmm, I think "Ubound" no need to -1
Egghead
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:et**************@TK2MSFTNGP14.phx.gbl... For i = 0 to UBound(MyArray)-1 ... Next
-- I hope this helps, Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message news:eJ**************@TK2MSFTNGP14.phx.gbl... Hello,
I have this for loop:
For i = 1 to 10 ... Next
I want to use the size of an array instead of 10.
How to determine the size of an array?
Thanks, Miguel
Shapper wrote: Hello,
I have this for loop:
For i = 1 to 10 ... Next
I want to use the size of an array instead of 10.
How to determine the size of an array?
Thanks, Miguel
myArray.Length
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
I think you do need it.
it's zero based.
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Egghead" <ro**************@shaw.ca> wrote in message
news:u8**************@TK2MSFTNGP15.phx.gbl... hmmm, I think "Ubound" no need to -1
Egghead "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:et**************@TK2MSFTNGP14.phx.gbl... For i = 0 to UBound(MyArray)-1 ... Next
-- I hope this helps, Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message news:eJ**************@TK2MSFTNGP14.phx.gbl... > Hello, > > I have this for loop: > > For i = 1 to 10 > ... > Next > > I want to use the size of an array instead of 10. > > How to determine the size of an array? > > Thanks, > Miguel >
When you use the ubound(array) in VB.net, it gives you the upper index of
the array, nothing to do with Zero based. such as
dim a as string() = {"A","B","C","D","E"}
ubound(a) will give you 4, same as in VB 6.0. Therefore, just to know the
size, it is better to use the length. It gives you 5. Just remember to "-1"
when you use it in a loop.
Do you get your mcsd in C#?
Egghead
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... I think you do need it. it's zero based.
-- I hope this helps, Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Egghead" <ro**************@shaw.ca> wrote in message news:u8**************@TK2MSFTNGP15.phx.gbl... hmmm, I think "Ubound" no need to -1
Egghead "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:et**************@TK2MSFTNGP14.phx.gbl... For i = 0 to UBound(MyArray)-1 ... Next
-- I hope this helps, Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message news:eJ**************@TK2MSFTNGP14.phx.gbl... > Hello, > > I have this for loop: > > For i = 1 to 10 > ... > Next > > I want to use the size of an array instead of 10. > > How to determine the size of an array? > > Thanks, > Miguel >
You are right.
I was confusing it with Array.Length, in which case the "-1" should be used.
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Egghead" <ro**************@shaw.ca> wrote in message
news:%2*****************@TK2MSFTNGP14.phx.gbl... When you use the ubound(array) in VB.net, it gives you the upper index of the array, nothing to do with Zero based. such as dim a as string() = {"A","B","C","D","E"} ubound(a) will give you 4, same as in VB 6.0. Therefore, just to know the size, it is better to use the length. It gives you 5. Just remember to "-1" when you use it in a loop.
Do you get your mcsd in C#?
Egghead
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... I think you do need it. it's zero based.
-- I hope this helps, Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Egghead" <ro**************@shaw.ca> wrote in message news:u8**************@TK2MSFTNGP15.phx.gbl... > hmmm, I think "Ubound" no need to -1 > > Egghead > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > news:et**************@TK2MSFTNGP14.phx.gbl... >> For i = 0 to UBound(MyArray)-1 >> ... >> Next >> >> -- >> I hope this helps, >> Steve C. Orr, MCSD, MVP >> http://SteveOrr.net >> >> >> "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message >> news:eJ**************@TK2MSFTNGP14.phx.gbl... >> > Hello, >> > >> > I have this for loop: >> > >> > For i = 1 to 10 >> > ... >> > Next >> > >> > I want to use the size of an array instead of 10. >> > >> > How to determine the size of an array? >> > >> > Thanks, >> > Miguel >> > >> >> > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: p175 |
last post by:
Hi folks,
I've tried reading just about every post I can on raid stiping / extent
size etc and I'm just getting myself more confused than ever. Here's my
situation.
On a Windows Server 2000...
|
by: sugaray |
last post by:
Hi, my problem with calculating the size of an array is when
I pass an array as a parameter to a function which perform the
calculation, the result never comes right, like below:
int...
|
by: Wynand Winterbach |
last post by:
I think every C programmer can relate to the frustrations that malloc
allocated arrays bring. In particular, I've always found the fact that
the size of an array must be stored separately to be a...
|
by: madireddy |
last post by:
Hi,
Inside a program how do i find out what size has been allocated to
pointer using malloc. eg...
int *p;
p=(int*)malloc(1024*sizeof(int));
now how do find how much has been allocated to p?...
|
by: manochavishal |
last post by:
Hi,
I have a question.
How can i know the size of array when it is passed to a function.
For Example i have this code:
#include <stdio.h>
#include <stdlib.h>
| |
by: redefined.horizons |
last post by:
I would like to have an array declaration where the size of the array
is dependent on a variable. Something like this:
/* Store the desired size of the array in a variable named
"array_size". */...
|
by: Harry |
last post by:
Good Day To all,
When i am declaring a array for e.g char ....it means i am
declaring array of 45 characters each of which has a maximum,minimum
value limit or range...for example in...
|
by: bowlderster |
last post by:
Hello,all.
I want to get the array size in a function, and the array is an argument of the function.
I try the following code.
/***************************************
*/
#include<stdio.h>...
|
by: desktop |
last post by:
I have a function that takes two pointers to an array. The first point
to the first element while the other points to the last element.
int nums = { 1, 2, 3, 4, 5, 7, 8, 9};
int* result;
int...
|
by: Adam Chapman |
last post by:
Hi,
Im trying to migrate from programming in Matlab over to C. Im trying
to make a simple function to multiply one matrix by the other. I've
realised that C can't determine the size of a 2d...
|
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,...
| |
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...
|
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...
|
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,...
|
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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |