shankar_it Posted August 30, 2005 Posted August 30, 2005 Dim a() As String a.SetValue("a-a", 0) a.SetValue("a-b", 1) a.SetValue("c-a", 2) a.SetValue("b-l", 3) a.SetValue("b-k", 4) a.SetValue("c-l", 5) a.SetValue("c-v", 6) a.SetValue("a-l", 7) when i try to use this in the program it always gives error.If i declare Dim a(500) As String it works but when i use a.length command it gives 501 as the result instead of 8 which i expect to return. Can any one help me in this?. Quote
techmanbd Posted August 30, 2005 Posted August 30, 2005 (edited) Are you trying to put strings into an array then find out how many items you assigned to the array? I would use arraylist like so Dim a As ArrayList a.Add("a-a") a.add("b-b") ' and so on. Dim i As Integer = a.Count Edited August 30, 2005 by techmanbd Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
shankar_it Posted August 30, 2005 Author Posted August 30, 2005 i tryed using the arraylist but in my program i am using a(i).Split("-") to get the first half of the each and every array in it and the split function does not work when i declare it as arraylist.I just want to run the program to get just the first half of each and every array which is the reason i am trying to use "Dim a() As String". Quote
Mothra Posted August 31, 2005 Posted August 31, 2005 i tryed using the arraylist but in my program i am using a(i).Split("-") to get the first half of the each and every array in it and the split function does not work when i declare it as arraylist.I just want to run the program to get just the first half of each and every array which is the reason i am trying to use "Dim a() As String". Have you tried using ReDim Preserve instead of a.SetValue("...", 0), etc? When you declare the array as Dim a(500) As String, you're going to always have an array with a length of that ammount. You could also try casting the item in the ArrayList as a string before you do the split: CType(a(i), String).Split("-") Quote Being smarter than you look is always better than looking smarter than you are.
Joe Mamma Posted August 31, 2005 Posted August 31, 2005 i tryed using the arraylist but in my program i am using a(i).Split("-") to get the first half of the each and every array in it and the split function does not work when i declare it as arraylist.I just want to run the program to get just the first half of each and every array which is the reason i am trying to use "Dim a() As String". a(i).ToString().Split("-") Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
shankar_it Posted August 31, 2005 Author Posted August 31, 2005 I opened a form and just typed in the below code Dim a As ArrayList a.Add("a") it compiles but it gives the below error during run time. "An unhandled exception of type 'System.NullReferenceException' occurred in remove duplicates.exe Additional information: Object reference not set to an instance of an object." Quote
techmanbd Posted August 31, 2005 Posted August 31, 2005 change Dim a As ArrayList to Dim a As New ArrayList need to put "New" in Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.