Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?.

Posted (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 by techmanbd
Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

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".

Posted
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("-")

Being smarter than you look is always better than looking smarter than you are.
Posted
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("-")

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.

Posted

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."

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...