Ciao a tutti
Ho cercato questo argomento sul forum ma non ho trovato nulla di significativo.
Sto cercando di fare un .exe con un campo di testo in cui l'utente possa semplicemente scrivere un testo e veder evidenziati i tag HTML.
Ho trovato su internet questo codice:
codice:Private Sub rtf1_Click() On Error Resume Next Dim tmptxt As String Dim regexTagname As RegExp, regexProp As RegExp Dim matches As MatchCollection Dim match As match ListView1.ListItems.Clear 'first, lets see if we are in a tag Dim OtagSP As Long Dim OtagLength As Long OtagSP = InStrRev(rtf1.Text, "<", rtf1.SelStart, vbTextCompare) If InStrRev(rtf1.Text, ">", rtf1.SelStart, vbTextCompare) > OtagSP Then ListView1.ListItems.Add , "tagname", "Text" ListView1.ListItems("tagname").ListSubItems.Add , "value", "No tag selected" Exit Sub End If OtagLength = InStr(rtf1.SelStart, rtf1.Text, ">", vbTextCompare) - OtagSP + 1 tmptxt = Mid(rtf1.Text, OtagSP, OtagLength) ' lets get the tag name real quick ' Regx to get tag name Set regexTagname = New RegExp regexTagname.Pattern = "[/]?\w[^ =<>]*" regexTagname.IgnoreCase = False regexTagname.Global = False Set matches = regexTagname.Execute(tmptxt) ' Execute search. ListView1.ListItems.Add , matches.Item(0), matches.Item(0) ' define regx to get tag name / attributes ' Regx to get properties/values Set regexProp = New RegExp regexProp.Pattern = "\s(\w[\w\d\s:_\-\.]*)\s*=\s*(""[^""]+""|'[^']+'|\d+)" regexProp.IgnoreCase = False regexProp.Global = True Set matches = regexProp.Execute(tmptxt) ' Execute search. For Each match In matches ' Iterate Matches collection. ListView1.ListItems.Add , match.SubMatches(0), match.SubMatches(0) ListView1.ListItems(match.SubMatches(0)).ListSubItems.Add , "value", match.SubMatches(1) Next End Sub Private Sub rtf1_KeyUp(KeyCode As Integer, Shift As Integer) On Error Resume Next If chkHighlight < 1 Then Exit Sub Debug.Print KeyCode & "shift=" & Shift 'If Shift > 0 Then Exit Sub Select Case KeyCode Case 188 ' < Case 190 '> Case 32 ' space Case 187 '= Case 222 ' " Case 49 '! Case Else Exit Sub End Select 'first, lets see if we are in a tag LockWindowUpdate rtf1.hWnd Dim OtagSP As Long Dim OtagLength As Long Dim ss As Long Dim sl As Long ss = rtf1.SelStart sl = rtf1.SelLength OtagSP = InStrRev(rtf1.Text, "<", rtf1.SelStart, vbTextCompare) OtagLength = InStr(rtf1.SelStart, rtf1.Text, ">", vbTextCompare) - OtagSP + 1 rtf1.SelStart = OtagSP - 1 rtf1.SelLength = OtagLength + 1 rtf1.SelRTF = colorhtml(rtf1.SelText) rtf1.SelStart = ss rtf1.SelLength = sl LockWindowUpdate False End Sub
Ho creato un form e ci ho messo un textbox che ho chiamato RichTextBox1, come credo sia necessario fare. Ho cliccato fuori dal textbox, sul form, e ho incollato esattamente il codice qui sopra.
Se lo provo però mi da errore, parla di funzioni non definite.
Premettendo che non sono alle prime armi, sto proprio alla fionda e alla cerbottana, qualcuno puo' spiegarmi il motivo?
Grazie
Ciao


Rispondi quotando


