|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
array element isexist ?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) zulan***@gmail.com ha scritto: Show quoteHide quote > 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 <zulan***@gmail.com> schrieb:
> is there a way to find out if the element exist ? You may want to use the array's 'IndexOf' method.> > dim myarray() as string -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> | theelemet myarray(4) doesn't exist how do i find out if it exist or not Without using ubound or GetUpperBound?? Have you tried Length?| with out doing ubound or GetUpperBound Generally I use GetUpperBound or Length to find the upper bound of an array... -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net <zulan***@gmail.com> wrote in message news:1153342671.471587.267520@b28g2000cwb.googlegroups.com... | 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 zulan***@gmail.com,
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 Show quoteHide quote > 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 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: Show quoteHide quote > Hello zulan***@gmail.com, > > 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 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... -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net <tommaso.gasta***@uniroma1.it> wrote in message news:1153380365.967421.23170@s13g2000cwa.googlegroups.com... | 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 zulan***@gmail.com, | > | > 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: Show quoteHide quote > 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 > > > <tommaso.gasta***@uniroma1.it> wrote in message > news:1153380365.967421.23170@s13g2000cwa.googlegroups.com... > | 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 zulan***@gmail.com, > | > > | > 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 > | 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 <zulan***@gmail.com> schreef in bericht Show quoteHide quote news:1153342671.471587.267520@b28g2000cwb.googlegroups.com... > 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 >
disabling checkbox in checkedlistbox
Argument not specified check database connection/open Datagrids (again) ComboBox SelectionChangeCommitted event fires twice How much disk space is needed... Deriving from Abstract Classes with Enums and Varying Object Types VB6 to VB.NET Error Compiling Create Recordset from a non standard data source |
|||||||||||||||||||||||