Visualizzazione dei risultati da 1 a 7 su 7

Discussione: [VB] HTML Highlighting

  1. #1

    [VB] HTML Highlighting

    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
    MA DI CHE PARLATE??

  2. #2
    Utente di HTML.it
    Registrato dal
    Jul 2001
    Messaggi
    798
    Devi utilizzare non la textbox ma la richtextbox, il componente lo aggiungi dalla voce componenti e lo trovi sotto la voce microsoft richtextbox.
    Ans.

  3. #3



    Ho provato a mettere un RichtextBox e il programma funziona, solo che non fa nessun highlighting. Non son capace nemmeno a fare un copy/paste :quipy:

    Puo' darsi che il codice sopra sia errato?

    E scusate. in breve che differenza passa tra textbox e richtexbox? Ho notato che sul richtextbox il tasto dx del mouse e' disabilitato...

    Grazie e ciao
    MA DI CHE PARLATE??

  4. #4
    uhm... se per te è lo stesso editor simili ce ne sono a iosa di già fatti...

    TextPad
    UltraEdit
    Vladislav III din Sighisoara,
    conte di domnitor al Valahiei
    denumit Tepes sau al Dracului


    ...ce tie nu-ti place altuia nu-i face...

  5. #5


    Grazie molte, ma il fatto è che sto cercando di capire come funziona VB e credo che il modo migliore per rompere il ghiaccio sia smanettarci sopra... volevo assemblare vari pezzi di codice per provare a fare un programma

    Ciao
    MA DI CHE PARLATE??

  6. #6

    EVVIVA!!

    Sono riuscito a farlo andare... credo mancassero delle variabili da dichiarare o qualcosa di simile


    Ciao
    MA DI CHE PARLATE??

  7. #7
    per piaciere, mi manderesti( webmaster@lucascript.net ) in uno .zip il .exe e i sorgenti se nn ti disturba??????

    Grazie per una tua eventuale risposta

    P.S: per i curiosi, è solo per vedere se il VB è na cazzata come dicono
    Se in un primo momento l'idea non è assurda, allora non c'è nessuna speranza che
    si realizzi
    .
    Os: WinME
    Lang: C++
    Editor: C++ Builder 6 Enterprise

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.