I am not that good in PB like you..
yes i see now when i do mistakes...
sorry if i bothering you with questions and also i have one more .
next exemple is also from forum and also not work because i get error about not valid
i looked again and again and cannot figured why is not valid..it is supose to highlite keywords from array??
or not ...
here is acode :
Code: Select all
Enumeration
#MainWindow
EndEnumeration
;Gadget enumeration.
Enumeration
#RichEdit
EndEnumeration
;Font enumeration
Enumeration
#FontEdit
EndEnumeration
;Declare constants.
#COLOR_Text = $000000 : #EFFECTS_Text = 0
#COLOR_Symbol = $ff0000 : #EFFECTS_Symbol = #CFE_ITALIC
#NbBasicKeywords = 126; ***NOT 64!
Dim validcharacters(126)
;Load fonts.
LoadFont(#FontEdit, "Times New Roman", 16)
;Declare procedures.
Declare HighlightLine(Line)
Declare InitSyntaxHighlightning()
Declare WindowCallback(hWnd, uMsg, wParam, lParam)
;- Open main window and display gadgets.
OpenWindow(#MainWindow,0,0,400,400,"EDitor", #PB_Window_Invisible | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget,1)
ShowWindow_(WindowID(#MainWindow), #SW_MAXIMIZE)
CreateGadgetList(WindowID(#MainWindow))
EditorGadget(#RichEdit,0,50,3*WindowWidth(#MainWindow)/4,WindowHeight(#MainWindow)-50)
;SetGadgetFont(#RichEdit, UseFont(#FontEdit))
SendMessage_(GadgetID(#RichEdit), #EM_SETBKGNDCOLOR, 0, $b6fcf8); Set background colour.
;Allow the trapping of the EN_CHANGE message which occurs after the contents of the editor gadget
;has changed.
SendMessage_(GadgetID(#RichEdit), #EM_SETEVENTMASK, 0, #ENM_CHANGE)
;ActivateGadget(#RichEdit)
;InitSyntaxHighlightning()
SetWindowCallback(@WindowCallback())
;Main message loop..
Repeat
EventID=WaitWindowEvent()
Until EventID = #WM_CLOSE
;- Highlight line
;The following procedure scans the given line of text in the richedit control looking for occurrences of
;the word "test". Such words are coloured and set to italic.
Procedure HighlightLine(Line)
Protected LineText.s, Format.CHARFORMAT, StartPos, Endpos, Left, Right, Flag.b
LineText = LCase(GetGadgetItemText(#RichEdit, Line,0))
;Get the character index's of both ends of the line.
StartPos = SendMessage_(GadgetID(#RichEdit),#EM_LINEINDEX, Line,0)
EndPos = StartPos + Len(LineText)
Format\cbSize = SizeOf(CHARFORMAT)
Format\dwMask = #CFM_COLOR | #CFM_BOLD | #CFM_ITALIC
Left = StartPos
Restore BasicKeywords
For a=1 To 126
Left = StartPos
Read.s inst$
Repeat
Right = FindString(LineText, inst$, Left-StartPos+1) + StartPos
If Right = StartPos;No occurrences found.
Left = EndPos
Else
;******
Left = Right-1 : Right + Len(inst$)-1
;******
check$=Mid(LineText,right+1,1)
Debug check$
If check$=" "
SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right);Highlight the word.
Left = Right
Format\crTextColor = #COLOR_Symbol : Format\dwEffects = #EFFECTS_Symbol
SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Left+1);Highlight the word.
Format\crTextColor = #COLOR_text : Format\dwEffects = #EFFECTS_text
SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
Else
left=right+1
Debug "yes"
EndIf
EndIf
Until Left = EndPos
ttt:
Next a
; Repeat
;Identify possible occurrences of "test".
; Right = FindString(LineText, "test", Left-StartPos+1) + StartPos
; If Right = StartPos;No occurrences found so colour entire line with the default text colour.
; Left = EndPos
; Else
; SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right-1)
; Format\crTextColor = #COLOR_Text : Format\dwEffects = #EFFECTS_Text
; SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
; Left = Right-1 : Right + 3
; SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right);Highlight the word "test"
; Left = Right
; Format\crTextColor = #COLOR_Symbol : Format\dwEffects = #EFFECTS_Symbol
; SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
; EndIf
; Until Left = EndPos
EndProcedure
;- window callback
;The following call back procedure is responsible for syntax highlighting etc.
;It does this by intercepting the #EN_CHANGE command message which fires whenever
;text in the rich edit control has changed. We then examine the entire line containing the text.
Procedure WindowCallback(hWnd, uMsg, wParam, lParam)
Protected ReturnValue, Chr.CHARRANGE, Line, CurrentStartPos
ReturnValue = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_COMMAND
If wParam >>16 = #EN_CHANGE And lparam = GadgetID(#RichEdit)
;The following returns the index (0-based) of the line containing the current character.
SendMessage_(GadgetID(#RichEdit),#EM_GETSEL,@CurrentStartPos, @Line)
Line = SendMessage_(GadgetID(#RichEdit),#EM_LINEFROMCHAR, CurrentStartPos,0)
SendMessage_(GadgetID(#RichEdit), #EM_HIDESELECTION, 1,0)
HighlightLine(Line)
If GetAsyncKeyState_(#VK_RETURN) & 1 = 1;Â Bit 0 is set if the enter key was pressed since the last check.
;Investigate the previous line.
HighlightLine(Line-1)
EndIf
SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, CurrentStartPos,CurrentStartPos); Return cursor to its correct position.
SendMessage_(GadgetID(#RichEdit),#EM_SETMODIFY,0,0)
SendMessage_(GadgetID(#RichEdit), #EM_HIDESELECTION, 0,0)
EndIf
EndSelect
ProcedureReturn(Returnvalue)
EndProcedure
Procedure InitSyntaxHighlightning()
; Build the ValidCharacter table to have have a faster routine to detect
; If the char is a considered as a string Or not. Nice improvement :)
For k='0' To '9'
ValidCharacters(k) = 1 ; i receive error here that is not valid ???
Next
For k='A' To 'Z'
ValidCharacters(k) = 1
Next
For k='a' To 'z'
ValidCharacters(k) = 1
Next
ValidCharacters('_') = 1
DataSection
BasicKeywords:
Data.s "And", "and"
Data.s "CallDebugger" , "calldebugger"
Data.s "Case" , "case"
Data.s "CompilerCase" , "compilercase"
Data.s "CompilerDefault" , "compilerdefault"
Data.s "CompilerElse" , "compilerelse"
Data.s "CompilerEndIf" , "compilerendif"
Data.s "CompilerEndSelect", "compilerendselect"
Data.s "CompilerIf" , "compilerif"
Data.s "CompilerSelect" , "compilerselect"
Data.s "Data" , "data"
Data.s "DataSection" , "datasection"
Data.s "Debug" , "debug"
Data.s "DebugLevel" , "debuglevel"
Data.s "Declare" , "declare"
Data.s "DeclareDLL" , "declaredll"
Data.s "Default" , "default"
Data.s "DefType" , "deftype"
Data.s "Dim" , "dim"
Data.s "DisableDebugger", "disabledebugger"
Data.s "Else" , "else"
Data.s "ElseIf" , "elseif"
Data.s "EnableDebugger", "enabledebugger"
Data.s "End" , "end"
Data.s "EndDataSection", "enddatasection"
Data.s "EndIf" , "endif"
Data.s "EndProcedure", "endprocedure"
Data.s "EndSelect" , "endselect"
Data.s "EndStructure", "endstructure"
Data.s "EndStructureUnion", "endstructureunion"
Data.s "FakeEndSelect", "fakeendselect"
Data.s "FakeReturn" , "fakereturn"
Data.s "For" , "for"
Data.s "ForEver" , "forever"
Data.s "Global", "global"
Data.s "Gosub", "gosub"
Data.s "Goto" , "goto"
Data.s "If", "if"
Data.s "IncludeBinary", "includebinary"
Data.s "IncludeFile", "includefile"
Data.s "IncludePath", "includepath"
Data.s "NewList", "newlist"
Data.s "Next", "next"
Data.s "Or", "or"
Data.s "Procedure" , "procedure"
Data.s "ProcedureDLL" , "proceduredll"
Data.s "ProcedureReturn", "procedurereturn"
Data.s "Protected" , "protected"
Data.s "Read", "read"
Data.s "Repeat", "repeat"
Data.s "Restore", "restore"
Data.s "Return", "return"
Data.s "Select", "select"
Data.s "Shared", "shared"
Data.s "Step", "step"
Data.s "Structure", "structure"
Data.s "StructureUnion", "structureunion"
Data.s "To", "to"
Data.s "Until", "until"
Data.s "Wend" , "wend"
Data.s "While", "while"
Data.s "XIncludeFile" , "xincludefile"
Data.s "XOr" , "xor"
EndDataSection
EndProcedure