I would like to get the last value of a specific column but it is returning the whole column values.
below is my code:
LastSSN = row(1).ToString().Split(","c).Last()
here is the result:
I would like to only get “821024241”
Your immediate assistance is greatly appreciated.
There are probably a couple ways.
One way is to take the last row, then extract the column of that row.
Another way is to take all the items of the column as a list then extract the last item using a lambda expression
Both methods are to be used outside of the for each since you are only extracting the last item in the column and don’t need to loop through everything.
Thank you ClaytonM! your response is very fast!
this one is working:
i realized .Last cannot be used with .Rows, so the alternative was to use .Count
(I will correct it in my previous post.)
To be honest, I prefer the second solution I provided though or atleast knowing it cause it is very versatile and powerful.
is working too!
I have converted the result to Int32 so that I can add a value. for example: 821024241 + 1
how can I do that?
You can use some vb to convert it when performing the math.
The number is a little long so you might use the Long type.
(for Int32, it’s just CInt() or Convert.ToInt32())
It’s also good practice to check your string to make sure it’s a number first.
If(IsNumeric(LastSSN), CLng(LastSSN), 0) + 1
(Assuming LastSSN is the string you extracted as the last ssn)
Got it! You are awesome! thank you very much!