Using For Each Loops to Different lines in a Textbox

180hpr

New member
Joined
Feb 24, 2012
Messages
3
Programming Experience
Beginner
I am trying to create a For Each Loop in my program.

I have 20 lines worth of data in my RichTextBox, and I want to apply a ruleset as follows: Code:

VB.NET:
If Textbox1.Text.Contains(Printer(13)) 
Then ClassifyTextbox.Text = "Printer - Jam" 
ElseIf Textbox1.Text.Contains(Printer(9)) Then ClassifyTextBox.Text = "Printer - Toner" 
ElseIf Textbox1.Text.Contains(Printer(i)) Then ClassifyTextBox.Text = "Printer"

The 20 lines I have are IT related issues, e.g 'The printer has a paper jam'
The Classify Textbox displays the class the issue relates to, then I have some code to send it to a text file for storage.

Each of the 20 lines are different classes, however can anyone help me with a For Each Loop statement to read the first issue classify it send it, then repeat 20 times, so that my text file has 20 rows of data, but each issue has been classified due to my ruleset in the code above?
 
Hope this helps, i use this for simler things you have mentioned.

VB.NET:
Option Strict On
Option Explicit On

Public Class frmOptions

    Private Sub btnRun_Click(sender As System.Object, e As System.EventArgs) Handles btnRun.Click
        'Clears The Text Result Box up on the Control Button being pressed
        txtResult.Clear()
        'These below are you Declared Values
        'strText(3) is an Array of Strings (Any letter, number or symbol), and nbrValue(3) is an Array of Integers (Numbers Only)
        'I is also an integer which is Set to store a single Value as a time.
        Dim strText(2) As String
        Dim nbrValue(2) As Integer
        Dim I As Integer

        'Here are the Array(s) with their stored values and seperator :
        nbrValue(0) = 13 : strText(0) = "Printer - Jam"
        nbrValue(1) = 9 : strText(1) = "Printer - Toner"
        nbrValue(2) = 1 : strText(2) = "Printer"

        'Simple For an Next loop which rages from 0 to 2 as all arrays should be used like this
        'Example: if you have 20 items in your array then you would range the numbers from 0 to 19 for the 20 items
        ' Which is generally good programming practice
        For I = 0 To 2
            'This line here checks the for next loop and catches the Value which is needed for the txtValue.text
            'and then txtResult.text equals the Required String as both use the For,Next loop to equal the requires values
            If CDbl(txtValue.Text) = nbrValue(I) Then txtResult.Text = strText(I).ToString
            'Hope This helps or is an the region you were looking for
        Next
    End Sub
End Class

i wrote somthing simler to this for an app needing to call certain ListBox Items.
 
I have an issue with the line:
If CDbl(ClassTextBox.Text) = nbrValue(I) Then

And I got a InvalidCastException was unhandled error, and it was 'Conversion from string "" to type 'Double' is not valid'

Do you have any ideas?
 
I have an issue with the line:
If CDbl(ClassTextBox.Text) = nbrValue(I) Then

And I got a InvalidCastException was unhandled error, and it was 'Conversion from string "" to type 'Double' is not valid'

Do you have any ideas?

I'm using VB.NET 2010 so if you not maybe thats it

CHANGE THIS:
If CDbl(ClassTextBox.Text) = nbrValue(I) Then

TO THIS:
If ClassTextBox.Text = nbrValue(I).ToString Then

You Might not need to ".ToString" on nbrValue(i)

if your still having problems send me the code your using, as the one on the board works fine for me :|
 
Back
Top