Help with Displaying Specific Line Number

XSYLUS

Member
Joined
Jan 25, 2008
Messages
5
Programming Experience
Beginner
Greetings!

Okay, here's the deal, I've been working on a program for the past week (in my spare time) and I've gotten pretty far on my own with the help of several ebooks and a few google searches. But now I'm stuck on what might be a very simple problem.

I have an if statement which checks the values of each line of a multiline textbox for the first value that is a positive number.

Example:

Let's say there are 5 lines in the textbox, the if statement (which is nested inside of a For/Next loop) checks each line and stops the loop as soon as a positive value is found.

Thus:

-22
-8
10
32
58

Displays 10 in the output field, which is exactly what I wanted, however, what I also need is for the output field to display which line that number is found on. In this case it's on line 3.

I know that the values in the textbox make up an array but I can't quite figure how to get it to output the line number.

Would I use Ubound, and if so how?

Here's the exact code I'm using, to help avoid too much confusion.

VB.NET:
1.)        For Each line As String In Me.txtBox4.Lines
2.)            Decimal.TryParse(line, System.Globalization.NumberStyles.Any, Nothing, value1)
3.)            If value1 >= 1 Then
4.)                lblOutput.Text = value1
5.)                Exit For
6.)           End If
7.)        Next
 
Another thought... I am going to try using Array.Indexof() and see if that works.
Yea, Array.Indexof() works. I figured it was something simple. If anyone has any other ideas feel free to share them, I'm still very new to VB so the more info the better.
 
Attention Site Administrator(s)

Feel free to remove this thread.

As far as I am concerned it is no longer necessary.

Thanks.
 
I know that the values in the textbox make up an array but I can't quite figure how to get it to output the line number.
VB.NET:
1.)        For Each line As String In Me.txtBox4.Lines
For-Each is one of two ways to iterate the array, the other is with a For-Next index iteration:
VB.NET:
For index As Integer = 0 To Me.TextBox1.Lines.Length - 1
    MsgBox(String.Format("{0}: {1}", index, Me.TextBox1.Lines(index)))
Next
Yea, Array.Indexof() works.
No, it doesn't, because if you have two lines with same value you will only get the first item. It may not concern you, but in many cases it does.
Attention Site Administrator(s)

Feel free to remove this thread.

As far as I am concerned it is no longer necessary.

Thanks.
That's not how the forums work. Did you notice there are currently about 19.000 threads at this site? Do you think we should delete this site and all forum sites on the internet?
 
Back
Top