array element isexist ?

  • Thread starter Thread starter zulander
  • Start date Start date
Z

zulander

is there a way to find out if the element exist ?

dim myarray() as string
dim mytxt as string

mytxt ="Superman1,Superman2,Superman3,Superman4"

myarray=mytxt.split(",")

debug.print(myarray(4))

theelemet myarray(4) doesn't exist how do i find out if it exist or not
with out doing ubound or GetUpperBound
thank you
 
Hi zulander (nice movie!)

Indexes start from 0. ubound is the last index in the array (3 in your
case):0,1,2,3
(that's count -1)

(e-mail address removed) ha scritto:
 
| theelemet myarray(4) doesn't exist how do i find out if it exist or not
| with out doing ubound or GetUpperBound

Without using ubound or GetUpperBound?? Have you tried Length?

Generally I use GetUpperBound or Length to find the upper bound of an
array...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| is there a way to find out if the element exist ?
|
| dim myarray() as string
| dim mytxt as string
|
| mytxt ="Superman1,Superman2,Superman3,Superman4"
|
| myarray=mytxt.split(",")
|
| debug.print(myarray(4))
|
| theelemet myarray(4) doesn't exist how do i find out if it exist or not
| with out doing ubound or GetUpperBound
| thank you
|
 
Hello (e-mail address removed),

Most array's in .NET are 0-based. Hoever it is possible to create arrays
which start at a different index. So GetUpperBound() and GetLowerBound()
are the best methods for determining your bounds. Any other method is just
guessing.

-Boo
 
Zulander,

The way I would use it.

\\\
Dim myarray() As String
Dim mytxt As String
mytxt = "Superman1,Superman2,Superman3,Superman4"
myarray = mytxt.Split(","c)
If myarray.Length < 4 Then
Debug.Print(myarray(4))
End If
///

I hope this helps,

Cor
 
hi GhostInAK

can you make an example of what you mean by starting
at a different index?

-tom

PS. btw array elements are not sexist :)

GhostInAK ha scritto:
 
Tommaso,
Try something like:

Dim list As Array
Dim lengths() As Integer = {10, 10}
Dim lowerBounds() As Integer = {1, 1}
list = Array.CreateInstance(GetType(Integer), lengths, lowerBounds)
Dim values(,) As Integer = DirectCast(list, Integer(,))

For x As Integer = values.GetLowerBound(0) To
values.GetUpperBound(0)
For y As Integer = values.GetLowerBound(1) To
values.GetUpperBound(1)
values(x, y) = x * y
Next
Next

' this causes an exception!
Dim value As Integer = values(0, 0)

What I think misleads people is that most .NET languages (such as C# & VB)
only support creating 0 based arrays in their "native" syntax. If you use
the runtime itself, you can create an array with any lower bound...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| hi GhostInAK
|
| can you make an example of what you mean by starting
| at a different index?
|
| -tom
|
| PS. btw array elements are not sexist :)
|
| GhostInAK ha scritto:
|
| > Hello (e-mail address removed),
| >
| > Most array's in .NET are 0-based. Hoever it is possible to create
arrays
| > which start at a different index.
| >
| > -Boo
| >
| > > is there a way to find out if the element exist ?
| > >
| > > dim myarray() as string
| > > dim mytxt as string
| > > mytxt ="Superman1,Superman2,Superman3,Superman4"
| > >
| > > myarray=mytxt.split(",")
| > >
| > > debug.print(myarray(4))
| > >
| > > theelemet myarray(4) doesn't exist how do i find out if it exist or
| > > not
| > > with out doing ubound or GetUpperBound
| > > thank you
|
 
Thanks Jay. It helps a lot !

I did not know that, and it's good to learn it can be done this way.

I also think, however, they while a rich language such as vb.net allows
to do many things, many of them should be accurately avoided in order
not to have troubles.

Actually I regard the path of learning a language a kind of selective
process where one, by learning from experience, learns to distinguish
what lead to good and maintenable programs from what instead
calls only for troubles. Sometimes this process can be very painful
as we may be spending days just for 1 bug.

During the years I have changed a lot my way of programming
and I am continuosly getting rid of (what prove to be) bad habits.

I see it like a kind of puzzle, ... at the end there aren't actually
that many ways to put the parts together :)

-tom

Jay B. Harlow [MVP - Outlook] ha scritto:
 
Back
Top