P
Pascal
hello
Short summary of my goal: I try to make a small software to easily create
exercises like on my site here:
http://www.scalpa.info/fr_gram_vb1_clicmot.php
I do these exercises by hand now, by directly editing the javascript and
html file.
I'd like to build a small program that would generate this type of exercise
and bring an improvement for words which are written with the same letters
but have a different meaning (homograph?).
At this time, If I ask my students to find the verb in the following
sentence: "Les poules du couvent couvent." The verb "couvent"(incubate) and
the name "couvent" (a convent) is considered in the same way!
In my previous posts, I tried to understand a few things: select, deselect
one word in a RichTextBox to edit it using regex words etc.. And I thank
everybody for his help. People on This forum are efficient.
To distinguish words that I consider a good response from others, I thought:
1) identify them in a RichTextBox by clicking on each, applying special
format (fontsize, fonttype etc.).
2)Then using a regex that would test this format, and change it by a
particular tag.
Here is the code I Used :
Imports System.Text.RegularExpressions
Module Core
'ToDo créer une variable pour les séparateurs
Private chars As Char() = " ,.:;?!-'`".ToCharArray
Public Function SelectWord(ByVal RTBText As RichTextBox)
Dim LeMot As String = String.Empty
Dim cursorPosition As Integer = RTBText.SelectionStart
Dim nextSpace As Integer = RTBText.Text.IndexOfAny(chars,
cursorPosition)
Dim selectionStart As Integer = 0
Dim trimmedString As String = String.Empty
' Strip everything after the next space...
If nextSpace <> -1 Then
trimmedString = RTBText.Text.Substring(0, nextSpace)
Else
trimmedString = RTBText.Text
End If
If trimmedString.LastIndexOfAny(chars) <> -1 Then
selectionStart = 1 + trimmedString.LastIndexOfAny(chars)
trimmedString = trimmedString.Substring(1 +
trimmedString.LastIndexOfAny(chars))
End If
RTBText.SelectionStart = selectionStart
RTBText.SelectionLength = trimmedString.Length
Return LeMot
End Function
Public Function ChangeFormat(ByRef RTBText As RichTextBox)
If RTBText.SelectionFont.Name = ("Tahoma") And _
RTBText.SelectionFont.Size = "12" And _
RTBText.SelectionFont.Style = FontStyle.Bold And _
RTBText.SelectionColor = System.Drawing.Color.Red Then
RTBText.SelectionFont = New Font("Arial", 11, FontStyle.Regular)
RTBText.SelectionColor = System.Drawing.Color.Black
Else
RTBText.SelectionFont = New Font("Tahoma", 12, FontStyle.Bold)
RTBText.SelectionColor = System.Drawing.Color.Red
RTBText.AutoWordSelection = True
End If
Return RTBText
End Function
Public Function SpanWord2(ByVal Rtb As RichTextBox)
Dim input As String = Rtb.Text
Dim pattern As String = "([\w]+)(?=[\s '.,;!?«»\-(\)])"
'for words that are not a solution
Dim replacement As String = "<span class=""blue""
onclick=""verif(this)"">$1</span>"
'for solution words
Dim replacement2 As String = "<span id=""yes"" class=""blue""
onclick=""verif(this)"">$1</span>"
Dim rgx As New Regex(pattern)
Dim options As RegexOptions = RegexOptions.IgnoreCase
If Rtb.SelectionFont.Name = ("Tahoma") And _
Rtb.SelectionFont.Size = "12" And _
Rtb.SelectionFont.Style = FontStyle.Bold And _
Rtb.SelectionColor = System.Drawing.Color.Red Then
Dim result As String = rgx.Replace(input, replacement2)
Return result
Else
Dim result As String = rgx.Replace(input, replacement)
Return result
End If
End Function
End Module
Code for the form RTB :
Private Sub RTB_txt_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RTB_txt.Click
'Modify the font and size of the selected word
SelectWord(Me.RTB_txt)
ChangeFormat(RTB_txt)
End Sub
Private Sub RTB_txt_MouseLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RTB_txt.MouseLeave
RTB_txt.DeselectAll()
End Sub
Private Sub BtnRegx_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles BtnRegx.Click
'each word is surrounded by span tag
RichTextBox2.Text = SpanWord2(RTB_txt).ToString
End Sub
At this step, It don't work....... because the test fails . I thought i
could test the font of each word but it seems to test only the first one.
Can we know the font property of each word of a string and test it in an
evaluator of the regex and then choose between two replacements?
thanks
pascal
I explain all the stuff because as I am not a programmer, I don't know if
the thing i would like are possible or engaged in the right way..........
Short summary of my goal: I try to make a small software to easily create
exercises like on my site here:
http://www.scalpa.info/fr_gram_vb1_clicmot.php
I do these exercises by hand now, by directly editing the javascript and
html file.
I'd like to build a small program that would generate this type of exercise
and bring an improvement for words which are written with the same letters
but have a different meaning (homograph?).
At this time, If I ask my students to find the verb in the following
sentence: "Les poules du couvent couvent." The verb "couvent"(incubate) and
the name "couvent" (a convent) is considered in the same way!
In my previous posts, I tried to understand a few things: select, deselect
one word in a RichTextBox to edit it using regex words etc.. And I thank
everybody for his help. People on This forum are efficient.
To distinguish words that I consider a good response from others, I thought:
1) identify them in a RichTextBox by clicking on each, applying special
format (fontsize, fonttype etc.).
2)Then using a regex that would test this format, and change it by a
particular tag.
Here is the code I Used :
Imports System.Text.RegularExpressions
Module Core
'ToDo créer une variable pour les séparateurs
Private chars As Char() = " ,.:;?!-'`".ToCharArray
Public Function SelectWord(ByVal RTBText As RichTextBox)
Dim LeMot As String = String.Empty
Dim cursorPosition As Integer = RTBText.SelectionStart
Dim nextSpace As Integer = RTBText.Text.IndexOfAny(chars,
cursorPosition)
Dim selectionStart As Integer = 0
Dim trimmedString As String = String.Empty
' Strip everything after the next space...
If nextSpace <> -1 Then
trimmedString = RTBText.Text.Substring(0, nextSpace)
Else
trimmedString = RTBText.Text
End If
If trimmedString.LastIndexOfAny(chars) <> -1 Then
selectionStart = 1 + trimmedString.LastIndexOfAny(chars)
trimmedString = trimmedString.Substring(1 +
trimmedString.LastIndexOfAny(chars))
End If
RTBText.SelectionStart = selectionStart
RTBText.SelectionLength = trimmedString.Length
Return LeMot
End Function
Public Function ChangeFormat(ByRef RTBText As RichTextBox)
If RTBText.SelectionFont.Name = ("Tahoma") And _
RTBText.SelectionFont.Size = "12" And _
RTBText.SelectionFont.Style = FontStyle.Bold And _
RTBText.SelectionColor = System.Drawing.Color.Red Then
RTBText.SelectionFont = New Font("Arial", 11, FontStyle.Regular)
RTBText.SelectionColor = System.Drawing.Color.Black
Else
RTBText.SelectionFont = New Font("Tahoma", 12, FontStyle.Bold)
RTBText.SelectionColor = System.Drawing.Color.Red
RTBText.AutoWordSelection = True
End If
Return RTBText
End Function
Public Function SpanWord2(ByVal Rtb As RichTextBox)
Dim input As String = Rtb.Text
Dim pattern As String = "([\w]+)(?=[\s '.,;!?«»\-(\)])"
'for words that are not a solution
Dim replacement As String = "<span class=""blue""
onclick=""verif(this)"">$1</span>"
'for solution words
Dim replacement2 As String = "<span id=""yes"" class=""blue""
onclick=""verif(this)"">$1</span>"
Dim rgx As New Regex(pattern)
Dim options As RegexOptions = RegexOptions.IgnoreCase
If Rtb.SelectionFont.Name = ("Tahoma") And _
Rtb.SelectionFont.Size = "12" And _
Rtb.SelectionFont.Style = FontStyle.Bold And _
Rtb.SelectionColor = System.Drawing.Color.Red Then
Dim result As String = rgx.Replace(input, replacement2)
Return result
Else
Dim result As String = rgx.Replace(input, replacement)
Return result
End If
End Function
End Module
Code for the form RTB :
Private Sub RTB_txt_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RTB_txt.Click
'Modify the font and size of the selected word
SelectWord(Me.RTB_txt)
ChangeFormat(RTB_txt)
End Sub
Private Sub RTB_txt_MouseLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RTB_txt.MouseLeave
RTB_txt.DeselectAll()
End Sub
Private Sub BtnRegx_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles BtnRegx.Click
'each word is surrounded by span tag
RichTextBox2.Text = SpanWord2(RTB_txt).ToString
End Sub
At this step, It don't work....... because the test fails . I thought i
could test the font of each word but it seems to test only the first one.
Can we know the font property of each word of a string and test it in an
evaluator of the regex and then choose between two replacements?
thanks
pascal
I explain all the stuff because as I am not a programmer, I don't know if
the thing i would like are possible or engaged in the right way..........