Go to the line

comcrack

Regular
Joined
Jun 14, 2003
Messages
52
Location
Canada
Hy

I'm triing to make an HTML,PHP,ASP editor for myself. In the menu Edit, I add the menu 'Go to the line' . I try this code but it doesn't work. :

Visual Basic:
Private Sub MenuItem32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem32.Click
        Dim temp As String
startMenuItem32:
        temp = InputBox("Quelle ligne?", "ComCrack(Éditeur)")
        If temp = "" Then
            Exit Sub
        ElseIf Not IsNumeric(temp) Then
            MsgBox("La valeur n'est pas numérique.", MsgBoxStyle.Critical, "ComCrack(Éditeur)")
            GoTo startMenuItem32
        ElseIf Not Int(temp) = temp Then
            MsgBox("La valeur n'est pas numérique.", MsgBoxStyle.Critical, "ComCrack(Éditeur)")
            GoTo startMenuItem32
        End If
        Text1.SelectionStart = 0
        Dim i As Integer
        For i = 1 To temp
            Text1.Find(vbCrLf, Text1.SelectionStart + 1, RichTextBoxFinds.MatchCase)
        Next

Thank you

ComCrack
 
Most programmers don't suggest using a goto statement in their code. Use while loop instead with continue instead of goto and break to exit the loop.
 
It's this line which doesn't work because It don't find the VBCRLF :
Visual Basic:
Text1.Find(vbCrLf, Text1.SelectionStart + 1, RichTextBoxFinds.MatchCase)


and I don't know why.
 
The method Find returns an integer. It does not look like you are assigning the value retured from it to anything. Maybe you are but I just don't know VB syntax very well.

It is not going to highlight the word for you. You must use the integer returned as an index number to highlight the word with some other method...
 
I tryed this :
Visual Basic:
Text1.SelectionStart = Text1.Find(vbCrLf, Text1.SelectionStart + 1, RichTextBoxFinds.MatchCase)

but an error say that I can't asign -1 to text1.selectionstart :

Additional information: '-1' is not a valid value for 'value'.

I think it's because the find method doesn't find vbcrlf in my textbox
but there is many vbcrlf in the textbox.
 
You are going to have to split that up

int i=Text1.Find(vbCrLf, Text1.SelectionStart + 1, RichTextBoxFinds.MatchCase)
if(i not equal to -1)
Text1.SelectionStart = i

What is vbcrlf?
 
Ok, try bringing the text in as a string variable and searching that instead. See if that works.
 
Your best bet for finding anything in a string is to use class Regex.
Here is a C# example:
C#:
public static MatchCollection FindExact(string text, string find)
{
	MatchCollection mc = Regex.Matches(text, @"\W" + "(?<G>" + find + ")" + @"\W");
	return mc;
}
But if you are just looking for new line characters just use IndexOf of the string class.
 
I tryed to do this and it work :
Visual Basic:
Text1.SelectionStart = Text1.Find("salut",Text1.SelectionStart + 1, RichTextBoxFinds.MatchCase)

after I tryed this but it doesn't work. It did the same error

Visual Basic:
Text1.SelectionStart = Text1.Find(chr(10),Text1.SelectionStart + 1, RichTextBoxFinds.MatchCase)
 
I found some thing other whit split like you say:


Visual Basic:
        Dim temp As String
startMenuItem32:
        temp = InputBox("Quelle ligne?", "ComCrack(Éditeur)")
        If temp = "" Then
            Exit Sub
        ElseIf Not IsNumeric(temp) Then
            MsgBox("La valeur n'est pas numérique.", MsgBoxStyle.Critical, "ComCrack(Éditeur)")
            GoTo startMenuItem32
        ElseIf Not Int(temp) = temp Then
            MsgBox("La valeur n'est pas numérique.", MsgBoxStyle.Critical, "ComCrack(Éditeur)")
            GoTo startMenuItem32
        End If
        Text1.SelectionStart = 0
        Dim i As Integer
        Dim temparray() As String
        temparray = Split(Text1.Text, Chr(10))
        Dim temptextlen As Integer = 0
        If Not temp - 1 > UBound(temparray) Then
            For i = 1 To temp - 1
                temptextlen = temptextlen + 1 + Len(temparray(i - 1))
            Next
            Text1.SelectionStart = temptextlen
        End If
It work!!!!!!!!!!!!!!!!!!!!!

Thanks a lot

ComCrack
 
Back
Top