comcrack Posted June 20, 2003 Posted June 20, 2003 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. : 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 Quote [ () /\/\ [ |\ /\ [ |<
aewarnick Posted June 20, 2003 Posted June 20, 2003 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. Quote C#
comcrack Posted June 20, 2003 Author Posted June 20, 2003 It's this line which doesn't work because It don't find the VBCRLF : Text1.Find(vbCrLf, Text1.SelectionStart + 1, RichTextBoxFinds.MatchCase) and I don't know why. Quote [ () /\/\ [ |\ /\ [ |<
aewarnick Posted June 20, 2003 Posted June 20, 2003 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... Quote C#
comcrack Posted June 20, 2003 Author Posted June 20, 2003 I tryed this : 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. Quote [ () /\/\ [ |\ /\ [ |<
aewarnick Posted June 20, 2003 Posted June 20, 2003 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? Quote C#
comcrack Posted June 20, 2003 Author Posted June 20, 2003 it's a enter (chr10) Quote [ () /\/\ [ |\ /\ [ |<
aewarnick Posted June 20, 2003 Posted June 20, 2003 Try searching for something else "Hi" maybe. See if it finds that. Quote C#
comcrack Posted June 20, 2003 Author Posted June 20, 2003 I tryed It does the same thing. Quote [ () /\/\ [ |\ /\ [ |<
aewarnick Posted June 20, 2003 Posted June 20, 2003 Ok, try bringing the text in as a string variable and searching that instead. See if that works. Quote C#
aewarnick Posted June 20, 2003 Posted June 20, 2003 Your best bet for finding anything in a string is to use class Regex. Here is a C# example: 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. Quote C#
comcrack Posted June 20, 2003 Author Posted June 20, 2003 I tryed to do this and it work : Text1.SelectionStart = Text1.Find("salut",Text1.SelectionStart + 1, RichTextBoxFinds.MatchCase) after I tryed this but it doesn't work. It did the same error Text1.SelectionStart = Text1.Find(chr(10),Text1.SelectionStart + 1, RichTextBoxFinds.MatchCase) Quote [ () /\/\ [ |\ /\ [ |<
comcrack Posted June 20, 2003 Author Posted June 20, 2003 I found some thing other whit split like you say: 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 Quote [ () /\/\ [ |\ /\ [ |<
cRuLo Posted June 22, 2003 Posted June 22, 2003 (edited) enter is Chr(13) .... not Chr(10) Edited June 23, 2003 by cRuLo Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.