
											'#####################################
											'												 '
											' A Rich edit control editor example '
											'             By Andy                '
											'                                    '
											'           Version 4.64             '
                                 '           Amendement 1             '
                                 '                                    '
											'          Beta 2 Edition            '
											'         9 November, 2020           '
											'                                    '
											'#####################################

' WARNING:- 
' This program is provided as-is without any guarantees of fitness of purpose either expressed or implied, 
' by using this program you accept this and use it completely at your own risk. 

' Before loading any of your files, make a copy!

' Screen resolution - 1366 x 768 or greater.
' The icons are kindly provided by Open Icon Library
' Please read the license file for more information.

$MAIN
$INCLUDE "xeditor.inc"
$USE "Comctl32.lib"

AUTODEFINE "off"
STRING ProgramTitle = " - The 2020 hindsight editor version - 4 . 64 - by Andy [ Beta 2 edition ]."
WINDOW wx
INT Console = 1		'Used by me for program tracing - not required.
IF Console = 1
   OPENCONSOLE
   PRINT
   print getstartpath
ENDIF

'############################
'                           '
'        Main section       '
'                           '
'############################

Load_Defaults()					'Load your default program preferences including key word colours etc.	
GetLineSpace()						'Get the line spacing based on your font name and size preference.
LoadIncludePath()					'Get the IWB include folder path so we can open standard include files if needed.
ReadKeyWords()						'Read in IWB key words and set their colours based on your preferences.
IndexKeyWords()					'Build key word indexes for fast searching.
LoadWindow()						'Load the main window (named w1).
DoInitialLoad()					'Load any files that were open when the program was last closed (if any).
ReSizeTabs()						'Resize tabs to fit the file names.
InitialLoadDisplay()				'Show any files that were open when the program was last closed (if any).
DisplayLastTab()              'Set tab to the one that was being viewed when program was last closed.
cLine++                       'Set current line variable.
WAITUNTIL ISWINDOWCLOSED(w1)  'Wait until the main window is closed.
Finish()								'Close down files, tidy up and exit the program.

'############################
'                           '
'      End of Program       '
'                           '
'############################

'----------------------------

'############################
'                           '
'    Main window handler    '
'                           '
'############################

SUB Main(),INT

SELECT @MESSAGE
	case @IDCREATE
		  Centerwindow w1

   'Vertical Scrollbar
	CASE @IDVSCROLL

        'Scroll started
        if @CODE = 5
           Scrolling = 1 
        endif

        'Scroll ended
        if @CODE = 8
           Scrolling = 0 
           print GETSCROLLPOS(w1,ScrollBar)
           if GETSCROLLPOS(w1,ScrollBar) = 0
              setcontroltext(w1,EDIT_1,ltrim$(str$(1)))
              SENDMESSAGE(rHandle,EM_SETSEL,0,0)
              setfocus w1,RichEdit
           else
              print GETSCROLLPOS(w1,ScrollBar),"          ",cLine
              setscrollpos(w1,ScrollBar,cLine) 
           endif
        endif

		  SELECT @CONTROLID
			  CASE ScrollBar 'Scrollbar
				    SELECT @CODE
					     CASE  @SBTHUMBTRACK
                          cLine = GETSCROLLPOS(w1,ScrollBar) '+ 1 'Change
                          StoreLine = cLine
                          setcontroltext(w1,EDIT_1,ltrim$(str$(cLine)))

					     CASE& @SBTHUMBPOS 		
							     SETSCROLLPOS w1,ScrollBar,@QUAL

						  case  @SBLINEUP
                          DoLineUp()

						  case  @SBLINEDOWN
								  stoptimer w1,MainTimer
							     int StoreFVL = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1
							     SENDMESSAGE(w1.hWnd,EM_SCROLL,SB_LINEDOWN,0,1)
							     setscrollpos(w1,ScrollBar,getscrollpos(w1,ScrollBar)+1)
							     Loading = 1
							     FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
							     for a = 1 to 30
								      setcontroltext(w1,a+1000,str$(FirstVisLine + a))
								      SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
							     next a

							     QuietMode(1)
							     for a = FirstVisLine to FirstVisLine + LinesPerPage
								      char_index = CONTROLCMD (w1,RichEdit,@RTCHARFROMLINE,a)
								      CONTROLCMD(w1,RichEdit,@RTGETLINE,a,#cp.ClipText,512)
								      ColourLineP(rHandle,a,char_index)
							     next a
							     QuietMode(0)
							     Loading = 0

                          StoreFVL = StoreFVL + (LinesPerPage)
							     Offset = CONTROLCMD (w1,RichEdit,@RTCHARFROMLINE,StoreFVL)
							     CONTROLCMD(w1,RichEdit,@RTGETLINE,StoreFVL,#cp.ClipText,512)

                          QuietMode(1)
							     ColourLineP(rHandle,StoreFVL,Offset)
                          SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset)
                          QuietMode(0)
                          starttimer w1,TimerSpeed,MainTimer 

								  Offset = CONTROLCMD (w1,RichEdit,@RTCHARFROMLINE,StoreFVL+1)
								  cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
								  StoreLine = cLine
							     setcontroltext(w1,1000 + LinesPerPage,"> " + getcontroltext(w1,1000 + LinesPerPage))
							     SETCONTROLCOLOR w1,1000 + LinesPerPage,Red,BackColour
                          setcontroltext(w1,LineNumberEdit,ltrim$(str$(cLine)))
                          return 0

						  case  @SBPAGEUP
								  setscrollpos(w1,ScrollBar,getscrollpos(w1,ScrollBar)-34)
                          ColourText()  
								  sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace
								  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)

						  case  @SBPAGEDOWN
								  setscrollpos(w1,ScrollBar,getscrollpos(w1,ScrollBar)+34)
                          ColourText()  
								  sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace
								  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)

				ENDSELECT
      endselect

		case @IDCLOSEWINDOW 
           DoCloseProgram()

      CASE @IDMENUPICK
           SELECT @MENUNUM
                  case 300 'Recent files
                       WindowRecentFiles()

                  case 201 'Cut
                       Cut()
                       return 0

                  case 202 'Copy
                       CopyStringToClipboard(CutLine)
                       return 0

                  case 203 'Paste
                       PasteKey = 1
                       Paste()
                       PasteKey = 0
                       Loading = 0
                       return 0

                  case 205 'Find first
                       setstate(w1,FindFirst,1)
                       setstate(w1,FindAll,0)
                       setstate(w1,FindLast,0)
                       DoFind()

                  case 230 'Find All
                       setstate(w1,FindFirst,0)
                       setstate(w1,FindAll,1)
                       setstate(w1,FindLast,0)
                       DoFind()

                  case 231 'Find Last
                       setstate(w1,FindFirst,0)
                       setstate(w1,FindAll,0)
                       setstate(w1,FindLast,1)
                       DoFind()

                  case 232 'Swap lines around
                       Cut()
                       system getstartpath + "Transpose.exe"

                  case 233
                       SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
                       CONTROLCMD w1,RichEdit,@RTGETSELTEXT,ClipText
                       ClipText = ltrim$(rtrim$(ClipText))
                       WindowCase(ClipText)

                  case 206 'Select All
                       RTSelectAll(w1,RichEdit)
                       CopyStringToClipboard(CutLine) 

                  case 209 'New file
							  Loading = 1
							  DoMinimiseAll()
							  ProgPath = getstartpath + "\Res\\Untitled.iwb"
							  DoOpen(1)
							  ProgPath = getstartpath + "Untitled.iwb"
							  string NewFileCaption = getcaption w1
							  setcaption w1,NewFileCaption + "*" + ProgramTitle
							  if OnTab = 1
								  setcontroltext(w1,FileTab1,"Untitled.iwb*")
							  endif
							  if OnTab = 2
								  setcontroltext(w1,FileTab2,"Untitled.iwb*")
							  endif
							  if OnTab = 3
								  setcontroltext(w1,FileTab3,"Untitled.iwb*")
							  endif
							  if OnTab = 4
								  setcontroltext(w1,FileTab4,"Untitled.iwb*")
							  endif
							  if OnTab = 5
								  setcontroltext(w1,FileTab5,"Untitled.iwb*")
							  endif
							  if OnTab = 6
								  setcontroltext(w1,FileTab6,"Untitled.iwb*")
							  endif
							  Loading = 0

                  case 210 'Open
							  Loading = 1
							  DoMinimiseAll()
							  DoOpen()
							  if NoNewFile = 1
								  NoNewFile = 0
								  if OnTab = 1
									  DoRestore(0,1)
								  endif  
								  if OnTab = 2
									  DoRestore(0,2)
								  endif 
								  if OnTab = 3
									  DoRestore(0,3)
								  endif 
								  if OnTab = 4
									  DoRestore(0,4)
								  endif 
								  if OnTab = 5
									  DoRestore(0,5)
								  endif 
								  if OnTab = 6
									  DoRestore(0,6)
								  endif 
							  endif
							  if Restoring = 1
								  Restoring = 0
							  endif
							  Loading = 0

                  case 211 'Close 
							  ClearEditor()
							  if OnTab = 1
								  buffer1 = ""
								  buffer1 = buffer2
								  buffer2 = ""
								  buffer2 = buffer3
								  buffer3 = ""
								  buffer3 = buffer4
								  buffer4 = ""
								  buffer4 = buffer5
								  buffer5 = ""
								  buffer5 = buffer6
								  buffer6 = ""
								  RecentProgs[1] = RecentProgs[2]
								  RecentProgs[2] = RecentProgs[3]
								  RecentProgs[3] = RecentProgs[4]
								  RecentProgs[4] = RecentProgs[5]
								  RecentProgs[5] = RecentProgs[6]
								  RecentProgs[6] = "" 
								  Tab6Loaded = 0
								  ProgCount = 5
								  ProgPath = RecentProgs[1]
								  GetFileName(w1,0,ProgPath,1)
								  setcontroltext(w1,FileTab1,FileNameIs)
								  setcontroltext(w1,FileTab2,getcontroltext(w1,FileTab3))
								  setcontroltext(w1,FileTab3,getcontroltext(w1,FileTab4))
								  setcontroltext(w1,FileTab4,getcontroltext(w1,FileTab5))
								  setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab6))
								  setcontroltext(w1,FileTab6,"")
								  showwindow w1,@SWHIDE,FileTab6
								  FileNameIs = getcontroltext(w1,FileTab1)
								  SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),BlueButton
								  SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
								  if getcontroltext(w1,FileTab1) <> ""
									  DoRestore(0,1)
								  else
									  OnTab = 0
									  TabTaken = 0
									  Tab1Loaded = 0
								  endif 
							  endif

							  if OnTab = 2
								  buffer2 = ""
								  buffer2 = buffer3
								  buffer3 = ""
								  buffer3 = buffer4
								  buffer4 = ""
								  buffer4 = buffer5
								  buffer5 = ""
								  buffer5 = buffer6
								  buffer6 = ""
								  RecentProgs[2] = RecentProgs[3]
								  RecentProgs[3] = RecentProgs[4]
								  RecentProgs[4] = RecentProgs[5]
								  RecentProgs[5] = RecentProgs[6]
								  RecentProgs[6] = "" 
								  Tab6Loaded = 0
								  ProgCount = 5
								  ProgPath = RecentProgs[2]
								  GetFileName(w1,0,ProgPath,1)
								  setcontroltext(w1,FileTab2,FileNameIs)
								  setcontroltext(w1,FileTab3,getcontroltext(w1,FileTab4))
								  setcontroltext(w1,FileTab4,getcontroltext(w1,FileTab5))
								  setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab6))
								  setcontroltext(w1,FileTab6,"")
								  showwindow w1,@SWHIDE,FileTab6
								  FileNameIs = getcontroltext(w1,FileTab2)
								  SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),BlueButton
								  SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
								  DoRestore(0,2)
							  endif

							  if OnTab = 3
								  buffer3 = ""
								  buffer3 = buffer4
								  buffer4 = ""
								  buffer4 = buffer5
								  buffer5 = ""
								  buffer5 = buffer6
								  buffer6 = ""
								  RecentProgs[3] = RecentProgs[4]
								  RecentProgs[4] = RecentProgs[5]
								  RecentProgs[5] = RecentProgs[6]
								  RecentProgs[6] = "" 
								  Tab6Loaded = 0
								  ProgCount = 5
								  ProgPath = RecentProgs[3]
								  GetFileName(w1,0,ProgPath,1)
								  setcontroltext(w1,FileTab3,FileNameIs)
								  setcontroltext(w1,FileTab4,getcontroltext(w1,FileTab5))
								  setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab5))
								  setcontroltext(w1,FileTab6,"")
								  showwindow w1,@SWHIDE,FileTab6
								  FileNameIs = getcontroltext(w1,FileTab3)
								  SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),BlueButton
								  SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
								  DoRestore(0,3)
							  endif

							  if OnTab = 4
								  buffer4 = ""
								  buffer4 = buffer5
								  buffer5 = ""
								  buffer5 = buffer6
								  buffer6 = ""
								  RecentProgs[4] = RecentProgs[5]
								  RecentProgs[5] = RecentProgs[6]
								  RecentProgs[6] = "" 
								  Tab6Loaded = 0
								  ProgCount = 5
								  ProgPath = RecentProgs[4]
								  GetFileName(w1,0,ProgPath,1)
								  setcontroltext(w1,FileTab4,FileNameIs)
								  setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab5))
								  setcontroltext(w1,FileTab6,"")
								  showwindow w1,@SWHIDE,FileTab6
								  FileNameIs = getcontroltext(w1,FileTab4)
								  SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),BlueButton
								  SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
								  DoRestore(0,4)
							  endif

							  if OnTab = 5
								  buffer5 = ""
								  buffer5 = buffer6
								  buffer6 = ""
								  RecentProgs[5] = RecentProgs[6]
								  RecentProgs[6] = "" 
								  Tab6Loaded = 0
								  ProgCount = 5
								  ProgPath = RecentProgs[5]
								  GetFileName(w1,0,ProgPath,1)
								  setcontroltext(w1,FileTab5,FileNameIs)
								  setcontroltext(w1,FileTab6,"")
								  showwindow w1,@SWHIDE,FileTab6
								  FileNameIs = getcontroltext(w1,FileTab5)
								  SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),BlueButton
								  SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
								  DoRestore(0,5)
							  endif

							  if OnTab = 6
								  OnTab = 5
								  buffer6 = ""
								  RecentProgs[6] = "" 
								  Tab6Loaded = 0
								  ProgCount = 5
								  ProgPath = RecentProgs[5]
								  GetFileName(w1,0,ProgPath,1)
								  setcontroltext(w1,FileTab5,FileNameIs)
								  setcontroltext(w1,FileTab6,"")
								  showwindow w1,@SWHIDE,FileTab6
								  FileNameIs = getcontroltext(w1,FileTab5)
								  SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),BlueButton
								  SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
								  SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
								  DoRestore(0,5)
							  endif

							  if getcontroltext(w1,FileTab1) <> ""
								  TabTaken = 1
							  else
								  Tab1Loaded = 0
							  endif

							  if getcontroltext(w1,FileTab2) <> ""
								  TabTaken = 2
							  else
								  Tab2Loaded = 0
							  endif

							  if getcontroltext(w1,FileTab3) <> ""
								  TabTaken = 3
							  else
								  Tab3Loaded = 0
							  endif

							  if getcontroltext(w1,FileTab4) <> ""
								  TabTaken = 4
							  else
								  Tab4Loaded = 0
							  endif

							  if getcontroltext(w1,FileTab5) <> ""
								  TabTaken = 5
							  else
								  Tab5Loaded = 0
							  endif

							  if getcontroltext(w1,FileTab5) <> ""
								  TabTaken = 5
							  else
								  Tab5Loaded = 0
							  endif

							  if getcontroltext(w1,FileTab6) <> ""
								  TabTaken = 6
							  else
								  Tab6Loaded = 0
							  endif

							  if RecentProgs[1] = ""
								  buffer1 = ""
								  Tab1Loaded = 0
								  TabTaken = 0
								  showwindow w1,@SWHIDE,FileTab1
							  endif

							  if RecentProgs[2] = ""
								  buffer2 = ""
								  TabTaken = 1
								  Tab2Loaded = 0
								  showwindow w1,@SWHIDE,FileTab2
							  endif

							  if RecentProgs[3] = ""
								  buffer3 = ""
								  TabTaken = 2
								  Tab3Loaded = 0
								  showwindow w1,@SWHIDE,FileTab3
							  endif

							  if RecentProgs[4] = ""
								  buffer4 = ""
								  TabTaken = 3
								  Tab4Loaded = 0
								  showwindow w1,@SWHIDE,FileTab4
							  endif

							  if RecentProgs[5] = ""
								  buffer5 = ""
								  TabTaken = 4
								  Tab5Loaded = 0
								  showwindow w1,@SWHIDE,FileTab5
							  endif

							  if RecentProgs[6] = ""
								  buffer6 = ""
								  TabTaken = 5
								  Tab6Loaded = 0
								  showwindow w1,@SWHIDE,FileTab6
							  endif

							  TabTaken = 0
						  
							  if openfile(MyFile2,getstartpath + "\\Res\\" + "xeditor4.ini","W") = 0
								  for a = 1 to ProgCount
									   if rtrim$(ltrim$(RecentProgs[a])) <> "" 
										   write MyFile2,RecentProgs[a]
										   TabTaken ++
										   if TabTaken = 1 then Tab1Loaded = 1
										   if TabTaken = 2 then Tab2Loaded = 1
										   if TabTaken = 3 then Tab3Loaded = 1
										   if TabTaken = 4 then Tab4Loaded = 1
										   if TabTaken = 5 then Tab5Loaded = 1
										   if TabTaken = 6 then Tab6Loaded = 1
									   endif
								  next a
                          write MyFile2,"!" + ltrim$(str$(OnTab))
								  closefile MyFile2
							  endif

							  ProgCount = TabTaken

							  if TabTaken = 1
								  LoadTab(1)
							  endif

							  if TabTaken = 2
								  LoadTab(2)
							  endif

							  if TabTaken = 3
								  LoadTab(3)
							  endif

							  if TabTaken = 4
								  LoadTab(4)
							  endif

							  if TabTaken = 5
								  LoadTab(5)
							  endif

                  case 212 'Save
							  if !instr(ProgPath,IncludePath)
								  DoSave()
							  else
								  ShowConfirm(-40)
							  endif

					   case 213 'Save as
							  SaveAsProc()

                  case 214 'Backup
							  BackupWindow()
							  if Confirm = 1
								  string StoreBookFileD = GETSTARTPATH() + "Backup\\" + BackupDesc
								  closefile MyFile2  
								  if openfile(MyFile2,StoreBookFileD,"W") = 0
									  buffer = ""
									  buffer = getcontroltext(w1,RichEdit)
									  write MyFile2,buffer 
								  endif
								  closefile MyFile2
							  endif

                  case 215 'Reindex
							  ShowConfirm(99)
							  DoRebuild()
							  ShowConfirm(-100)

                  case 216 'Editor Settings
                       showwindow w1,@SWMINIMIZED
                       EditorSettings()
                       GetLineSpace()
                       CreateLines()

                       if NoJumpRV = 1 then setstate w1,Check1,1
                       if NoJumpRV = 0 then setstate w1,Check1,0

							  Loading = 1
							  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
							  QuietMode(1)
							  ColourNow(w1,0,rHandle)
							  QuietMode(0)
							  Loading = 0
                       showwindow w1,@SWRESTORE
                       setfocus w1

                  case 240
                       system getstartpath + "\\Res\\2020-hindsight-editor.chm"

                  case 220 'Exit
                       DoCloseProgram()

           endselect 

           select @CODE
                  case 207 'Send to block
                       SendToBlock()

                  case 401 'Cut
                       Cut()
                       return 0 

                  case 402 'Copy
                       CopyStringToClipboard(CutLine)
                       return 0

                  case 403 'Paste
                       Paste()
                       return 0

                  case 404 'Select all
                       RTSelectAll(w1,RichEdit)
                       CopyStringToClipboard(CutLine) 

           endselect

      case @IDTIMER
			  select @CODE

					   case MainTimer
							  int lvcount2
							  string text2,text4
                       text2 = getcaption(w1)
                       if mid$(text2,1,1) = " " 
                          select OnTab
                                 case 1
                                      setcaption(w1,getcontroltext(w1,FileTab1) + ProgramTitle)
                                 case 2
                                      setcaption(w1,getcontroltext(w1,FileTab2) + ProgramTitle)
                                 case 3
                                      setcaption(w1,getcontroltext(w1,FileTab3) + ProgramTitle)
                                 case 4
                                      setcaption(w1,getcontroltext(w1,FileTab4) + ProgramTitle)
                                 case 5
                                      setcaption(w1,getcontroltext(w1,FileTab5) + ProgramTitle)
                                 case 6
                                      setcaption(w1,getcontroltext(w1,FileTab6) + ProgramTitle)
                          endselect
                       endif 
                       text2 = "" 

                       if getselected(w1,Combo2) = -1
                          ShowSubRoutineButtons(0)
                       else
                          ShowSubRoutineButtons(1)
                       endif
                       if getselected(w1,Combo4) = -1
                          ShowWindowButtons(0)
                       else
                          ShowWindowButtons(1)
                       endif
							  handle = GetFocus()
							  if handle = getcontrolhandle(w1,RichEdit)
									cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,-1) + 1
                           GetSelPos()

									if KeyUp = 1
										KeyUp = 0
										ScrollUpKey()
										cLine -= 1
										char_index = CONTROLCMD(w1,RichEdit,@RTCHARFROMLINE,cLine)
										SendMessage(getcontrolhandle(w1,RichEdit),EM_SETSEL,char_index,char_index)
										StoreLine = cLine
										return 0
									endif

									if StoreLine <> cLine 'Now on a different line
                              AdjustPos = 0
       
										if Loading = 0                       
										   Debug()
										endif

										StoreLine = cLine
                              setcontroltext(w1,LineNumberEdit,ltrim$(str$(cLine)))

										ttx = varStart 
										varEnd = varStart 
										showwindow w1,@SWHIDE,ListView
										setcontroltext(w1,KeyWordEdit,"")
										kw = 0
										DelFound = 0
										setcontroltext(w1,LinePosEdit,ltrim$(getcontroltext(w1,1029)))
										if AcrossX < 0 then AcrossX = 1
										setcontroltext(w1,LineCharEdit,ltrim$(str$(AcrossX)))
										setcontroltext(w1,nwPosEdit,ltrim$(str$(ttx)))
										setcontroltext(w1,EditPosEdit,ltrim$(str$(EditPos)))
									endif

									if AcrossX < 0 then AcrossX = 0
									if EditPos < 0 then EditPos = 0
									if MouseWheel = 1
										MouseWheel = 0
										cLine = val(ltrim$(getcontroltext(w1,1030)))
										StoreLine = cLine
										setcontroltext(w1,LinePosEdit,ltrim$(str$(cLine)))
										setcontroltext(w1,LineCharEdit,ltrim$(str$(AcrossX)))
										setcontroltext(w1,nwPosEdit,ltrim$(str$(ttx)))
										setcontroltext(w1,EditPosEdit,ltrim$(str$(EditPos)))
									endif
							  endif 

							  int OnLine = (sRange.Low / LineSpace) + 1
							  SENDMESSAGE(w1.hWnd,EM_GETSCROLLPOS,0,sRange,RichEdit)

							  if MouseWheel = 1
								  MouseWheel = 0
								  cLine = val(ltrim$(getcontroltext(w1,1030)))
								  StoreLine = cLine
								  setcontroltext(w1,LinePosEdit,ltrim$(str$(cLine)))
								  setcontroltext(w1,LineCharEdit,ltrim$(str$(AcrossX)))
								  setcontroltext(w1,nwPosEdit,ltrim$(str$(ttx)))
								  setcontroltext(w1,EditPosEdit,ltrim$(str$(EditPos)))
							  endif 
                       return 0

			  endselect   

		CASE @IDCONTROL
			  SELECT @CONTROLID
           case FindFirst
                if @NOTIFYCODE = 0
                   if getstate(w1,FindFirst)
                      setstate w1,FindAll,0
                      setstate w1,FindLast,0
                      setfocus w1
                   endif 
                endif

           case FindAll
                if @NOTIFYCODE = 0
                   if getstate(w1,FindAll)
                      setstate w1,FindFirst,0
                      setstate w1,FindLast,0
                      setfocus w1
                   endif 
                endif

           case FindLast
                if @NOTIFYCODE = 0
                   if getstate(w1,FindLast)
                      setstate w1,FindFirst,0
                      setstate w1,FindAll,0
                      setfocus w1
                   endif 
                endif

           case HandyControls
                if @NOTIFYCODE = 0
						 if iswindowclosed(w16)
							 WindowCase()
						 else  
							 if iswindowhidden(w16)
								 showwindow w16,@SWSHOW
							 else
								 showwindow w16,@SWHIDE
								 setfocus w1
							 endif 
						 endif
                endif

           case ExitButton
                if @NOTIFYCODE = 0
                   DoCloseProgram()
                endif

           case BinButton
                if @NOTIFYCODE = 0
                   WindowDelete(6)
                   if DelConfirm = 1
                      cls
							 Undo2Count[OnTab] = 0
							 Redo2Count[OnTab] = 0
                      ShowConfirm(-110)
                   endif
                endif

           case AutoButton
                if @NOTIFYCODE = 0
                   AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
                   if AutoCompleteKeyWords = 0
                      AutoCompleteStore = 0
                      SETCONTROLTEXT w1,AutoButton,GETSTARTPATH() + "\\Res\\SpellingOff.bmp"
                   else
                      AutoCompleteStore = 1 
                      SETCONTROLTEXT w1,AutoButton,GETSTARTPATH() + "\\Res\\SpellingOn.bmp"
                   endif
                endif  

           case TopButton
                if @NOTIFYCODE = 0
                   setcontroltext(w1,EDIT_1,"1")
                   setscrollpos(w1,ScrollBar,0)
                   JustColourScreen()
                   setcontroltext(w1,EDIT_1,ltrim$(str$(1)))
                endif

           case BottomButton
                if @NOTIFYCODE = 0
                   int BL = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT) - 1
                   cLine = BL + 1
                   setcontroltext(w1,EDIT_1,ltrim$(str$(cLine)))
						 sRange.Low = (cLine-10) * LineSpace
						 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                   JustColourScreen()
                   setscrollpos(w1,ScrollBar,cLine-10)
                endif

           case NewButton
                if @NOTIFYCODE = 0
                   NewFileProc()
                endif

           case OpenButton
                if @NOTIFYCODE = 0
                   OpenFileProc()
                endif

           case ReLoadButton
                if @NOTIFYCODE = 0

                   int EditPosWas = EditPos
						 int ScrollBackTo = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1
						 int Combo2Was = getselected(w1,Combo2)
						 int Combo4Was = getselected(w1,Combo4)
						 ClearEditor()
						 GetLines()
						 setcontroltext(w1,RichEdit,ClipText)
						 setcontroltext(w1,EDIT_1,ltrim$(str$(ScrollBackTo)))
                   if EditPosWas > 0
							 SENDMESSAGE(rHandle,EM_SETSEL,EditPosWas,EditPosWas)
							 setfocus w1,RichEdit
                   StoreLine = -1
                   endif

						 DoRebuild()

						 if Combo2Was > -1
							 setselected(w1,Combo2,Combo2Was)
						 endif
						 if Combo4Was > -1
							 setselected(w1,Combo4,Combo4Was)
						 endif

                   if iswindowclosed(w16) = 0
                      closewindow w16
                      WindowCase()
                   endif

                endif

           case CloseButton
                if @NOTIFYCODE = 0

						 Undo2Count[OnTab] = 0
						 Redo2Count[OnTab] = 0
                   SubDisplayed[OnTab] = -1
                   WinDisplayed[OnTab] = -1

                   conDrawOn(w1,RichEdit)

                   if getcontroltext(w1,FileTab1) = ""
							 if getcontroltext(w1,FileTab2) = ""
								 if getcontroltext(w1,FileTab3) = ""
									 if getcontroltext(w1,FileTab4) = ""
										 if getcontroltext(w1,FileTab5) = ""
											 if getcontroltext(w1,FileTab6) = ""
                                     setcontroltext(w1,RichEdit,"")
                                     OnTab = 0
                                     buffer1 = ""
                                     buffer2 = ""
                                     buffer3 = ""
                                     buffer4 = ""
                                     buffer5 = ""
                                     buffer6 = ""
												 conDrawOn(w1,RichEdit)
												 setcontroltext(w1,RichEdit,"")
												 showwindow w1,@SWHIDE,RichEdit
                                     HideFileButtons()
                                     return 0
                                  endif
                               endif
                            endif
                         endif
                      endif 
                   endif 

                   select OnTab 
                          case 1
										 if instr(getcontroltext(w1,FileTab1),"*")
											 CloseDown = OnTab
											 WindowDelete(0)
											 SaveAndCloseIt()
										 endif
                               
                          case 2
										 if instr(getcontroltext(w1,FileTab2),"*")
											 CloseDown = OnTab
											 WindowDelete(0)
											 SaveAndCloseIt()
										 endif
                          case 3
										 if instr(getcontroltext(w1,FileTab3),"*")
											 CloseDown = OnTab
											 WindowDelete(0)
											 SaveAndCloseIt()
										 endif

                          case 4
										 if instr(getcontroltext(w1,FileTab4),"*")
											 CloseDown = OnTab
											 WindowDelete(0)
											 SaveAndCloseIt()
										 endif
                          case 5
										 if instr(getcontroltext(w1,FileTab5),"*")
											 CloseDown = OnTab
											 WindowDelete(0)
											 SaveAndCloseIt()
										 endif
                          case 6
										 if instr(getcontroltext(w1,FileTab6),"*")
											 CloseDown = OnTab
											 WindowDelete(0)
											 SaveAndCloseIt()
										 endif
						 endselect

                   ClearEditor()

                   if OnTab = 1
                      buffer1 = ""
                      buffer1 = buffer2
                      buffer2 = ""
                      buffer2 = buffer3
                      buffer3 = ""
                      buffer3 = buffer4
                      buffer4 = ""
                      buffer4 = buffer5
                      buffer5 = ""
                      buffer5 = buffer6
                      buffer6 = ""
                      RecentProgs[1] = RecentProgs[2]
                      RecentProgs[2] = RecentProgs[3]
                      RecentProgs[3] = RecentProgs[4]
                      RecentProgs[4] = RecentProgs[5]
                      RecentProgs[5] = RecentProgs[6]
                      RecentProgs[6] = "" 
                      Tab6Loaded = 0
                      ProgCount = 5
                      ProgPath = RecentProgs[1]
                      GetFileName(w1,0,ProgPath,1)
                      setcontroltext(w1,FileTab1,getcontroltext(w1,FileTab2))
                      setcontroltext(w1,FileTab2,getcontroltext(w1,FileTab3))
                      setcontroltext(w1,FileTab3,getcontroltext(w1,FileTab4))
                      setcontroltext(w1,FileTab4,getcontroltext(w1,FileTab5))
                      setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab6))
                      setcontroltext(w1,FileTab6,"")
                      showwindow w1,@SWHIDE,FileTab6
                      FileNameIs = getcontroltext(w1,FileTab1)
                      setcaption w1,FileNameIs + ProgramTitle
							 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),BlueButton
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                      if getcontroltext(w1,FileTab1) <> ""
                         DoRestore(0,1)
                      else
                         OnTab = 0
                         TabTaken = 0
                         Tab1Loaded = 0
                      endif 
                   endif

                   if OnTab = 2
                      buffer2 = ""
                      buffer2 = buffer3
                      buffer3 = ""
                      buffer3 = buffer4
                      buffer4 = ""
                      buffer4 = buffer5
                      buffer5 = ""
                      buffer5 = buffer6
                      buffer6 = ""
                      RecentProgs[2] = RecentProgs[3]
                      RecentProgs[3] = RecentProgs[4]
                      RecentProgs[4] = RecentProgs[5]
                      RecentProgs[5] = RecentProgs[6]
                      RecentProgs[6] = "" 
                      Tab6Loaded = 0
                      ProgCount = 5


                      'if Buffer2 <> ""
								 ProgPath = RecentProgs[2]
								 GetFileName(w1,0,ProgPath,1)
								 setcontroltext(w1,FileTab2,getcontroltext(w1,FileTab3))
								 setcontroltext(w1,FileTab3,getcontroltext(w1,FileTab4))
								 setcontroltext(w1,FileTab4,getcontroltext(w1,FileTab5))
								 setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab6))
								 setcontroltext(w1,FileTab6,"")
								 showwindow w1,@SWHIDE,FileTab6
								 FileNameIs = getcontroltext(w1,FileTab2)

								 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),BlueButton
								 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
								 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
								 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
								 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
								 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                         DoRestore(0,2)
                      'endif 
                   endif

                   if OnTab = 3
                      buffer3 = ""
                      buffer3 = buffer4
                      buffer4 = ""
                      buffer4 = buffer5
                      buffer5 = ""
                      buffer5 = buffer6
                      buffer6 = ""
                      RecentProgs[3] = RecentProgs[4]
                      RecentProgs[4] = RecentProgs[5]
                      RecentProgs[5] = RecentProgs[6]
                      RecentProgs[6] = "" 
                      Tab6Loaded = 0
                      ProgCount = 5

                      'if Buffer3 <> ""
								 ProgPath = RecentProgs[3]
								 GetFileName(w1,0,ProgPath,1)
								 setcontroltext(w1,FileTab3,getcontroltext(w1,FileTab4))
								 setcontroltext(w1,FileTab4,getcontroltext(w1,FileTab5))
								 setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab6))
								 setcontroltext(w1,FileTab6,"")
								 showwindow w1,@SWHIDE,FileTab6
								 FileNameIs = getcontroltext(w1,FileTab3)
								 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),BlueButton
								 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
								 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
								 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
								 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
								 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                      DoRestore(0,3)
                      'endif
                   endif

                   if OnTab = 4
                      buffer4 = ""
                      buffer4 = buffer5
                      buffer5 = ""
                      buffer5 = buffer6
                      buffer6 = ""
                      RecentProgs[4] = RecentProgs[5]
                      RecentProgs[5] = RecentProgs[6]
                      RecentProgs[6] = "" 
                      Tab6Loaded = 0
                      ProgCount = 5
                      ProgPath = RecentProgs[4]
                      GetFileName(w1,0,ProgPath,1)
                      setcontroltext(w1,FileTab4,getcontroltext(w1,FileTab5))
                      setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab6))
                      setcontroltext(w1,FileTab6,"")
                      showwindow w1,@SWHIDE,FileTab6
                      FileNameIs = getcontroltext(w1,FileTab4)
							 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),BlueButton
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                      DoRestore(0,4)
                   endif

                   if OnTab = 5
                      buffer5 = ""
                      buffer5 = buffer6
                      buffer6 = ""
                      RecentProgs[5] = RecentProgs[6]
                      RecentProgs[6] = "" 
                      Tab6Loaded = 0
                      ProgCount = 5
                      ProgPath = RecentProgs[5]
                      GetFileName(w1,0,ProgPath,1)
                      setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab6))
                      setcontroltext(w1,FileTab6,"")
                      showwindow w1,@SWHIDE,FileTab6
                      FileNameIs = getcontroltext(w1,FileTab5)
							 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),BlueButton
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                      DoRestore(0,5)
                   endif

                   if OnTab = 6
                      OnTab = 5
                      buffer6 = ""
                      RecentProgs[6] = "" 
                      Tab6Loaded = 0
                      ProgCount = 5
                      ProgPath = RecentProgs[5]
                      GetFileName(w1,0,ProgPath,1)
                      setcontroltext(w1,FileTab5,FileNameIs)
                      setcontroltext(w1,FileTab6,"")
                      showwindow w1,@SWHIDE,FileTab6
                      FileNameIs = getcontroltext(w1,FileTab5)
							 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),BlueButton
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                      DoRestore(0,5)
                   endif

                   if getcontroltext(w1,FileTab1) <> ""
                      TabTaken = 1
                   else
                      Tab1Loaded = 0
                   endif

                   if getcontroltext(w1,FileTab2) <> ""
                      TabTaken = 2
                   else
                      Tab2Loaded = 0
                   endif

                   if getcontroltext(w1,FileTab3) <> ""
                      TabTaken = 3
                   else
                      Tab3Loaded = 0
                   endif

                   if getcontroltext(w1,FileTab4) <> ""
                      TabTaken = 4
                   else
                      Tab4Loaded = 0
                   endif

                   if getcontroltext(w1,FileTab5) <> ""
                      TabTaken = 5
                   else
                      Tab5Loaded = 0
                   endif

                   if getcontroltext(w1,FileTab5) <> ""
                      TabTaken = 5
                   else
                      Tab5Loaded = 0
                   endif

                   if getcontroltext(w1,FileTab6) <> ""
                      TabTaken = 6
                   else
                      Tab6Loaded = 0
                   endif

                   if RecentProgs[1] = ""
                      buffer1 = ""
                      Tab1Loaded = 0
                      TabTaken = 0
                      showwindow w1,@SWHIDE,FileTab1
                   endif

                   if RecentProgs[2] = ""
                      buffer2 = ""
                      TabTaken = 1
                      Tab2Loaded = 0
                      showwindow w1,@SWHIDE,FileTab2
                   endif

                   if RecentProgs[3] = ""
                      buffer3 = ""
                      TabTaken = 2
                      Tab3Loaded = 0
                      showwindow w1,@SWHIDE,FileTab3
                   endif

                   if RecentProgs[4] = ""
                      buffer4 = ""
                      TabTaken = 3
                      Tab4Loaded = 0
                      showwindow w1,@SWHIDE,FileTab4
                   endif

                   if RecentProgs[5] = ""
                      buffer5 = ""
                      TabTaken = 4
                      Tab5Loaded = 0
                      showwindow w1,@SWHIDE,FileTab5
                   endif

                   if RecentProgs[6] = ""
                      buffer6 = ""
                      TabTaken = 5
                      Tab6Loaded = 0
                      showwindow w1,@SWHIDE,FileTab6
                   endif

                   TabTaken = 0

					    if openfile(MyFile2,getstartpath + "\\Res\\" + "xeditor4.ini","W") = 0
						    for a = 1 to ProgCount
								  if rtrim$(ltrim$(RecentProgs[a])) <> "" 
									  write MyFile2,RecentProgs[a]
                             TabTaken ++
                             if TabTaken = 1 then Tab1Loaded = 1
                             if TabTaken = 2 then Tab2Loaded = 1
                             if TabTaken = 3 then Tab3Loaded = 1
                             if TabTaken = 4 then Tab4Loaded = 1
                             if TabTaken = 5 then Tab5Loaded = 1
                             if TabTaken = 6 then Tab6Loaded = 1
								  endif
						    next a
                      write MyFile2,"!" + ltrim$(str$(OnTab))
						    closefile MyFile2
					    endif

                   ProgCount = TabTaken

                   if ProgCount = 0
                      OnTab = 0
                      Tab1Loaded = 0
                      TabTaken = 0
                      buffer1 = ""
                      buffer2 = ""
                      buffer3 = ""
                      buffer4 = ""
                      buffer5 = ""
                      buffer6 = ""
                      RecentProgs[1] = ""
                      RecentProgs[2] = ""
                      RecentProgs[3] = ""
                      RecentProgs[4] = ""
                      RecentProgs[5] = ""
                      RecentProgs[6] = "" 
                      Tab6Loaded = 0
                      ProgCount = 0
                      ProgPath = ""
                      setcontroltext(w1,FileTab1,"")
                      setcontroltext(w1,FileTab2,"")
                      setcontroltext(w1,FileTab3,"")
                      setcontroltext(w1,FileTab4,"")
                      setcontroltext(w1,FileTab5,"")
                      setcontroltext(w1,FileTab6,"")
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour

                   endif 

						 if Tab1Loaded = 1 and getcontroltext(w1,FileTab1) = ""
							 Tab1Loaded = 0
							 TabTaken = 0
							 showwindow w1,@SWHIDE,FileTab1
						 endif

						 if Tab2Loaded = 1 and getcontroltext(w1,FileTab2) = ""
							 Tab2Loaded = 0
							 TabTaken = 1
							 showwindow w1,@SWHIDE,FileTab2
						 endif

						 if Tab3Loaded = 1 and getcontroltext(w1,FileTab3) = ""
							 Tab3Loaded = 0
							 TabTaken = 2
							 showwindow w1,@SWHIDE,FileTab3
						 endif

						 if Tab4Loaded = 1 and getcontroltext(w1,FileTab4) = ""
							 Tab4Loaded = 0
							 TabTaken = 3
							 showwindow w1,@SWHIDE,FileTab4
						 endif

						 if Tab5Loaded = 1 and getcontroltext(w1,FileTab5) = ""
							 Tab5Loaded = 0
							 TabTaken = 4
							 showwindow w1,@SWHIDE,FileTab5
						 endif

						 if Tab6Loaded = 1 and getcontroltext(w1,FileTab6) = ""
							 Tab6Loaded = 0
							 TabTaken = 5
							 showwindow w1,@SWHIDE,FileTab6
						 endif

                   if getcontroltext(w1,FileTab1) = ""
							 if getcontroltext(w1,FileTab2) = ""
								 if getcontroltext(w1,FileTab3) = ""
									 if getcontroltext(w1,FileTab4) = ""
										 if getcontroltext(w1,FileTab5) = ""
											 if getcontroltext(w1,FileTab6) = ""
                                     setcontroltext(w1,RichEdit,"")
                                     OnTab = 0
                                     buffer1 = ""
                                     buffer2 = ""
                                     buffer3 = ""
                                     buffer4 = ""
                                     buffer5 = ""
                                     buffer6 = ""
												 conDrawOn(w1,RichEdit)
												 setcontroltext(w1,RichEdit,"")
												 showwindow w1,@SWHIDE,RichEdit
                                     HideFileButtons()
                                     return 0
                                  endif
                               endif
                            endif
                         endif
                      endif 
                   endif

					    LoadTab(TabTaken)
                   ResizeTabs()
                   DoRebuild()

                endif

           case MinButton
                if @NOTIFYCODE = 0
                   if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4)) and !instr(getcaption(w1),getcontroltext(w1,FileTab5)) and !instr(getcaption(w1),getcontroltext(w1,FileTab6))
                      DoMinimise()
                   endif 
                endif

           case FileTab1
                if @NOTIFYCODE = 0
                   'if OnTab = 1 
                      'setfocus w1,RichEdit
                      'return 0
                   'endif 
                   showwindow w1,@SWHIDE,RichEdit
                   DisplayTab(1)  
                   setcaption w1,getcontroltext(w1,FileTab1) + ProgramTitle
                   showwindow w1,@SWSHOW,RichEdit
	                Loading = 1
						 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                   QuietMode(1)
						 ColourNow(w1,0,rHandle)
                   QuietMode(0)
                   Loading = 0
                endif

           case FileTab2
                if @NOTIFYCODE = 0
                   showwindow w1,@SWHIDE,RichEdit
                   DisplayTab(2)
                   setcaption w1,getcontroltext(w1,FileTab2) + ProgramTitle
                   showwindow w1,@SWSHOW,RichEdit
	                Loading = 1
						 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                   QuietMode(1)
						 ColourNow(w1,0,rHandle)
                   QuietMode(0)
                   Loading = 0
                endif

           case FileTab3
                if @NOTIFYCODE = 0
                   DisplayTab(3)
                   setcaption w1,getcontroltext(w1,FileTab3) + ProgramTitle
                   showwindow w1,@SWSHOW,RichEdit
	                Loading = 1
						 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                   QuietMode(1)
						 ColourNow(w1,0,rHandle)
                   QuietMode(0)
                   Loading = 0
                endif

           case FileTab4
                if @NOTIFYCODE = 0
                   DisplayTab(4)
                   setcaption w1,getcontroltext(w1,FileTab4) + ProgramTitle
                   showwindow w1,@SWSHOW,RichEdit
	                Loading = 1
						 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                   QuietMode(1)
						 ColourNow(w1,0,rHandle)
                   QuietMode(0)
                   Loading = 0
                endif

           case FileTab5
                if @NOTIFYCODE = 0
                   DisplayTab(5)
                   setcaption w1,getcontroltext(w1,FileTab5) + ProgramTitle
                   showwindow w1,@SWSHOW,RichEdit
	                Loading = 1
						 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                   QuietMode(1)
						 ColourNow(w1,0,rHandle)
                   QuietMode(0)
                   Loading = 0
                endif

           case FileTab6
                if @NOTIFYCODE = 0
                   DisplayTab(6)
                   setcaption w1,getcontroltext(w1,FileTab6) + ProgramTitle
                   showwindow w1,@SWSHOW,RichEdit
	                Loading = 1
						 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                   QuietMode(1)
						 ColourNow(w1,0,rHandle)
                   QuietMode(0)
                   Loading = 0
                endif

           case BackupButton
                if @NOTIFYCODE = 0
                   BackupWindow()
						 if Confirm = 1
							 StoreBookFileD = GETSTARTPATH() + "Backup\\" + BackupDesc
							 closefile MyFile2  
							 if openfile(MyFile2,StoreBookFileD,"W") = 0
								 buffer = ""
								 buffer = getcontroltext(w1,RichEdit)
								 write MyFile2,buffer 
							 endif
							 closefile MyFile2
						 endif
                endif

           case CogButton
                if @NOTIFYCODE = 0
                   cls 
                   ShowConfirm(99)
                   DoRebuild()
                   ShowConfirm(-100)
                endif

           case ColourButton
                if @NOTIFYCODE = 0
                   Loading = 1
						 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                   QuietMode(1)
						 ColourNow(w1,0,rHandle)
                   QuietMode(0)
                   Loading = 0
                endif

           case ConstantsButton
                if @NOTIFYCODE = 0
                   system getstartpath + "Constants\\constantssearchv6.exe" 
                endif 

			  case BeginsWith
					 if @NOTIFYCODE = 0
						 if getstate(w1,BeginsWith) = 1 then setstate(w1,InsUbName,0)
						 if getstate(w1,BeginsWith) = 0 then setstate(w1,InsUbName,1)
						 SendMessage(GetDlgItem(w1.hwnd,Combo12),CB_RESETCONTENT,0,0)
						 setcontroltext(w1,EDIT_2,getcontroltext(w1,EDIT_2))
						 setfocus w1,EDIT_2
						 AppendEdit(w1,EDIT_2,"",0)
				   endif

			  case InSubName
					 if @NOTIFYCODE = 0
						 if getstate(w1,InSubName) = 1 then setstate(w1,BeginsWith,0)
						 if getstate(w1,InSubName) = 0 then setstate(w1,BeginsWith,1)
						 SendMessage(GetDlgItem(w1.hwnd,Combo12),CB_RESETCONTENT,0,0)
						 setcontroltext(w1,EDIT_2,getcontroltext(w1,EDIT_2))
						 setfocus w1,EDIT_2
						 AppendEdit(w1,EDIT_2,"",0) 
					 endif

           case Combo12
                if @NOTIFYCODE = @CBNSELCHANGE
                   setcontroltext(w1,CodeWordEdit1,getstring(w1,Combo12,getselected(w1,Combo12)))
                   showwindow w1,@SWHIDE,ListView 
                endif

           case NavButton
                if @NOTIFYCODE = 0
                   DoAddNavigationPage()
                endif

           case NavBackButton
                if @NOTIFYCODE = 0
                   if NavMax = 0 then return 0
                   if NavPos = 1 
                      showwindow w1,@SWHIDE,NavBackButton
                      showwindow w1,@SWSHOW,NavBackGrey
                   endif
                   if NavPos = 0
                      NavPos = NavMax
                   else
                      NavPos --
                      if NavPos <= 1
                         NavPos = 1
                         showwindow w1,@SWHIDE,NavBackButton
                         showwindow w1,@SWSHOW,NavBackGrey
                      endif
                   endif 
                   setcontroltext(w1,EDIT_1,getstring(w1,Combo18,NavPos-1))
                   setselected(w1,Combo18,NavPos-1)
                   Offset = SendMessage(rHandle,EM_LINEINDEX,val(getstring(w1,Combo18,NavPos-1))-1,0)
                   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                   setfocus w1,RichEdit
                   if NavPos < NavMax
                      showwindow w1,@SWSHOW,NavForwardButton
                      showwindow w1,@SWHIDE,NavForwardGrey
                   endif
                endif

           case NavForwardButton
                if @NOTIFYCODE = 0
                   if NavMax = 0 then return 0
                   if NavPos = NavMax 
                      showwindow w1,@SWHIDE,NavForwardButton
                      showwindow w1,@SWSHOW,NavForwardGrey
                   endif
                   if NavPos = 0
                      NavPos = 1
                   else
                      NavPos ++
                      showwindow w1,@SWSHOW,NavBackButton
                      showwindow w1,@SWHIDE,NavBackGrey
                      if NavPos >= NavMax
                         NavPos = NavMax
                         showwindow w1,@SWHIDE,NavForwardButton
                         showwindow w1,@SWSHOW,NavForwardGrey
                      endif
                   endif 
                   setcontroltext(w1,EDIT_1,getstring(w1,Combo18,NavPos-1))
                   setselected(w1,Combo18,NavPos-1)
                   Offset = SendMessage(rHandle,EM_LINEINDEX,val(getstring(w1,Combo18,NavPos-1))-1,0)
                   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                   setfocus w1,RichEdit

                endif

           case SubSearchButton
                if @NOTIFYCODE = 0
                   WindowSubs()
                endif

           case NavDeleteButton
                if @NOTIFYCODE = 0
                   deletestring(w1,Combo18,getselected(w1,Combo18))
                   NavPos --
                   NavMax --
                   if NavPos < 0 then NavPos = 0
                   if NavMax < 0 then NavMax = 0
                   if getstringcount(w1,Combo18) > 0
						    showwindow w1,@SWSHOW,NavBackButton
						    showwindow w1,@SWHIDE,NavBackGrey
                   endif
                   if getstringcount(w1,Combo18) > 1
						    showwindow w1,@SWSHOW,NavForwardButton
						    showwindow w1,@SWHIDE,NavForwardGrey
                   endif
                endif

           case NavDeleteAllButton
                if @NOTIFYCODE = 0
						 showwindow w1,@SWHIDE,NavBackButton
						 showwindow w1,@SWHIDE,NavForwardButton
						 showwindow w1,@SWSHOW,NavBackGrey
						 showwindow w1,@SWSHOW,NavForwardGrey
                   SendMessage(GetDlgItem(w1.hwnd,Combo18),CB_RESETCONTENT,0,0)
                   NavPos = 0
                   NavMax = 0
                endif

           case Combo18
                if @NOTIFYCODE = @CBNSELCHANGE and DoingOpen = 0
                    if getstate(w1,RememberMe) = 1
                       DoAddNavigationPage(1)
                    endif
                    string NavString = getstring(w1,Combo18,getselected(w1,Combo18))
                    int NavLine = val(NavString)
                    setcontroltext(w1,EDIT_1,NavString)
						  Offset = SendMessage(rHandle,EM_LINEINDEX,NavLine-1,0)
						  SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                    setfocus w1,RichEdit
                    if getstate(w1,RememberMe) = 1
                       DoAddNavigationPage(1)
                    endif
                endif

           case DebugCheck
                if @NOTIFYCODE = 0
                   DebugOn = 1 - DebugOn
                   if DebugOn = 1
                      showwindow w1,@SWSHOW,Debug1
                      showwindow w1,@SWSHOW,Debug2
                      showwindow w1,@SWSHOW,Debug3
                      setsize w1,119,100,EndButtons-400,rcDepth,RichEdit
                      setsize w1,EndButtons-280,100,15,rcDepth,ScrollBar
                      setsize w1,EndButtons-280,80,15,15,TopButton
                      setsize w1,EndButtons-280,rcDepth+103,15,15,BottomButton
                   endif 
                   if DebugOn = 0
                      showwindow w1,@SWHIDE,Debug1
                      showwindow w1,@SWHIDE,Debug2
                      showwindow w1,@SWHIDE,Debug3
                      setsize w1,119,100,EndButtons-109,rcDepth,RichEdit
                      setsize w1,EndButtons+10,100,15,rcDepth,ScrollBar
                      setsize w1,1307,80,15,15,TopButton
                      setsize w1,1307,rcDepth+105,15,15,BottomButton
                   endif 
                   setfocus w1
                endif


           case CoorCheck
                if @NOTIFYCODE = 0
                   CoOn = 1 - CoOn
					    if CoOn = 1
						    showwindow w1,@SWSHOW,PosStatic
						    showwindow w1,@SWSHOW,PosEdit
						    showwindow w1,@SWSHOW,CharPosStatic
						    showwindow w1,@SWSHOW,CharPosEdit
						    setfocus w1
					    endif 
					    if CoOn = 0
						    showwindow w1,@SWHIDE,PosStatic
						    showwindow w1,@SWHIDE,PosEdit
						    showwindow w1,@SWHIDE,CharPosStatic
						    showwindow w1,@SWHIDE,CharPosEdit
						    setfocus w1
					    endif
                endif

           case SaveButton
                if @NOTIFYCODE = 0
				       if !instr(ProgPath,IncludePath)
                      select OnTab
                             Case 1
											 if instr(getcontroltext(w1,FileTab1),"*")
                                     ShowConfirm(-120)
												 RealTabName = getcontroltext(w1,FileTab1)
                                     RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 

												 for b1 = 1 to MaxTabs
													  GetFileName(w1,0,RecentProgs[b1],1)
													  if FileNameIs = RealTabName
														  ProgPath = RecentProgs[b1]
														  breakfor
													  endif
												 next b1

												 DoSave()

												 if instr(getcontroltext(w1,FileTab1),"*")
													 setcontroltext(w1,FileTab1,mid$(getcontroltext(w1,FileTab1),1,instr(getcontroltext(w1,FileTab1),"*")-1))
												 endif
											 endif

                             Case 2
											 if instr(getcontroltext(w1,FileTab2),"*")
                                     ShowConfirm(-120)
												 RealTabName = getcontroltext(w1,FileTab2)
												 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 

												 for b1 = 1 to MaxTabs
													  GetFileName(w1,0,RecentProgs[b1],1)
													  if FileNameIs = RealTabName
														  ProgPath = RecentProgs[b1]
														  breakfor
													  endif
												 next b1

												 DoSave()

												 if instr(getcontroltext(w1,FileTab2),"*")
													 setcontroltext(w1,FileTab2,mid$(getcontroltext(w1,FileTab2),1,instr(getcontroltext(w1,FileTab2),"*")-1))
												 endif
											 endif

                             Case 3
											 if instr(getcontroltext(w1,FileTab3),"*")
                                     ShowConfirm(-120)
												 RealTabName = getcontroltext(w1,FileTab3)
												 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 

												 for b1 = 1 to MaxTabs
													  GetFileName(w1,0,RecentProgs[b1],1)
													  if FileNameIs = RealTabName
														  ProgPath = RecentProgs[b1]
														  breakfor
													  endif
												 next b1

												 DoSave()

												 if instr(getcontroltext(w1,FileTab3),"*")
													setcontroltext(w1,FileTab3,mid$(getcontroltext(w1,FileTab3),1,instr(getcontroltext(w1,FileTab3),"*")-1))
												 endif
											 endif

                             Case 4
											 if instr(getcontroltext(w1,FileTab4),"*")
                                     ShowConfirm(-120)
												 RealTabName = getcontroltext(w1,FileTab4)
												 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 

												 for b1 = 1 to MaxTabs
													  GetFileName(w1,0,RecentProgs[b1],1)
													  if FileNameIs = RealTabName
														  ProgPath = RecentProgs[b1]
														  breakfor
													  endif
												 next b1

												 DoSave()

												 if instr(getcontroltext(w1,FileTab4),"*")
													setcontroltext(w1,FileTab4,mid$(getcontroltext(w1,FileTab4),1,instr(getcontroltext(w1,FileTab4),"*")-1))
												 endif
											 endif

                             Case 5
											 if instr(getcontroltext(w1,FileTab5),"*")
                                     ShowConfirm(-120)
												 RealTabName = getcontroltext(w1,FileTab5)
												 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 

												 for b1 = 1 to MaxTabs
													  GetFileName(w1,0,RecentProgs[b1],1)
													  if FileNameIs = RealTabName
														  ProgPath = RecentProgs[b1]
														  breakfor
													  endif
												 next b1

												 DoSave()

												 if instr(getcontroltext(w1,FileTab5),"*")
													setcontroltext(w1,FileTab5,mid$(getcontroltext(w1,FileTab5),1,instr(getcontroltext(w1,FileTab5),"*")-1))
												 endif
											 endif

                             Case 6
											 if instr(getcontroltext(w1,FileTab6),"*")
                                     ShowConfirm(-120)
												 RealTabName = getcontroltext(w1,FileTab6)
												 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 

												 for b1 = 1 to MaxTabs
													  GetFileName(w1,0,RecentProgs[b1],1)
													  if FileNameIs = RealTabName
														  ProgPath = RecentProgs[b1]
														  breakfor
													  endif
												 next b1

												 DoSave()

												 if instr(getcontroltext(w1,FileTab6),"*")
													setcontroltext(w1,FileTab6,mid$(getcontroltext(w1,FileTab6),1,instr(getcontroltext(w1,FileTab6),"*")-1))
												 endif
											 endif

                      endselect

                   else
                      ShowConfirm(-40)
                   endif
                endif

           case SaveAsButton
                if @NOTIFYCODE = 0
                   SaveAsProc()
                endif

           case CopySubButton 'Copy sub
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo2)) = -1 
                      ShowConfirm(-2)
                      setfocus w1,Combo2
                      return 0
                   endif
                   CutLine = ""
                   GetSub(w1,RichEdit)
                   ShowConfirm(1)
                endif

           case CopySubBlockButton 'Copy sub
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo2)) = -1 
                      ShowConfirm(-2)
                      setfocus w1,Combo2
                      return 0
                   endif
                   CutLine = ""
                   showwindow w1,@SWHIDE,RichEdit
                   GetSub(w1,RichEdit,1)
                   ShowConfirm(2)
                   if OnBlock = 1 then FocusBlock1()
                   if OnBlock = 2 then FocusBlock2()
                   if OnBlock = 3 then FocusBlock3()
                   if OnBlock = 4 then FocusBlock4()
                   return 0
                endif

           case MoveSubButton 'Move sub
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo2)) = -1 
                      ShowConfirm(-2)
                      setfocus w1,Combo2
                      return 0
                   endif

						  for a = 1 to 30
							  string WhichLine = Getcontroltext(w1,a+1000)
                       if instr(WhichLine,">")
                          WhichLine = mid$(WhichLine,instr(WhichLine," ")+1,len(WhichLine))
                          textVV = val(WhichLine)
                       endif 
						  next a

                   'Copy sub to clipboard
                   CutLine = ""
                   GetSub(w1,RichEdit,1)

                   'Delete sub
                   RemoveSub(w1,ListView2,Combo2)

                   'Paste sub to new location
					    Loading = 1

					    DoPasteSub()
					    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)

                   QuietMode(1)
					    ColourNow(w1,1,rHandle)
                   QuietMode(0)

					    SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]+1,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]+1)
					    setfocus w1,RichEdit
					    Loading = 0

                   'Delete block code
                   'DeleteBlock()

                   'Rebuild indexes
                   'DoRebuild()

                endif

           case MoveWinButton 'Move window
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo4)) = -1 
                      ShowConfirm(-4)
                      setfocus w1,Combo4
                      return 0
                   endif

                   MoveToPosition = cLine

                   CutLine = "" 'Copy sub
                   GetSubToFile(w1,ListView4,1)
                   RemoveSub(w1,ListView4,Combo4,1)

						 int char_index1 = CONTROLCMD (w1,RichEdit,@RTCHARFROMLINE,MoveToPosition-1)
						 CONTROLCMD w1,RichEdit,@RTSETSELECTION,char_index1,char_index1
					 	 SetLines()

						 BlockIn = GETSTARTPATH() + "\\Res\\xtemp.txt"
						 int count = ReadBlock(BlockIn)

						 CopyStringToClipBoard(CutLine)

					    ReadClipBoard()
					    StorecLine = MoveToPosition

					    CONTROLCMD w1,RichEdit,@RTPASTE

					    rHandle = getcontrolhandle(w1,RichEdit)

                   QuietMode(1)

						 CommentBlockStart = 0
						 CommentBlockEnd = 0

					    for a = MoveToPosition-1 to MoveToPosition + (count-1)
							  char_index = CONTROLCMD (w1,RichEdit,@RTCHARFROMLINE,a-1)
							  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.ClipText,512)
							  ColourLineP(rHandle,a-1,char_index)
					    next a

                   BlockCommentCheck()

                   QuietMode(0)
					    ShowCursor(TRUE)

					    lvcount2 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
					    ADDSTRING w1,Combo4,StoreSubName
					    lvcount2 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
					    for a = 0 to lvcount2 - 1
							  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text)
							  if ucase$(StoreSubName) = ucase$(text)
								  CONTROLCMD(w1,ListView4,@LVSETTEXT,a,1,ltrim$(str$(MoveToPosition)))
								  CONTROLCMD w1,ListView4,@LVSETTEXT,a,2,ltrim$(str$((MoveToPosition + count) - 1))
								  breakfor
							  endif
					    next a 
							
					    MoveBlocks(cLine,LineCount-1,1,2687)

                   setselected(w1,Combo4,-1)

                endif

           case ShowWindowButton 'Window details
                if @NOTIFYCODE = 0
                   if iswindowclosed(w8) = 0
                      closewindow w8
                   endif
                   WindowDetails(4)
                endif

           case ClearWins 'Clear Win selection
                if @NOTIFYCODE = 0
                   setselected(w1,Combo4,-1)
                   ShowWindowButtons(0)
                endif 

           case ShowSubButton 'Sub details
                if @NOTIFYCODE = 0
                   if iswindowclosed(w8) = 0
                      closewindow w8
                   endif
                   WindowDetails(2)
                endif

           case ClearSubs 'Clear Sub selection
                if @NOTIFYCODE = 0
                   setselected(w1,Combo2,-1)
                   ShowSubroutineButtons(0)
                endif 

           case DeleteSubButton 'Remove sub
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo2)) = -1 
                      ShowConfirm(-2)
                      setfocus w1,Combo2
                      int NewRangeDel = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
                      SETSCROLLRANGE w1,ScrollBar,0,NewRangeDel
                      return 0
                   endif
                   if ConfirmMessage = 0 
                      StarTabs()
                      RemoveSub(w1,ListView2,Combo2)
                      DelConfirm = 0
                      NewRangeDel = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
                      SETSCROLLRANGE w1,ScrollBar,0,NewRangeDel
                      return 0 
                   endif
                   WindowDelete(2)
                   if DelConfirm = 1
                      StarTabs()
                      RemoveSub(w1,ListView2,Combo2)
                   endif
                   DelConfirm = 0
                   NewRangeDel = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
                   SETSCROLLRANGE w1,ScrollBar,0,NewRangeDel
						 setcontroltext(w1,EDIT_1,ltrim$(str$(SaveSubDelete)))
						 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
						 SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset)
                   SETSCROLLPOS w1,ScrollBar,cLine 'Set croll pos for redo delete sub.
						 setfocus w1,RichEdit
                   return 0

                endif

           case CopyWinButton 'Copy window
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo4)) = -1 
                      ShowConfirm(-4)
                      setfocus w1,Combo4
                      return 0
                   endif
                   CutLine = ""
                   GetWindowE(w1,1)
                   ShowConfirm(1)
                endif

           case CopyWinBlockButton 'Copy window
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo4)) = -1 
                      ShowConfirm(-4)
                      setfocus w1,Combo4
                      return 0
                   endif
                   CutLine = ""
                   GetWindowE(w1,1,1)
                   ShowConfirm(2)
                   if OnBlock = 1 then FocusBlock1()
                   if OnBlock = 2 then FocusBlock2()
                   if OnBlock = 3 then FocusBlock3()
                   if OnBlock = 4 then FocusBlock4()
                endif

           case DeleteWinButton 'Remove window
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo4)) = -1 
                      ShowConfirm(-4)
                      setfocus w1,Combo4
                      return 0
                   endif
                   WindowDelete(4)
                   if DelConfirm = 1
                      RemoveWindow(w1,1)
                   endif
                   DelConfirm = 0
                   NewRangeDel = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
                   SETSCROLLRANGE w1,ScrollBar,0,NewRangeDel
                endif

           case CopyBlockButton
                if @NOTIFYCODE = 0
                   select OnBlock 
                          case 1
										 CutLine = ""
										 CutLine = getcontroltext(w1,TextBlock1)
										 CopyStringToClipboard(CutLine)  
                          case 2
										 CutLine = ""
										 CutLine = getcontroltext(w1,TextBlock2)
										 CopyStringToClipboard(CutLine) 
                          case 3
										 CutLine = ""
										 CutLine = getcontroltext(w1,TextBlock3)
										 CopyStringToClipboard(CutLine) 
                          case 4
										 CutLine = ""
										 CutLine = getcontroltext(w1,TextBlock4)
										 CopyStringToClipboard(CutLine) 
                   endselect 
                endif

           case DeleteBlockButton
                if @NOTIFYCODE = 0
                   DeleteBlock()
                endif

           case ShowCode
                if @NOTIFYCODE = 0
                   FocusMain()
                endif

           case ShowBlock1
                if @NOTIFYCODE = 0
                   FocusBlock1()
                endif

           case ShowBlock2
                if @NOTIFYCODE = 0
                   FocusBlock2()
                endif

           case ShowBlock3
                if @NOTIFYCODE = 0
                   FocusBlock3()
                endif

           case ShowBlock4
                if @NOTIFYCODE = 0
                   FocusBlock4()
                endif

           case BookAdd
                if @NOTIFYCODE = 0
						 handle = GetFocus()
						 int NoLineClicked = 1
						 string StringLineNo = ""
						 for a = 1 to LinesPerPage
							  StringLineNo = getcontroltext(w1,a+1000)
							  if instr(StringLineNo,">")
								  NoLineClicked = 0
								  breakfor
							  endif
						 next a
						 if NoLineClicked = 1
							 ShowConfirm(-66)
						 return 0
						 endif

                   int DupBookMark = 0
                   for b = 0 to getstringcount(w1,Combo6) - 1
                       string BookString = getstring(w1,Combo6,b)
                       string BookLineNumber = BookString
                       if instr(BookLineNumber," ")
                          BookLineNumber = mid$(BookLineNumber,1,instr(BookLineNumber," ")-1)
                       endif
                       if BookLineNumber = ltrim$(str$(cLine))
                          DupBookMark = 1
                          breakfor
                       endif
                   next b

                   if DupBookMark = 0 
                      StringLineNo = rtrim$(ltrim$(mid$(StringLineNo,instr(StringLineNo,">")+1,len(StringLineNo))))
                      cLine = val(StringLineNo)
                      BookmarkWindow() 'Optional description text
                      lvcountIn = CONTROLCMD(w1,ListView6,@LVGETCOUNT)
					       CONTROLCMD w1,ListView6,@LVINSERTITEM,lvcountIn+1,StringLineNo
					       CONTROLCMD w1,ListView6,@LVSETTEXT,lvcountIn+1,1,BookMarkDesc
                      insertstring w1,Combo6,lvcountIn,StringLineNo + " " + BookMarkDesc
                      ShowConfirm(6)
                   else
                      ShowConfirm(66)
                   endif 
                   BookMarkDesc = ""
                endif
 
           case BookDel
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo6)) = -1 
                      ShowConfirm(-6)
                      setfocus w1,Combo6
                      return 0
                   endif
						 deletestring(w1,Combo6,getselected(w1,Combo6))
						 setselected w1,Combo6,-1
                endif  

           case BookDelAll
                if @NOTIFYCODE = 0
                   SendMessage(GetDlgItem(w1.hwnd,Combo6),CB_RESETCONTENT,0,0)
                   CONTROLCMD(w1,ListView6,@LVDELETEALL)
						 setselected w1,Combo6,-1
                endif 

           case Combo6
                if @NOTIFYCODE = @CBNSELCHANGE and DoingOpen = 0
                   if AutoJumpTo = 1
                      string Combo6String = getstring(w1,Combo6,getselected(w1,Combo6))
                      if instr(Combo6String," ")
                         setcontroltext(w1,EDIT_1,mid$(Combo6String,1,instr(Combo6String," ")-1))
							    Offset = SendMessage(rHandle,EM_LINEINDEX,val(mid$(Combo6String,1,instr(Combo6String," ")-1))-1,0)
							    SendMessage(rHandle,EM_SETSEL,Offset,Offset)
							    setfocus w1,RichEdit
							    return 0
                      else
                         setcontroltext(w1,EDIT_1,Combo6String)
							    Offset = SendMessage(rHandle,EM_LINEINDEX,val(Combo6String)-1,0)
							    SendMessage(rHandle,EM_SETSEL,Offset,Offset)
							    setfocus w1,RichEdit
							    return 0
                      endif
                   endif
                endif

           case Combo8
                if @NOTIFYCODE = @CBNSELCHANGE and DoingOpen = 0
                   DoCombo8()
                endif

           case SelectJump
                if @NOTIFYCODE = 0
                   if getselected(w1,Combo8) = -1 then return 0
                   setcontroltext(w1,EDIT_1,TextIn1)
                   Combo10Add()
                   setfocus w1
                endif

           case SelectEnd
                if @NOTIFYCODE = 0
                   if getselected(w1,Combo8) = -1 then return 0
                   setcontroltext(w1,EDIT_1,TextIn2)
                endif

           case Combo10
                if @NOTIFYCODE = @CBNSELCHANGE and DoingOpen = 0
                   if AutoJumpTo = 1
                      goto AutoJumpCombo10
                   endif
                endif

           case CaseJump
                if @NOTIFYCODE = 0
                   label AutoJumpCombo10
                   if getselected(w1,Combo10) = -1 then return 0
                   string lv10String = getstring(w1,Combo10,getselected(w1,Combo10))
					    CONTROLCMD(w1,ListView10,@LVGETTEXT,getselected(w1,Combo10),0,TextInName)
				       CONTROLCMD(w1,ListView10,@LVGETTEXT,getselected(w1,Combo10),1,TextIn1)
                   setcontroltext(w1,EDIT_1,TextIn1)
                endif 
              
           case EDIT_2 'Search key words
                if @NOTIFYCODE = @ENENTERKEY
                   if getcontroltext(w1,EDIT_2) = ""
                      setfocus w1,EDIT_2
                      return 0
                   endif
                   Loading = 1
                   setcontroltext(w1,CodePhraseEdit,getstring(w1,Combo12,getselected(w1,Combo12)))
                   showwindow w1,@SWHIDE,ListView
                   if iswindowclosed(w4) = 0 then closewindow w4
                   CodePhraseWordsV  = 1
                   CodePhraseV       = 0
                   setstate w1,CodePhrase,CodePhraseV 
                   setstate w1,CodePhraseWords,CodePhraseWordsV
                   setcontroltext(w1,CodePhraseStatic,"Find words")
                   showwindow w1,@SWSHOW,CodeWordAnd
                   showwindow w1,@SWSHOW,CodeWordOr
                   if iswindowclosed(w6) = 0 then closewindow w6
                   WindowSearchPhrase()

                   Loading = 0
						 setcontroltext(w1,EDIT_1,ltrim$(str$(cLine)))
						 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
						 SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset)
						 setfocus w1,RichEdit
                endif 
                if @NOTIFYCODE = @ENCHANGE
                   SendMessage(GetDlgItem(w1.hwnd, Combo12),CB_RESETCONTENT,0,0)
					    for a = 1 to 1661
                       if getstate(w1,InSubName)
								  if instr(#p[a].words,ucase$(getcontroltext(w1,EDIT_2)))
									  addstring(w1,Combo12,#p[a].words) 
								  endif
                       endif
							  if getstate(w1,BeginsWith)
								  int InLine = len(getcontroltext(w1,EDIT_2))
								  if mid$(#p[a].words,1,InLine) = ucase$(getcontroltext(w1,EDIT_2))
									  addstring(w1,Combo12,#p[a].words)
								  endif
							  endif
					    next a
                   setselected(w1,Combo12,0)
                   int Combo12Count
                   string Combo12String 
                endif 

           case KeyFind
                if @NOTIFYCODE = 0
                   if getcontroltext(w1,EDIT_2) = ""
                      setfocus w1,EDIT_2
                      return 0
                   endif

                   Loading = 1
                   setcontroltext(w1,CodePhraseEdit,getstring(w1,Combo12,getselected(w1,Combo12)))
                   showwindow w1,@SWHIDE,ListView
                   CodePhraseWordsV  = 1
                   CodePhraseV       = 0
                   setstate w1,CodePhrase,CodePhraseV 
                   setstate w1,CodePhraseWords,CodePhraseWordsV
                   setcontroltext(w1,CodePhraseStatic,"Find words")
                   showwindow w1,@SWSHOW,CodeWordAnd
                   showwindow w1,@SWSHOW,CodeWordOr
                   if iswindowclosed(w6) = 0 then closewindow w6
                   WindowSearchPhrase()

                   Loading = 0
						 setcontroltext(w1,EDIT_1,ltrim$(str$(cLine)))
						 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
						 SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset)
						 setfocus w1,RichEdit
                endif

           case KeyDelete
                if @NOTIFYCODE = 0
                   closewindow w2
                   SendMessage(GetDlgItem(w1.hwnd,Combo12),CB_RESETCONTENT,0,0)
                   setcontroltext(w1,EDIT_2,"")
                   setfocus w1,EDIT_2
                endif

           case ListViewResult
					 if @NOTIFYCODE=@NMCLICK 
                   label ClickListViewResult
						 lvpos=*<NMLISTVIEW>@LPARAM.iItem
						 CONTROLCMD(w1,ListViewResult,@LVGETTEXT,lvpos,0,text)
						 setcontroltext(w1,EDIT_1,text)
					 endif

           case ListView10
					 if @NOTIFYCODE=@NMCLICK and AutoJumpTo = 1
						 lvpos=*<NMLISTVIEW>@LPARAM.iItem
						 CONTROLCMD(w1,ListView10,@LVGETTEXT,lvpos,1,text)
						 setcontroltext(w1,EDIT_1,text)
					 endif

           case CaseStatic
                if @NOTIFYCODE = 0
                   if iswindowclosed(w16) = 0
                      closewindow w16
                   endif
                   WindowCase() 
                endif

           case EDIT_4 'Search cases
                if @NOTIFYCODE = @ENENTERKEY
                   goto DoCaseFind
                endif

                if @NOTIFYCODE = @ENCHANGE
                   Combo12Count = getstringcount(w1,Combo10)
                   for a = 0 to Combo12Count - 1
                       Combo12String = ucase$(getstring(w1,Combo10,a))
                       if instr(Combo12String,ucase$(getcontroltext(w1,EDIT_4)))
								  setselected(w1,Combo10,a)
								  breakfor
                       endif
                   next a
                endif 

           case CaseFind 'Search cases (generic)
                if @NOTIFYCODE = 0
                   label DoCaseFind
                   SendMessage(GetDlgItem(w1.hwnd,Combo14),CB_RESETCONTENT,0,0)
                   Combo12Count = getstringcount(w1,Combo10)
                   for a = 0 to Combo12Count - 1
                       Combo12String = getstring(w1,Combo10,a)
                       if instr(ucase$(Combo12String),ucase$(getcontroltext(w1,EDIT_4)))
                          addstring(w1,Combo14,Combo12String) '+ " - " + ltrim$(str$(a))) 
                       endif
                   next a
                   setselected(w1,Combo14,0)
                   setcontroltext(w1,CaseFindStatic,"(" + ltrim$(str$(getstringcount(w1,Combo14))) + ")")
                endif 

           case Combo14
                if @NOTIFYCODE = @CBNSELCHANGE
                   string Combo14String = getstring(w1,Combo14,getselected(w1,Combo14))
					    lvcountIn = CONTROLCMD(w1,ListView10,@LVGETCOUNT)
					    for a = 0 to lvcountIn - 1
							  CONTROLCMD(w1,ListView10,@LVGETTEXT,a,0,text)
                       if text = Combo14String
                          text4 = ""
							     CONTROLCMD(w1,ListView10,@LVGETTEXT,a,1,text4)
                          setselected (w1,Combo10,a)
                          breakfor
                       endif
                   next a
                endif

           case CaseDelete
                if @NOTIFYCODE = 0
                   setcontroltext(w1,EDIT_4,"")
                   setcontroltext(w1,CaseFindStatic,"")
                   SendMessage(GetDlgItem(w1.hwnd,Combo14),CB_RESETCONTENT,0,0)
                   setfocus w1,EDIT_4
                endif 

           case Combo16
                if @NOTIFYCODE = @CBNSELCHANGE and DoingOpen = 0
                   DoSelect16()
                endif

           case CodeWordAnd
                if @NOTIFYCODE = 0
                   if getstate(w1,CodeWordAnd) = 1
							 AndV = 1
							 OrV  = 0
							 setstate w1,CodeWordOr,0 
                   else
							 AndV = 0
							 OrV  = 1
							 setstate w1,CodeWordOr,1
                   endif
                   setfocus w1 
                endif 

           case CodeWordOr
                if @NOTIFYCODE = 0
                   if getstate(w1,CodeWordOr) = 1
							 AndV = 0
							 OrV  = 1
							 setstate w1,CodeWordAnd,0 
                   else
							 AndV = 1
							 OrV  = 0
							 setstate w1,CodeWordAnd,1
                   endif
                   setfocus w1 
                endif 

           case CodeWordEdit1
                if @NOTIFYCODE = @ENCHANGE and Loading = 0
                   if len(getcontroltext(w1,CodeWordEdit1)) < len(NewEdit)
                      NewEdit = getcontroltext(w1,CodeWordEdit1)
                   endif  
                   int Spaces = 0
                   int SpacePos = 0
                   string WordsToLookup = getcontroltext(w1,CodeWordEdit1)
                   a = 0
                   if instr(WordsToLookup," ") <> 0
                      do 
                        a ++ 
                        if mid$(WordsToLookup,a,1) = " "
                           SpacePos = a
                        endif 
                      until instr(WordsToLookup," ") = 0 or a = len(WordsToLookup)
                   endif
						 if SpacePos = 0
							 Search_And_Highlight(getcontroltext(w1,CodeWordEdit1),2)
						 else
							 Search_And_Highlight(mid$(WordsToLookup,SpacePos + 1,len(WordsToLookup)),2)
						 endif

                   if len(getcontroltext(w1,CodeWordEdit2)) = 0 or len(getcontroltext(w1,CodeWordEdit1)) = 0
                      enablecontrol w1,CodeWordAnd,0
                      enablecontrol w1,CodeWordOr,0
                   else
                      enablecontrol w1,CodeWordAnd,1
                      enablecontrol w1,CodeWordOr,1
                   endif 
                endif

                if @NOTIFYCODE = @ENENTERKEY
                   showwindow w1,@SWHIDE,ListView
                   if (getcontroltext(w1,CodeWordEdit1)) = "" 
                      return 0
                   endif
						 WordsToLookup = mid$(WordsToLookup,1,SpacePos+1)
						 setcontroltext(w1,CodeWordEdit1,InfoA)
						 AppendEdit(w1,CodeWordEdit1,"",0)   
                   showwindow w1,@SWHIDE,ListView
                endif

           case CodePhraseEdit
                if @NOTIFYCODE = @ENCHANGE and Loading = 0
                   string ThePhrase = getcontroltext(w1,CodePhraseEdit)
                   for a = ePos to 1 step -1
                       if mid$(ThePhrase,a,1) = " "
                          SpacePosX = a + 1
                          breakfor
                       endif
                   next a

                   if a = 1
                      SpacePosX = 0
                   endif

                   Rlen = (ePos - SpacePosX) + 1
                   WordToLookUp = mid$(ThePhrase,SpacePosX,Rlen)

						 if SpacePosX = 0
							 WordToLookUp = mid$(getcontroltext(w1,CodePhraseEdit),0,ePos)
						 else
							 WordToLookUp = mid$(getcontroltext(w1,CodePhraseEdit),(ePos-Rlen)+1,(ePos+Rlen))
						 endif

						 WordToLookUp = ltrim$(rtrim$(WordTOLookUp))
						 if instr(WordToLookUp," ")
							 WordToLookUp = mid$(WordToLookUp,1,instr(WordToLookUp," ")-1) 
						 endif

						 if len(WordToLookUp) >= 2
							 Loading = 0
							 Search_And_Highlight(WordToLookUp,1)
						 endif

                   if getcontroltext(w1,CodePhraseEdit) = ""
                      ClearSearchPhrase()
                   endif

                endif

                if @NOTIFYCODE = @ENENTERKEY
						 if SpacePosX = 0
							 SENDMESSAGE(getcontrolhandle(w1,CodePhraseEdit),EM_SETSEL,0,ePos)
						 else
							 SENDMESSAGE(getcontrolhandle(w1,CodePhraseEdit),EM_SETSEL,(ePos-Rlen)-1,ePos)
						 endif

                   showwindow w1,@SWHIDE,ListView
                   if (getcontroltext(w1,CodePhraseEdit)) = "" 
                      Loading = 0
                      InfoA = ""
                      WordToLookup = ""
                      SpacePosX = 0
                      showwindow w1,@SWHIDE,ListView
                      setfocus w1,CodePhraseEdit
                      return 0
                   endif
                   Loading = 1
                   CONTROLCMD w1,CodePhraseEdit,@RTDELETESEL 
                   SENDMESSAGE(getcontrolhandle(w1,CodePhraseEdit),EM_SETSEL,(ePos-Rlen)-1,(ePos-Rlen)-1)
                   CONTROLCMD w1,CodePhraseEdit,@RTREPLACESEL,InfoA + " "
                   Loading = 0
                   InfoA = ""
                   WordToLookup = ""
                   SpacePosX = 0
                   showwindow w1,@SWHIDE,ListView
                endif

           case CodePhrase
                if @NOTIFYCODE = 0
                   Loading = 1
                   CodePhraseWordsV  = 0
                   CodePhraseV       = 1
                   setstate w1,CodePhrase,CodePhraseV 
                   setstate w1,CodePhraseWords,CodePhraseWordsV
                   AppendEdit(w1,CodePhraseEdit,"",0)
                   setcontroltext(w1,CodePhraseStatic,"Find exact")
                   showwindow w1,@SWSHOW,MaxWordsStatic
                   showwindow w1,@SWHIDE,CodeWordAnd
                   showwindow w1,@SWHIDE,CodeWordOr
                   setfocus w1,CodePhraseEdit 
                   showwindow w1,@SWHIDE,ListView 
                   Loading = 0
                endif

           case CodePhraseWords
                if @NOTIFYCODE = 0
                   ClearSearchPhrase()
                endif 

           case PhraseDeleteButton
                if @NOTIFYCODE = 0
                   NewEdit = ""
                   setcontroltext(w1,CodePhraseEdit,"") 
                   showwindow w1,@SWHIDE,ListView
                   if iswindowclosed(w6) = 0
                      closewindow w6
                   endif
                   setfocus w1,CodePhraseEdit 
                endif
 
           case CodePhraseSearch
                if @NOTIFYCODE = 0
                   showwindow w1,@SWHIDE,ListView
                   if (getcontroltext(w1,CodePhraseEdit)) = "" 
                      setfocus w1,CodePhraseEdit
                      return 0
                   endif
                   if iswindowclosed(w6) = 0
                      closewindow w6
                   endif
                   WindowSearchPhrase()
                endif

           case BookJump
                if @NOTIFYCODE = 0
						 if getselected(w1,Combo6) = -1 
							 ShowConfirm(-6)
							 setfocus w1,Combo6
							 return 0
						 endif
                   BookLineNumber = getstring(w1,Combo6,getselected(w1,Combo6))
                   if instr(BookLineNumber," ")
                      BookLineNumber = mid$(BookLineNumber,1,instr(BookLineNumber," ")-1)
                   endif
                   setcontroltext(w1,EDIT_1,BookLineNumber)
                   Offset = SendMessage(rHandle,EM_LINEINDEX,val(BookLineNumber)-1,0)
                   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                   setfocus w1,RichEdit
						 return 0
                endif

           case Check1
                if @NOTIFYCODE = 0
                   AutoJumpTo = 1 - AutoJumpTo
                   setfocus w1
                endif

           case Combo2
                if @NOTIFYCODE = @CBNSELCHANGE and DoingOpen = 0
                    if getstate(w1,RememberMe) = 1
                       DoAddNavigationPage(1)
                    endif
                    lv2Selected = getselected(w1,Combo2)
                    ShowSubroutineButtons(1)
                    if AutoJumpTo = 1
							  stoptimer w1,MainTimer
							  int ComboPos = getselected(w1,Combo2)
                       string ComboJump = ""
                       string ComboName = getstring(w1,Combo2,getselected(w1,Combo2))
                       for a = 0 to getstringcount(w1,Combo2)-1
                           CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,ComboJump)
                           if ucase$(ComboName) = ucase$(ComboJump)
							         CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
                              breakfor
                           endif
                       next a 
							  StoreLine = val(text)
							  setscrollpos(w1,ScrollBar,StoreLine)
							  cLine = val(text)
							  sRange.Low = (getscrollpos(w1,ScrollBar) * LineSpace) - LineSpace
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
							  rHandle = getcontrolhandle(w1,RichEdit)
							  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

							  for a = 1 to 30
									setcontroltext(w1,a+1000,str$(FirstVisLine+(a-1)))
							  next a

                       QuietMode(1)
							  ColourNow(w1,1,rHandle)
                       QuietMode(0) 

							  StoreLine = val(text)
							  setscrollpos(w1,ScrollBar,StoreLine)
							  cLine = val(text)
							  sRange.Low = (getscrollpos(w1,ScrollBar) * LineSpace) - LineSpace
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
							  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

							  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
							  SETCONTROLCOLOR w1,1001,Red,BackColour
							  setcontroltext(w1,LinePosEdit,ltrim$(str$(cLine)))
							  setcontroltext(w1,LineCharEdit,ltrim$(str$(AcrossX)))
							  setcontroltext(w1,nwPosEdit,ltrim$(str$(ttx)))
							  setcontroltext(w1,EditPosEdit,ltrim$(str$(EditPos)))
                       ResetScroll()
							  starttimer w1,TimerSpeed1,MainTimer
							  Offset = SendMessage(rHandle,EM_LINEINDEX,val(text)-1,0)
							  SendMessage(rHandle,EM_SETSEL,Offset,Offset)
							  setfocus w1,RichEdit
                       if getstate(w1,RememberMe) = 1
                          DoAddNavigationPage(1)
                       endif
							  return 0
                    endif
                endif

           case SubJump
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo2)) = -1 
                      ShowConfirm(-2)
                      setfocus w1,Combo2
                      return 0
                   endif
                   if getstate(w1,RememberMe) = 1
                      DoAddNavigationPage(1)
                   endif
						 stoptimer w1,MainTimer
                   conDrawOn(w1,Combo2)
                   conDrawOn(w1,ListView2) 
						 ComboPos = getselected(w1,Combo2)
						 CONTROLCMD(w1,ListView2,@LVGETTEXT,ComboPos,0,text2)
						 CONTROLCMD(w1,ListView2,@LVGETTEXT,ComboPos,1,text)
						 ComboJump = ""
						 ComboName = getstring(w1,Combo2,getselected(w1,Combo2))
						 lvcount2 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
						 for a = 0 to lvcount2-1
							  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,ComboJump)
							  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
							  if ucase$(ComboName) = ucase$(ComboJump)
								  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text2)
								  breakfor
							  endif
						 next a 
                   StoreLine = val(text) - 1
                   cLine = val(text) - 1
                   setcontroltext(w1,EDIT_1,ltrim$(text))
						 starttimer w1,TimerSpeed1,MainTimer
                   Offset = SendMessage(rHandle,EM_LINEINDEX,val(text)-1,0)
                   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                   setfocus w1,RichEdit
                   if getstate(w1,RememberMe) = 1
                      DoAddNavigationPage(1)
                   endif
						 return 0
                endif

           case EndSubb
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo2)) = -1 
                      ShowConfirm(-2)
                      setfocus w1,Combo2
                      return 0
                   endif
                   if getstate(w1,RememberMe) = 1
                      DoAddNavigationPage(1)
                   endif
						 stoptimer w1,MainTimer
						 ComboName = getstring(w1,Combo2,getselected(w1,Combo2))
						 lvcount2 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
						 for a = 0 to lvcount2
							  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,ComboJump)
							  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
							  if ucase$(ComboName) = ucase$(ComboJump)
								  breakfor
							  endif
						 next a 

                   EndSubFound = 0

                   int CodeEnd = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
                   for a = val(text) to CodeEnd
                       CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512) 
                       DoGetEndSubZ(a+1,Line$,1)
                       if EndSubFound = 1
                          breakfor
                       endif
                   next a
                   if EndSubFound = 1
                      EndSubFound = 0
                      int EndSubLine = a + 1
							 StoreLine = EndSubLine
							 cLine = EndSubLine
							 setcontroltext(w1,EDIT_1,ltrim$(str$(EndSubLine)))
							 starttimer w1,TimerSpeed1,MainTimer
							 Offset = SendMessage(rHandle,EM_LINEINDEX,EndSubLine-1,0)
							 SendMessage(rHandle,EM_SETSEL,Offset,Offset)
							 setfocus w1,RichEdit
                      CONTROLCMD(w1,ListView2,@LVGETTEXT,ComboPos,0,text2)
							 int PositionZ = CONTROLCMD(w1,ListView2,@LVFINDITEM,text2)
                      if PositionZ > -1
							    CONTROLCMD w1,ListView2,@LVSETTEXT,PositionZ,2,LTRIM$(STR$(EndSubLine))
                      endif
                      SETSCROLLPOS(w1,ScrollBar,EndSubLine)
							 sRange.Low = (EndSubLine-1) * LineSpace
							 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                      if getstate(w1,RememberMe) = 1
                         DoAddNavigationPage(1)
                      endif
                      return 0 
                   else 
						    return 0
                   endif
                endif

           case Combo4
                if @NOTIFYCODE = @CBNSELCHANGE and DoingOpen = 0
                    if getstate(w1,RememberMe) = 1
                       DoAddNavigationPage(1)
                    endif
                    ShowWindowButtons(1)
                    if AutoJumpTo = 1
							  stoptimer w1,MainTimer
							  ComboPos = getselected(w1,Combo4)
							  CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,1,text)
							  StoreLine = val(text)
							  setscrollpos(w1,ScrollBar,StoreLine)
							  cLine = val(text)
							  sRange.Low = (getscrollpos(w1,ScrollBar) * LineSpace) - LineSpace
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
							  rHandle = getcontrolhandle(w1,RichEdit)
							  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

							  for a = 1 to 35
									setcontroltext(w1,a+1000,str$(FirstVisLine+(a-1)))
							  next a
 
                       QuietMode(1)
							  ColourNow(w1,1,rHandle)
                       QuietMode(0)

							  StoreLine = val(text)
							  setscrollpos(w1,ScrollBar,StoreLine)
							  cLine = val(text)
							  sRange.Low = (getscrollpos(w1,ScrollBar) * LineSpace) - LineSpace
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
							  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1
							  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
							  SETCONTROLCOLOR w1,1001,Red,BackColour
						     setcontroltext(w1,LinePosEdit,ltrim$(str$(cLine)))
							  setcontroltext(w1,LineCharEdit,ltrim$(str$(AcrossX)))
							  setcontroltext(w1,nwPosEdit,ltrim$(str$(ttx)))
							  setcontroltext(w1,EditPosEdit,ltrim$(str$(EditPos)))
                       ResetScroll()
							  starttimer w1,TimerSpeed1,MainTimer
                       Offset = SendMessage(rHandle,EM_LINEINDEX,val(text)-1,0)
                       SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                       setfocus w1,RichEdit
                       if getstate(w1,RememberMe) = 1
                          DoAddNavigationPage(1)
                       endif
						     return 0
                    endif
                endif

           case WinJump
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo4)) = -1 
                      ShowConfirm(-4)
                      setfocus w1,Combo4
                      return 0
                   endif
                   if getstate(w1,RememberMe) = 1
                      DoAddNavigationPage(1)
                   endif
						 stoptimer w1,MainTimer
						 ComboPos = getselected(w1,Combo4)
						 CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,1,text)
						 ComboJump = ""
						 ComboName = getstring(w1,Combo4,getselected(w1,Combo4))
						 lvcount2 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
						 for a = 0 to lvcount2
							  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,ComboJump)
							  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text)
							  if ucase$(ComboName) = ucase$(ComboJump)
								  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text)
								  breakfor
							  endif
						 next a 
                   StoreLine = val(text) - 1
                   cLine = val(text) - 1
                   setcontroltext(w1,EDIT_1,ltrim$(text))
						 starttimer w1,TimerSpeed1,MainTimer
                   Offset = SendMessage(rHandle,EM_LINEINDEX,val(text)-1,0)
                   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                   setfocus w1,RichEdit
                   if getstate(w1,RememberMe) = 1
                      DoAddNavigationPage(1)
                   endif
						 return 0
                endif

           case EndWin
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo4)) = -1 
                      ShowConfirm(-4)
                      setfocus w1,Combo4
                      return 0
                   endif
                   if getstate(w1,RememberMe) = 1
                      DoAddNavigationPage(1)
                   endif
						 stoptimer w1,MainTimer

						 ComboName = getstring(w1,Combo4,getselected(w1,Combo4))
						 lvcount2 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
						 for a = 0 to lvcount2
							  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,ComboJump)
							  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text)
							  if ucase$(ComboName) = ucase$(ComboJump)
								  breakfor
							  endif
						 next a 

                   EndWinFound = 0

                   CodeEnd = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
                   for a = val(text) to CodeEnd
                       CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512) 
                       DoGetEndWinZ(a,Line$,1)
                       if EndWinFound = 1
                          breakfor
                       endif
                   next a
                   if EndWinFound = 1
                      EndWinFound = 0
                      int EndWinLine = a + 1
							 StoreLine = EndWinLine
							 cLine = EndWinLine
							 setcontroltext(w1,EDIT_1,ltrim$(str$(EndWinLine)))
							 starttimer w1,TimerSpeed1,MainTimer
							 Offset = SendMessage(rHandle,EM_LINEINDEX,EndWinLine-1,0)
							 SendMessage(rHandle,EM_SETSEL,Offset,Offset)
							 setfocus w1,RichEdit
                      CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,0,text2)
							 PositionZ = CONTROLCMD(w1,ListView4,@LVFINDITEM,text2)
                      if PositionZ > -1
							    CONTROLCMD w1,ListView4,@LVSETTEXT,PositionZ,2,LTRIM$(STR$(EndWinLine))
                      endif
                      SETSCROLLPOS(w1,ScrollBar,EndWinLine)
							 sRange.Low = (EndWinLine-1) * LineSpace
							 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                      if getstate(w1,RememberMe) = 1
                         DoAddNavigationPage(1)
                      endif
                      return 0 
                   else 
						    return 0
                   endif
                endif

           case WinHandler
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo4)) = -1 
                      ShowConfirm(-4)
                      setfocus w1,Combo4
                      return 0
                   endif
                   if getstate(w1,RememberMe) = 1
                      DoAddNavigationPage(1)
                   endif
						 stoptimer w1,MainTimer
						 ComboPos = getselected(w1,Combo4)
						 CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,1,text2)
                   int WinLine = val(text2)
                   CONTROLCMD(w1,RichEdit,@RTGETLINE,WinLine-1,line$,512)
                   DoGetEndHandlerZ(line$,1)
						 lvcount2 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
						 for a = 0 to lvcount2
							  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text2)
							  if ucase$(text2) = ucase$(#w[1].aWord)
								  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
								  CONTROLCMD(w1,ListView2,@LVSETTEXT,a,3,#w[1].aWord)
								  breakfor
							  endif
						 next a 
                   StoreLine = val(text) - 1
                   cLine = val(text) - 1
                   setcontroltext(w1,EDIT_1,ltrim$(text))
						 starttimer w1,TimerSpeed1,MainTimer
                   Offset = SendMessage(rHandle,EM_LINEINDEX,val(text)-1,0)
                   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                   setfocus w1,RichEdit
                   if getstate(w1,RememberMe) = 1
                      DoAddNavigationPage(1)
                   endif
						 return 0
                endif 

           case KeyWordEdit 'Keyword edit box
                if Loading = 0
						 CONTROLCMD w1,KeyWordEdit,@EDGETSELECTION,xStart,xEnd
                endif

           case 4
                if @NOTIFYCODE = @ENCHANGE and Loading = 0 
                NoUpdate = 1
                NoUpdate = 0
                endif 

       endselect 

       SELECT @CONTROLID

           case LineNumberEdit
                if @NOTIFYCODE = @ENCHANGE
						 for a = 1 to LinesPerPage
							  string lnec = ltrim$(Getcontroltext(w1,a+1000))
							  if instr(lnec,">")
								  lnec = mid$(lnec,instr(lnec,">")+2)
								  lnec = rtrim$(ltrim$(lnec))
							  endif
							  setcontroltext(w1,a+1000,lnec)
							  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
							  if lnec = getcontroltext(w1,LineNumberEdit)
								  setcontroltext(w1,a+1000,"> " + getcontroltext(w1,a+1000))
								  SETCONTROLCOLOR w1,a+1000,Red,BackColour
								  cLine = val(lnec)
							  endif 
						 next a
                endif
  
           case Combo1 'Block words
                if @NOTIFYCODE = @CBNSELCHANGE
						 if AutoJumpTo = 1
							 InsertPoint = cLine
							 sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace
							 BlockIn = getstring(w1,Combo1,getselected(w1,Combo1))
							 BlockIn = getstartpath + "\\Res\\" + BlockIn 
							 count = ReadBlock(BlockIn)
							 CopyStringToClipBoard(CutLine)
							 DoPaste()
                      int srMin,srMax
                      getscrollrange(w1,ScrollBar,srMin,srMax)
                      SETSCROLLRANGE w1,ScrollBar,0,srMax + count
						 endif
                endif

           case BlockJumpButton
                if @NOTIFYCODE = 0
						 if getselected(w1,Combo1) = -1 
							 ShowConfirm(-1)
							 setfocus w1,Combo1
							 return 0
						 endif

                   NoLineClicked = 1
                   StringLineNo = ""
                   FOR a = 1 TO LinesPerPage
                       StringLineNo = GETCONTROLTEXT(w1,a+1000)
                       IF INSTR(StringLineNo,">")
                          NoLineClicked = 0
                          BREAKFOR
                       ENDIF
                   NEXT a
                   IF NoLineClicked = 1
                      ShowConfirm(-11)
                   RETURN 0
                   ENDIF

						 InsertPoint = cLine
						 sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace
						 BlockIn = getstring(w1,Combo1,getselected(w1,Combo1))
						 BlockIn = getstartpath + "\\Res\\" + BlockIn 
						 count = ReadBlock(BlockIn)
						 CopyStringToClipBoard(CutLine)
						 DoPaste()
                   getscrollrange(w1,ScrollBar,srMin,srMax)
                   SETSCROLLRANGE w1,ScrollBar,0,srMax + count
                endif

           case Combo88
                if @NOTIFYCODE = @CBNSELCHANGE and DoingOpen = 0
                   int WasChanged = 0
						 string IncludeFile = getstring w1,Combo88,getselected(w1,Combo88)
						 string OpenInclude = IncludePath + IncludeFile
						 string SaveFilter = "IWBasic files|*.iwb|EBasic files|*.eba|Include files|*.inc||"
						 filter = "Include files|" + IncludeFile + "|"

						 if openfile(MyFile2,OpenInclude,"R") = 0
							 DoMinimiseAll()
							 CreatePathFile()
							 ProgPath = OpenInclude
							 DoOpen(1)
                      ColourText()
							 ProgCount ++
							 RecentProgs[ProgCount] = ProgPath 
							 if Restoring = 1
								 Restoring = 0
							 endif
							 DisplayTab(OnTab)
							 ReSizeTabs()
						 else
							 OpenInclude = getstartpath + IncludeFile
							 if openfile(MyFile2,OpenInclude,"R") = 0
								 DoMinimiseAll()
								 CreatePathFile()
								 ProgPath = OpenInclude
								 DoOpen()
								 ProgCount ++
								 RecentProgs[ProgCount] = ProgPath 
								 if Restoring = 1
									 Restoring = 0
								 endif
								 DisplayTab(OnTab)
								 ReSizeTabs()
							 endif 
						 endif
						 closefile MyFile2

                   Filter = SaveFilter

                endif

           case RememberMe
                if @NOTIFYCODE = 0
                   if getstate(w1,RememberMe) = 1 then RememberV = 1
                   if getstate(w1,RememberMe) = 0 then RememberV = 0
                   setfocus w1
                endif

           case DupPlaces
                if @NOTIFYCODE = 0
                   if getstate(w1,DupPlaces) = 1 then DupPlacesV = 1
                   if getstate(w1,DupPlaces) = 0 then DupPlacesV = 0
                   setfocus w1
                endif
 
           case EDIT_1
                if @NOTIFYCODE = @ENCHANGE 
                   JumpLine()
                   ResetScroll()
                   OldsRange = (sRange.Low / LineSpace) + LinesPerPage
                   if iswindowclosed(w2) = 0
                      setfocus w2
                   endif
                endif

           case BUTTON_4 'User jump to line button
                if @NOTIFYCODE = 0
                   if (getcontroltext w1,EDIT_11) <> ""
                      JumpLineUser(EDIT_11) 
                   endif
						 sRange.Low = (getscrollpos(w1,ScrollBar) * LineSpace) - LineSpace
						 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
						 cLine = getscrollpos(w1,ScrollBar)
						 StoreLine = cLine
						 if getstate(w1,RememberMe) = 1
							 DoAddNavigationPage(1)
						 endif
                endif 

           case BUTTON_44 'User jump to line button
                if @NOTIFYCODE = 0
                   if (getcontroltext w1,EDIT_111) <> ""
                      JumpLineUser(EDIT_111) 
                   endif
						 sRange.Low = (getscrollpos(w1,ScrollBar) * LineSpace) - LineSpace
						 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
						 cLine = getscrollpos(w1,ScrollBar)
						 StoreLine = cLine
						 if getstate(w1,RememberMe) = 1
							 DoAddNavigationPage(1)
						 endif
                endif

           case BUTTON_444 'User jump to line button
                if @NOTIFYCODE = 0
                   if (getcontroltext w1,EDIT_1111) <> ""
                      JumpLineUser(EDIT_1111) 
                   endif
						 sRange.Low = (getscrollpos(w1,ScrollBar) * LineSpace) - LineSpace
						 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
						 cLine = getscrollpos(w1,ScrollBar)
						 StoreLine = cLine
						 if getstate(w1,RememberMe) = 1
							 DoAddNavigationPage(1)
						 endif
                endif

           case EDIT_11
                if @NOTIFYCODE = @ENCHANGE and DoingOpen = 0
                   if getcontroltext(w1,EDIT_11) <> ""
                      showwindow w1,@SWSHOW,BUTTON_4
                   else
                      showwindow w1,@SWHIDE,BUTTON_4
                   endif
                   JumpLineUser(EDIT_11)
                   ResetScroll()
                   OldsRange = (sRange.Low / LineSpace) + LinesPerPage
                   if iswindowclosed(w2) = 0
                      setfocus w2
                   endif
                   Offset = SendMessage(rHandle,EM_LINEINDEX,val(getcontroltext(w1,EDIT_11))-1,0)
                   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                   setfocus w1,EDIT_11
                endif

           case EDIT_111
                if @NOTIFYCODE = @ENCHANGE and DoingOpen = 0
                   if getcontroltext(w1,EDIT_111) <> ""
                      showwindow w1,@SWSHOW,BUTTON_44
                   else
                      showwindow w1,@SWHIDE,BUTTON_44
                   endif
                   JumpLineUser(EDIT_111)
                   ResetScroll()
                   OldsRange = (sRange.Low / LineSpace) + LinesPerPage
                   if iswindowclosed(w2) = 0
                      setfocus w2
                   endif
                   Offset = SendMessage(rHandle,EM_LINEINDEX,val(getcontroltext(w1,EDIT_111))-1,0)
                   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                   setfocus w1,EDIT_111
                endif

           case EDIT_1111
                if @NOTIFYCODE = @ENCHANGE and DoingOpen = 0
                   if getcontroltext(w1,EDIT_1111) <> ""
                      showwindow w1,@SWSHOW,BUTTON_444
                   else
                      showwindow w1,@SWHIDE,BUTTON_444
                   endif
                   JumpLineUser(EDIT_1111)
                   ResetScroll()
                   OldsRange = (sRange.Low / LineSpace) + LinesPerPage
                   if iswindowclosed(w2) = 0
                      setfocus w2
                   endif
                   Offset = SendMessage(rHandle,EM_LINEINDEX,val(getcontroltext(w1,EDIT_1111))-1,0)
                   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                   setfocus w1,EDIT_1111
                endif

  			  CASE ListView
  				    SELECT @NOTIFYCODE
							  CASE NM_CUSTOMDRAW '<--- Do something when list view is being re-drawn
							       RETURN ColourListViewSearch(w1.hWnd,@LPARAM) '<--- Color the list view items
                endselect

			  CASE ListView2 'Sub routines list
                sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace
					 if @NOTIFYCODE=@NMCLICK 'Click on listview
							lvpos=*<NMLISTVIEW>@LPARAM.iItem
                          CONTROLCMD(w1,ListView2,@LVGETTEXT,lvpos,1,text)
                          sRange.High = 0
                          sRange.Low = (val(text) * LineSpace) - LineSpace
                          SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                          setcontroltext w1,4,text
                          ColourThis = val(text)
                          setfocus w1,RichEdit
								  StartAt = CONTROLCMD(w1,RichEdit,@RTCHARFROMLINE,sRange)
								  CONTROLCMD w1,RichEdit,@RTSETSELECTION,StartAt,StartAt
                          SetLines()
								  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
								  SETCONTROLCOLOR w1,1001,Red,BackColour

                          setscrollpos(w1,ScrollBar,val(text))
                          return 0
					 endif

					 if @NOTIFYCODE=@NMDBLCLK 'Double click on listview
							lvpos=*<NMLISTVIEW>@LPARAM.iItem
                          CONTROLCMD(w1,ListView2,@LVGETTEXT,lvpos,2,text)
                          sRange.High = 0
                          sRange.Low = (val(text) * LineSpace) - LineSpace
                          SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                          setcontroltext w1,4,text
                          ColourThis = val(text)
                          setfocus w1
                          SetLines()
								  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
								  SETCONTROLCOLOR w1,1001,Red,BackColour

                          setscrollpos(w1,ScrollBar,val(text))
                          return 0
					 endif

			  CASE ListView4
                sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace
					 if @NOTIFYCODE=@NMCLICK 'Click on listview
							lvpos=*<NMLISTVIEW>@LPARAM.iItem
                          CONTROLCMD(w1,ListView4,@LVGETTEXT,lvpos,1,text)
                          sRange.High = 0
                          sRange.Low = (val(text) * LineSpace) - LineSpace
                          SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                          setfocus w1
                          SetLines()
								  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
								  SETCONTROLCOLOR w1,1001,Red,BackColour

                          setscrollpos(w1,ScrollBar,val(text))
                          return 0 
					 endif

					 if @NOTIFYCODE=@NMDBLCLK 'Double click on listview
							lvpos=*<NMLISTVIEW>@LPARAM.iItem
                          CONTROLCMD(w1,ListView4,@LVGETTEXT,lvpos,2,text)
                          sRange.High = 0
                          sRange.Low = (val(text) * LineSpace) - LineSpace
                          SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                          setfocus w1
                          SetLines()
								  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
								  SETCONTROLCOLOR w1,1001,Red,BackColour

                          setscrollpos(w1,ScrollBar,val(text))
                          return 0 
					 endif

			  CASE RichEdit
					 SENDMESSAGE(w1.hWnd,EM_GETSCROLLPOS,0,sRange,RichEdit)
					 int OnLine2 = (sRange.Low / LineSpace) + 1

                if Colouring = 1 then return 0 
					 if Loading = 0
						 SendMessage w1,EM_POSFROMCHAR,&pt,pt.y,RichEdit
						 ppos = GETCARETPOSITION w1,x,y
					 endif

					 SELECT @NOTIFYCODE
 							  case @ENENTERKEY 'Enter key pressed...
									 showwindow w1,@SWHIDE,ListView
									 if kw = 0 'Insert blank line
                               Loading = 1
                               QuietMode(1)
									 	 sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace
                               int JumpToPos = val(getcontroltext(w1,PosEdit))
										 CONTROLCMD w1,RichEdit,@RTSETSELECTION,JumpToPos,JumpToPos
										 CONTROLCMD w1,RichEdit,@RTREPLACESEL,chr$(13) + chr$(10)
										 CONTROLCMD w1,RichEdit,@RTSETSELECTION,JumpToPos + 2,JumpToPos + 2
                               QuietMode(0)
                               Loading = 0 

                               cLine ++
										 StartAt = CONTROLCMD(w1,RichEdit,@RTCHARFROMLINE,cLine-1)
										 setcontroltext(w1,KeyWordEdit,"")
										 InfoA = "" 
										 Line2$ = ""
										 Line4$ = ""
										 ttx = StartAt
										 Match = 0
										 kw = 0
										 ttx = varStart
										 CommentsOn = 0
										 sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace
										 SetLines2()
										 ListViewUpdate(1,1)
                               StarTabs()
										 setfocus w1,RichEdit
										 return 0
									 endif

									 if kw > 0
									 	 int eventMask = 0
                               QuietMode(1)
										 TheWordSelected = val(getcontroltext(w1,WordNumberEdit))
										 SENDMESSAGE(rHandle,EM_SETSEL,#w[TheWordSelected].StartPos,#w[TheWordSelected].EndPos)
                               QuietMode(0)

                               string LineBeforeKeyWord = ""
                               CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,LineBeforeKeyWord,512)

										 WordLen   = #w[TheWordSelected].Length
										 WordStart = #w[TheWordSelected].StartPos
										 WordEnd   = #w[TheWordSelected].EndPos
                          
										 if Ucase = 2 then InfoA = lcase$(InfoA)
										 if Ucase = 3 and CapsOn = 0 then InfoA = lcase$(InfoA)
                                  QuietMode(1)
										    CONTROLCMD w1,RichEdit,@RTREPLACESEL,InfoA
                                  kw = 0
                                  SENDMESSAGE(rHandle,EM_SETSEL,#w[TheWordSelected].StartPos,#w[TheWordSelected].EndPos)
											 setcontroltext(w1,KeyWordEdit,InfoA)
											 string LineAfterKeyWord = "" 
											 CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,LineAfterKeyWord,512)
											 string FirstBit = mid$(LineBeforeKeyWord,0,instr(LineBeforeKeyWord,UndoWord)-1)
											 string SecondBit = mid$(LineBeforeKeyWord,instr(LineBeforeKeyWord,UndoWord)+len(UndoWord),len(LineBeforeKeyWord))
											 SecondBit = mid$(SecondBit,1,instr(SecondBit,chr$(13))-1)
											 Undo2Count[OnTab] = Undo2Count[OnTab] - UndoDec
											 Undo2Count[OnTab]++
											 Undo2[OnTab].Press[Undo2Count[OnTab]]  = 10
											 Undo2[OnTab].Length[Undo2Count[OnTab]] = len(#w[a].aWord)
											 Undo2[OnTab].Typed[Undo2Count[OnTab]]  = mid$(LineAfterKeyWord,1,instr(LineAfterKeyWord,chr$(13))-1)
											 Undo2[OnTab].Was[Undo2Count[OnTab]]    = FirstBit + SecondBit
											 Undo2[OnTab].PosBK[Undo2Count[OnTab]]  = EditPos - len(UndoWord)
											 Undo2[OnTab].LineNo[Undo2Count[OnTab]] = cLine-1
                                  Undo2[OnTab].NewLine[Undo2Count[OnTab]] = -1
											 Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)

											 WordNumber = VAL(getcontroltext(w1,WordNumberEdit))
											 TheWordSelected = WordNumber
											 SENDMESSAGE(rHandle,EM_SETSEL,#m[TheWordSelected].StartPos,(#m[TheWordSelected].StartPos + len(InfoA)))
											 showwindow w1,@SWHIDE,ListView

											 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
											 int StoreVis = FirstVisLine

											 Loading = 1
                                  conDrawOff(w1,RichEdit)
											 QuietMode(1)
											 ColourNow(w1,0,rHandle)
											 QuietMode(0)
                                  conDrawOn(w1,RichEdit)
											 Loading = 0

											 sRange.Low = (StoreVis) * LineSpace
											 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
											 setscrollpos(w1,ScrollBar,StoreVis)
											 SENDMESSAGE(rHandle,EM_SETSEL,(#m[TheWordSelected].StartPos + len(InfoA)) , (#m[TheWordSelected].StartPos + len(InfoA)))
											 Undo2[OnTab].PosAK[Undo2Count[OnTab]] = (ttx-1) + (len(InfoA))+1 
										 endif

										 ttx = varStart-1
										 Line2$ = ""
										 Line4$ = ""
										 kw = 0
										 setcontroltext(w1,KeyWordEdit,"")
										 ttx = varEnd
										 OnWord = 1
										 ttt = 0
										 return 0

						        CASE @ENCHANGE
										 TheWordSelected = VAL(getcontroltext(w1,WordNumberEdit))
										 if TheWordSelected
											 SENDMESSAGE(rHandle,EM_SETSEL,#m[TheWordSelected].EndPos+1,#m[TheWordSelected].EndPos+1)
											 Search_And_Highlight(#m[TheWordSelected].aWord)
											 if kw = 0 and Undo2[OnTab].Press[Undo2Count[OnTab]] <> 2 and Undo2[OnTab].Press[Undo2Count[OnTab]] <> 3
												 ttx = varStart-1
												 Line2$ = ""
												 Line4$ = ""
												 kw = 0
												 setcontroltext(w1,KeyWordEdit,"")
												 ttx = varEnd
												 OnWord = 1
												 ttt = 0
                                  endif
										 endif
					   ENDSELECT
			ENDSELECT	
	ENDSELECT
RETURN 0
endsub

SUB DoOpen(opt int Switch)
    DoingOpen = 1
    stoptimer w1,MainTimer 
    if !Switch or Switch = 1000
       if !Switch
			 string OpenThisFile = filerequest("Load File",w1,1,Filter)
			 if ltrim$(OpenThisFile) = "" 
				 NoNewFile = 1
				 starttimer w1,TimerSpeed1,MainTimer
				 return
			 endif 
       endif

       string StoreProgPath = ""
       string StoreFileName = ""
     
       if Switch = 1000
          NoNewFile = 1
          NewFile = 1
          StoreProgPath = ProgPath
          StoreFileName = FileNameIs
       else
          StoreProgPath = ProgPath
          StoreFileName = FileNameIs
          ProgPath = OpenThisFile
       endif

		 if instr(ProgPath,getcontroltext(w1,FileTab1))
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName 
			 LoadTab(1)
			 NoNewFile = 1
          starttimer w1,TimerSpeed1,MainTimer
			 return
		 endif

		 if instr(ProgPath,getcontroltext(w1,FileTab2)) 
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName 
			 LoadTab(2)
			 NoNewFile = 1
          starttimer w1,TimerSpeed1,MainTimer
			 return
		 endif

		 if instr(ProgPath,getcontroltext(w1,FileTab3)) 
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName 
			 LoadTab(3)
			 NoNewFile = 1
          starttimer w1,TimerSpeed1,MainTimer
			 return
		 endif

		 if instr(ProgPath,getcontroltext(w1,FileTab4))
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName 
			 LoadTab(4)
			 NoNewFile = 1
          starttimer w1,TimerSpeed1,MainTimer
			 return
		 endif

		 if instr(ProgPath,getcontroltext(w1,FileTab5)) 
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName 
			 LoadTab(5)
			 NoNewFile = 1
          starttimer w1,TimerSpeed1,MainTimer
			 return
		 endif

		 if instr(ProgPath,getcontroltext(w1,FileTab6)) 
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName 
			 LoadTab(6)
			 NoNewFile = 1
          starttimer w1,TimerSpeed1,MainTimer
			 return
		 endif

       GetFileName(w1,0,ProgPath,1)
       if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4)) and !instr(getcaption(w1),getcontroltext(w1,FileTab5)) and !instr(getcaption(w1),getcontroltext(w1,FileTab6))
          ProgCount ++
          if ProgCount > MaxTabs then ProgCount = MaxTabs  
			 RecentProgs[ProgCount] = ProgPath
			 string MainNameD = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
			 string StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".pth"
			 if openfile(MyFile2,StoreBookFileD,"W") = 0
				 write MyFile2,ltrim$(ProgPath) 
			 endif
			 closefile MyFile2
       else
          ProgPath   = StoreProgPath
          FileNameIs = StoreFileName
          if instr(getcaption(w1),getcontroltext(w1,FileTab1))
				 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,1)
          endif
          if instr(getcaption(w1),getcontroltext(w1,FileTab2))
				 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,2)
          endif
          if instr(getcaption(w1),getcontroltext(w1,FileTab3))
				 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,3)
          endif
          if instr(getcaption(w1),getcontroltext(w1,FileTab4))
				 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,4)
          endif
          if instr(getcaption(w1),getcontroltext(w1,FileTab5))
				 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,5)
          endif
          if instr(getcaption(w1),getcontroltext(w1,FileTab6))
				 SETCONTROLCOLOR w1,FileTab6,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,6)
          endif
          starttimer w1,TimerSpeed1,MainTimer
          if Ontab = 0 and Tab1Loaded = 0
             ProgPath = OpenThisFile
             InitialLoad = 1 
             goto LoadedBefore
          endif
          return 
       endif 
    endif
    'Has been loaded before?
    label LoadedBefore
	 if(len(ProgPath) > 0)

print "Loaded before? ",ProgPath


          ClearEditor()
			 GetFileName(w1,0,ProgPath,1)
			 MainNameD = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
			 StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".txt"
			 if openfile(MyFile2,StoreBookFileD,"R") = 0

				'################
				' LOADED BEFORE '
				'################

				 closefile MyFile2

             if InitialLoad = 1 
                goto SkipLoad 
             endif
				 x = GetLines()
				 setcontroltext(w1,RichEdit,ClipText)
             label SkipLoad
				 DoRestore(0)
             Restoring = 1 
             if (getcontroltext(w1,FileTab1)) <> ""
                OnTab = 1
                Tab1Loaded = 1 
                setscrollrange(w1,ScrollBar,1, CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT))
             endif
             if (getcontroltext(w1,FileTab2)) <> ""
                OnTab = 2
                Tab2Loaded = 1
                setscrollrange(w1,ScrollBar,1, CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)) 
             endif
             if (getcontroltext(w1,FileTab3)) <> ""
                OnTab = 3
                Tab3Loaded = 1 
                setscrollrange(w1,ScrollBar,1, CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT))
             endif
             if (getcontroltext(w1,FileTab4)) <> ""
                OnTab = 4
                Tab4Loaded = 1 
                setscrollrange(w1,ScrollBar,1, CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT))
             endif
             if (getcontroltext(w1,FileTab5)) <> ""
                OnTab = 5
                Tab5Loaded = 1 
                setscrollrange(w1,ScrollBar,1, CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT))
             endif
             if (getcontroltext(w1,FileTab6)) <> ""
                OnTab = 6
                Tab6Loaded = 1 
                setscrollrange(w1,ScrollBar,1, CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT))
             endif
			 else

				'####################
				' NOT LOADED BEFORE '
				'####################

				 ClearEditor()
				 StartUp()

			 endif
    else
       starttimer w1,TimerSpeed1,MainTimer
       return 
	 endif

    if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4)) and !instr(getcaption(w1),getcontroltext(w1,FileTab5)) and !instr(getcaption(w1),getcontroltext(w1,FileTab6))
print "HERE 3 SELECT TAB TAKEN ",TabTaken
print "HERE 3 ",ProgPath,"  ",FileNameIs
       select TabTaken
              case 1
						 Tab1Loaded = 1
						 Tab2Loaded = 0
						 Tab3Loaded = 0
						 Tab4Loaded = 0
						 Tab5Loaded = 0
						 Tab6Loaded = 0
              case 2
						 Tab1Loaded = 1
						 Tab2Loaded = 1
						 Tab3Loaded = 0
						 Tab4Loaded = 0
						 Tab5Loaded = 0
						 Tab6Loaded = 0
              case 3
						 Tab1Loaded = 1
						 Tab2Loaded = 1
						 Tab3Loaded = 1
						 Tab4Loaded = 0
						 Tab5Loaded = 0
						 Tab6Loaded = 0
              case 4
						 Tab1Loaded = 1
						 Tab2Loaded = 1
						 Tab3Loaded = 1
						 Tab4Loaded = 1
						 Tab5Loaded = 0
						 Tab6Loaded = 0
              case 5
						 Tab1Loaded = 1
						 Tab2Loaded = 1
						 Tab3Loaded = 1
						 Tab4Loaded = 1
						 Tab5Loaded = 1
						 Tab6Loaded = 0
              case 6
						 Tab1Loaded = 1
						 Tab2Loaded = 1
						 Tab3Loaded = 1
						 Tab4Loaded = 1
						 Tab5Loaded = 1
						 Tab6Loaded = 1
       endselect

       if Tab1Loaded = 0 
          TabTaken = 1
          goto DoTabLoad
       endif 
       if Tab2Loaded = 0 
          TabTaken = 2
          goto DoTabLoad
       endif
       if Tab3Loaded = 0 
          TabTaken = 3
          goto DoTabLoad
       endif
       if Tab4Loaded = 0 
          TabTaken = 4
          goto DoTabLoad
       endif
       if Tab5Loaded = 0 
          TabTaken = 5
          goto DoTabLoad
       endif
       if Tab6Loaded = 0 
          TabTaken = 6
       endif

       label DoTabLoad
print "HERE 4 DO TAB LOAD ",TabTaken
          if NewFile = 1 
print "HERE 4 - 2"
             GetFileName(w1,0,NewFileName,1)
print "NEW FILE"
          endif
print "HERE 4 New File Name ",FileNameIs

          select TabTaken
					  CASE 1
							 OnTab = 1
							 Tab1Loaded = 1
							 showwindow w1,@SWSHOW,FileTab1
							 setcontroltext(w1,FileTab1,FileNameIs)
							 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),BlueButton
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
							 buffer1 = ""
							 buffer1 = getcontroltext(w1,RichEdit)

                 case 2
							 OnTab = 2
							 Tab2Loaded = 1
							 showwindow w1,@SWSHOW,FileTab2
							 setcontroltext(w1,FileTab2,FileNameIs)
							 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),BlueButton
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
							 buffer2 = ""
							 buffer2 = getcontroltext(w1,RichEdit)
print "HERE 5 SAVE TO BUFF 2"

                 case 3
							 OnTab = 3
							 Tab3Loaded = 1
							 showwindow w1,@SWSHOW,FileTab3
							 setcontroltext(w1,FileTab3,FileNameIs)
							 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),BlueButton
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
							 buffer3 = ""
							 buffer3 = getcontroltext(w1,RichEdit)

                 case 4
							 OnTab = 4
							 Tab4Loaded = 1
							 showwindow w1,@SWSHOW,FileTab4
							 setcontroltext(w1,FileTab4,FileNameIs)
							 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),BlueButton
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
							 buffer4 = ""
							 buffer4 = getcontroltext(w1,RichEdit)

                 case 5
							 OnTab = 5
							 Tab5Loaded = 1
							 showwindow w1,@SWSHOW,FileTab5
							 setcontroltext(w1,FileTab5,FileNameIs)
							 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),BlueButton
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
							 buffer5 = ""
							 buffer5 = getcontroltext(w1,RichEdit)

                 case 6
							 OnTab = 6
							 Tab6Loaded = 1
							 showwindow w1,@SWSHOW,FileTab6
							 setcontroltext(w1,FileTab6,FileNameIs)
							 SETCONTROLCOLOR w1,FileTab6,RGB(255,255,255),BlueButton
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 buffer6 = ""
							 buffer6 = getcontroltext(w1,RichEdit)
          endselect
	 endif

showwindow w1,@SWSHOW,FileTab2
showwindow w1,@SWSHOW,FileTab3
showwindow w1,@SWSHOW,FileTab4
    DoingOpen = 0
    starttimer w1,TimerSpeed1,MainTimer

return
endsub

SUB DoSave(opt int Switch)
	 if CloseProgram = 0 
       select OnTab   
		        Case 1
						 if instr(getcontroltext(w1,FileTab1),"*")
							 buffer1 = ""
							 buffer1 = getcontroltext(w1,RichEdit)
						 endif

              case 2
						 if instr(getcontroltext(w1,FileTab2),"*")
							 buffer2 = ""
							 buffer2 = getcontroltext(w1,RichEdit)
						 endif

              case 3
						 if instr(getcontroltext(w1,FileTab3),"*")
							 buffer3 = ""
							 buffer3 = getcontroltext(w1,RichEdit)
						 endif

              case 4
						 if instr(getcontroltext(w1,FileTab4),"*")
							 buffer4 = ""
							 buffer4 = getcontroltext(w1,RichEdit)
						 endif

              case 5
						 if instr(getcontroltext(w1,FileTab5),"*")
							 buffer5 = ""
							 buffer5 = getcontroltext(w1,RichEdit)
						 endif

              case 6
						 if instr(getcontroltext(w1,FileTab6),"*")
							 buffer6 = ""
							 buffer6 = getcontroltext(w1,RichEdit)
						 endif
       endselect 
	 endif

	 if len(ProgPath) > 0
		 if openfile(file1,ProgPath,"W") = 0
         Modified = 0
         setcaption w1,FileNameIs + ProgramTitle
		   for a = 0 to CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT) - 1
			    CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512)
			    if instr(line$,chr$(13)) 'Line has CHR$(13) + CHR$(10) 
				    write file1,mid$(line$,1,instr(line$,chr$(13))-1)
                goto NextLine
             endif
			    if instr(line$,chr$(10)) 'Line has CHR$(13)
				    write file1,mid$(line$,1,instr(line$,chr$(10))-1)
                goto NextLine
             endif
			    if !instr(line$,chr$(13)) and !instr(line$,chr$(10)) 'Line does not have CHR$(13) or CHR$(10)
                write file1,line$
			    endif 
         label NextLine
		   next a
       endif
		 closefile file1
    endif 

    if OldProgName <> ProgPath
       OldProgName = ProgPath   
       DoRebuild()
       CreateDetailsFile()
    endif

    If CloseProgram = 0
       ShowConfirm(100)
    endif

endsub

SUB DoSaveToTab()
    TabTaken ++
    string StoreFileName = GETSTARTPATH() + "\\Res\\" + FileNameIs
    select TabTaken
           case 1
					 setcontroltext(w1,FileTab1,FileNameIs) 
					 buffer1 = ""
					 buffer1 = getcontroltext(w1,RichEdit)

           case 2
					 setcontroltext(w1,FileTab2,FileNameIs) 
					 buffer2 = ""
					 buffer2 = getcontroltext(w1,RichEdit)

           case 3
					 setcontroltext(w1,FileTab3,FileNameIs) 
					 buffer3 = ""
					 buffer3 = getcontroltext(w1,RichEdit)

           case 4
					 setcontroltext(w1,FileTab4,FileNameIs) 
					 buffer4 = ""
					 buffer4 = getcontroltext(w1,RichEdit)

           case 5
					 setcontroltext(w1,FileTab5,FileNameIs) 
					 buffer5 = ""
					 buffer5 = getcontroltext(w1,RichEdit)

           case 6
					 setcontroltext(w1,FileTab6,FileNameIs) 
					 buffer6 = ""
					 buffer6 = getcontroltext(w1,RichEdit)
    endselect

	 string MainNameD = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 string StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".pth"
	 if openfile(MyFile2,StoreBookFileD,"W") = 0
		 write MyFile2,ltrim$(ProgPath) 
	 endif
	 closefile MyFile2
endsub

SUB DoSaveAs(opt int Switch)

	 GetFileName(w1,0,ProgPath,1)
	 string OldPathFile = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 OldPathFile = OldPathFile + ".pth"
	 string OldTextFile = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 OldTextFile = OldTextFile + ".txt"

	 int MatchRP = 0
	 for a = 1 to MaxTabs
		  if RecentProgs[a] = ProgPath
			  RecentProgs[a] = ""
			  MatchRP = a
			  breakfor
		  endif
	 next a

	 string ProgPathNew = filerequest("Save File",w1,0,filter,"iwb")
	 if len(ProgPathNew) > 0
       ProgPath = ProgPathNew
       GetFileName(w1,0,ProgPath,1)
		 if(openfile(file1,ProgPath,"W") = 0)

			RecentProgs[MatchRP] = ProgPath

			if openfile(MyFile2,getstartpath + "\Res\\" + "xeditor4.ini","W") = 0
				for a = 1 to MaxTabs
					 if rtrim$(ltrim$(RecentProgs[a])) <> "" 
						 write MyFile2,RecentProgs[a]
					 endif
				next a
			endif 
         write MyFile2,"!" + ltrim$(str$(OnTab))
         closefile MyFile2

			GetFileName(w1,0,ProgPath,1)
			string NewPathFile = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
			NewPathFile = NewPathFile + ".pth"
			string NewTextFile = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
			NewTextFile = NewTextFile + ".txt"
			int cpy = 0
			copyfile getstartpath + "\Res\\" + OldPathFile,getstartpath + "\\Res\\" + NewPathFile,cpy
			sleep(200)
			copyfile getstartpath + "\Res\\" + OldTextFile,getstartpath + "\\Res\\" + NewTextFile,cpy
			sleep(200)

         Modified = 0
         setcaption w1,FileNameIs + ProgramTitle
		   for a = 0 to CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT) - 1
			    CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512)
			    if instr(line$,chr$(13))
				    write file1,mid$(line$,1,instr(line$,chr$(13))-1)
			    endif 
		   next a
       endif

		 closefile file1

       select OnTab
				  case 1
						 setcontroltext(w1,FileTab1,FileNameIs + "*")
						 RecentProgs[1] = ProgPath
              case 2
						 setcontroltext(w1,FileTab2,FileNameIs + "*")
						 RecentProgs[2] = ProgPath
              case 3
						 setcontroltext(w1,FileTab3,FileNameIs + "*")
						 RecentProgs[3] = ProgPath
              case 4
						 setcontroltext(w1,FileTab4,FileNameIs + "*")
						 RecentProgs[4] = ProgPath
              case 5
						 setcontroltext(w1,FileTab5,FileNameIs + "*")
						 RecentProgs[5] = ProgPath
              case 6
						 setcontroltext(w1,FileTab6,FileNameIs + "*")
						 RecentProgs[6] = ProgPath
		 endselect
	 endif
	 closefile file1

    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
	 for a = 1 to LinesPerPage
		  setcontroltext(w1,a+1000,str$(FirstVisLine+a))
		  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
	 next a

    int dll = val(getcontroltext(w1,1000 + (cLine-FirstVisLine)))

    if 1000 + (cLine-FirstVisLine) < 1001
       if FontSize = 10
	       setcontroltext(w1,1029,"> " + getcontroltext(w1,1029))
	       SETCONTROLCOLOR w1,1029,Red,BackColour
       endif
       if FontSize = 11
	       setcontroltext(w1,1027,"> " + getcontroltext(w1,1027))
	       SETCONTROLCOLOR w1,1027,Red,BackColour
       endif
    else
	    setcontroltext(w1,1000 + (cLine-FirstVisLine),"> " + getcontroltext(w1,1000 + (cLine-FirstVisLine)))
	    SETCONTROLCOLOR w1,1000 + (cLine-FirstVisLine),Red,BackColour
    endif

return
endsub

sub Search_And_Highlight(string WordIn,opt int Switch)
    if Loading = 1 then return
    if AutoCompleteKeyWords = 0 then return

	 if kw and len(WordIn) > len(InfoA)
       QuietMode(1)
		 int StoreStartPos = (EditPos - len(WordIn)) + 1
		 SENDMESSAGE(rHandle,EM_SETSEL,(EditPos - len(WordIn)) + 1,EditPos + 1)
		 CONTROLCMD w1,RichEdit,@RTREPLACESEL,WordIn
		 SENDMESSAGE(rHandle,EM_SETSEL,(EditPos - len(WordIn)) + 1,EditPos + 1)
		 cf.dwMask = CFM_COLOR
		 cf.crTextColor = TextColour
		 cf.cbSize = SIZEOF(cf)
		 SENDMESSAGE(rHandle,EM_SETCHARFORMAT,SCF_SELECTION,&cf)
		 SENDMESSAGE(rHandle,EM_SETSEL,EditPos + 1,EditPos + 1)
		 InfoA = ""
		 kw = 0
		 ttx = varEnd
		 showwindow w1,@SWHIDE,ListView
		 Undo2Count[OnTab] -= len(WordIn)
		 Undo2Count[OnTab]++
		 Undo2[OnTab].Press[Undo2Count[OnTab]] = 5
		 Undo2[OnTab].Length[Undo2Count[OnTab]] = len(WordIn)
		 Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
		 UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]] = WordIn
		 UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] = StoreStartPos 
		 UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] = EditPos + 1 
		 UndoBlock[OnTab].Length[Undo2Count[OnTab]] = len(WordIn)
       QuietMode(0)
		 return
	 endif

    QuietMode(1)

    kw = 0
    if Switch = 0
		 ppos = GETCARETPOSITION w1,AcrossX,DownY
		 int lvX = AcrossX
		 int lvY = DownY
		 setsize w1,lvX+100,lvY+118,300,58,ListView
    endif
    if Switch = 1
		 setsize w1,900,520,300,58,ListView
    endif
    if Switch = 2
		 setsize w1,750,520,300,58,ListView
    endif

    SearchFor = WordIn

	 if len(SearchFor) < 2 
		 SendMessage(w1,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w1,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif

	 int AscValue = asc(mid$(SearchFor,1,1))
	 if AscValue < 64 and AscValue <> 36
		 SendMessage(w1,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w1,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif
	 if AscValue >= 91 and AscValue <= 96 and AscValue <> 95
		 SendMessage(w1,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w1,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif
	 if AscValue = 81 or AscValue = 113 or AscValue = 88 or AscValue = 89 or AscValue = 90 or AscValue = 120 or AscValue = 121 or AscValue = 122
		 SendMessage(w1,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w1,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif

    int aa = 0
    if mid$(SearchFor,1,1) = "@" 
       aa = 0
       SearchLoopTo = 805
    else
       aa = 806 
       SearchLoopTo = CONTROLCMD(w1,ListView,@LVGETCOUNT) -1
    endif

    WordIn = ltrim$(WordIn)
    SearchFor = ""

    istring SearchForX[255] = WordIn
	 for SearchLoop = 1 to len(WordIn)
        if mid$(SearchForX,SearchLoop,1) = chr$(13)
           breakfor
        else
           SearchFor = SearchFor + mid$(SearchForX,SearchLoop,1)
        endif 
    next SearchLoop
    Match = 0

    uint rHandle = getcontrolhandle(w1,RichEdit)
    int eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,0)
    SendMessage(rHandle,WM_SETREDRAW,false,0)

	 for SearchLoop = aa to SearchLoopTo
		  InvalidateRect(GETCONTROLHANDLE(w1,ListView),NULL,0)
		  CONTROLCMD(w1,ListView,@LVGETTEXT,SearchLoop,0,InfoA)
        'Exact match
		  if mid$(ucase$(InfoA),1,len(SearchFor)) = mid$(ucase$(SearchFor),1,len(SearchFor))  
			  if ucase$(InfoA) = ucase$(SearchFor) 
              if len(SearchFor) > len(InfoA)
                 Match = 0
                 kw = 0
                 showwindow w1,@SWHIDE,ListView
                 breakfor
              endif
              showwindow w1,@SWSHOW,ListView
				  SendMessage(w1,@LVM_ENSUREVISIBLE,SearchLoop,0,ListView)
              Match = SearchLoop
				  LastPosFound = SearchLoop
              if !Switch
print "kw 2" 
                 kw = 2
              endif  
				  breakfor 
			  endif
           'Patial match
			  if mid$(ucase$(InfoA),1,len(SearchFor)) = mid$(ucase$(SearchFor),1,len(SearchFor)) 
              showwindow w1,@SWSHOW,ListView
              if len(SearchFor) > len(InfoA)
                 Match = 0
                 kw = 0
                 showwindow w1,@SWHIDE,ListView
                 breakfor
              endif
				  SendMessage(w1,@LVM_ENSUREVISIBLE,SearchLoop,0,ListView)
              Match = SearchLoop
				  LastPosFound = SearchLoop
              if !Switch
print "kw one"
                 kw = 1
              endif
				  breakfor 
			  endif
		  endif  
	next SearchLoop

   if kw = 0 and Switch = 0
      showwindow w1,@SWHIDE,ListView
   endif

   QuietMode(0)

return
endsub

'===========================================================
sub Search_And_Highlight_Find(string WordIn)
    'if Loading = 1 then return
    'if AutoCompleteKeyWords = 0 then return
    kw = 0
	 ppos = GETCARETPOSITION w6,AcrossX,DownY
	 int lvX = AcrossX
	 int lvY = DownY
	 'setsize w6,lvX+58,lvY+118,300,38,ListView

    SearchFor = WordIn

	 if len(SearchFor) < 2 
		 SendMessage(w6,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w6,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif

	 int AscValue = asc(mid$(SearchFor,1,1))
	 if AscValue < 64 and AscValue <> 36
		 SendMessage(w6,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w6,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif
	 if AscValue >= 91 and AscValue <= 96 and AscValue <> 95
		 SendMessage(w6,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w6,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif
	 if AscValue = 81 or AscValue = 113 or AscValue = 88 or AscValue = 89 or AscValue = 90 or AscValue = 120 or AscValue = 121 or AscValue = 122
		 SendMessage(w6,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w6,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif

    int aa = 0
    if mid$(SearchFor,1,1) = "@" 
       aa = 0
       SearchLoopTo = 805
    else
       aa = 806 
       SearchLoopTo = CONTROLCMD(w6,ListView,@LVGETCOUNT) -1
    endif

    WordIn = ltrim$(WordIn)
    SearchFor = ""

    istring SearchForX[255] = WordIn
	 for SearchLoop = 1 to len(WordIn)
        if mid$(SearchForX,SearchLoop,1) = chr$(13)
           breakfor
        else
           SearchFor = SearchFor + mid$(SearchForX,SearchLoop,1)
        endif 
    next SearchLoop
    Match = 0

	 for SearchLoop = aa to SearchLoopTo
		  InvalidateRect(GETCONTROLHANDLE(w6,ListView),NULL,0)
		  CONTROLCMD(w6,ListView,@LVGETTEXT,SearchLoop,0,InfoA)
		  if mid$(ucase$(InfoA),1,len(SearchFor)) = mid$(ucase$(SearchFor),1,len(SearchFor))  
			  if ucase$(InfoA) = ucase$(SearchFor) 
              showwindow w6,@SWSHOW,ListView
				  SendMessage(w6,@LVM_ENSUREVISIBLE,SearchLoop,0,ListView)
              Match = SearchLoop
				  LastPosFound = SearchLoop
              kw = 2
				  breakfor 
			  endif
			  if mid$(ucase$(InfoA),1,len(SearchFor)) = mid$(ucase$(SearchFor),1,len(SearchFor)) 'instr(ucase$(InfoA),ucase$(SearchFor)) 
              showwindow w6,@SWSHOW,ListView
				  SendMessage(w6,@LVM_ENSUREVISIBLE,SearchLoop,0,ListView)
              Match = SearchLoop
				  LastPosFound = SearchLoop
              kw = 1
				  breakfor 
			  endif
		  endif  
	next SearchLoop

   if kw = 0 
      showwindow w6,@SWHIDE,ListView
   endif

return
endsub

sub ColourNow(window WinIn,int id,int HandleIn,opt int Switch)
    showcursor(FALSE)
    ConDrawOff(w1,RichEdit)
    if !Switch
		 OnLine = FirstVisLine
		 for a = FirstVisLine -2 to FirstVisLine + LinesPerPage
           CONTROLCMD(w1,RichEdit,@RTGETLINE,a,#cp.ClipText,512)
			  if len(ltrim$(#cp.Cliptext)) < 3 then goto CheckNextLine
			  Offset = SendMessage(HandleIn,EM_LINEINDEX,a,0)
			  ColourLineP(rHandle,a-1,Offset)
		 label CheckNextLine
		 next a
       int StoreOffset = Offset

       BlockCommentCheck()

		 SendMessage(rHandle,EM_SETSEL,StoreOffset,StoreOffset)
		 OldLine = OnLine 
    endif
    if Switch = 1
		 OnLine = val(OldLastLine)
       int OldLastLineV = val(OldLastLine)
		 for a = OldLastLineV to OldLastLineV + 1
           CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.ClipText,512)
			  if len(ltrim$(#cp.ClipText)) < 3 then goto CheckNextLine2
			  Offset = SendMessage(HandleIn,EM_LINEINDEX,a-1,0)
			  ColourLineP(rHandle,a-1,Offset)
       label CheckNextLine2
		 next a

       'BlockCommentCheck()

		 Offset = SendMessage(HandleIn,EM_LINEINDEX,a,0)
		 SendMessage(rHandle,EM_SETSEL,1 + Offset,1 + Offset)
		 OldLine = OnLine 
    endif
    if Switch = 2
		 OnLine = val(OldFirstLine)
		 for a = OldFirstLineX - 3 to OldFirstLineX + 1
           CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.ClipText,512)
			  if !len(ltrim$(line$)) then goto CheckNextLine4
			  Offset = SendMessage(HandleIn,EM_LINEINDEX,a-1,0)
			  ColourLineP(rHandle,a-1,Offset)
       label CheckNextLine4
		 next a

       'BlockCommentCheck()

		 SendMessage(rHandle,EM_SETSEL,1 + Offset,1 + Offset)
		 OldLine = OnLine 
    endif
    ConDrawOn(w1,RichEdit)
    showcursor(TRUE)
return
endsub

SUB ColourListViewSearch(hWnd:UINT,lParam:UINT),UINT
    string tempola
    int row
	 row = *<NMLVCUSTOMDRAW>lParam.nmcd.dwItemSpec

	 if row = LastPosFound 'Found a search match in the constant names
	    currentcolor = color1 'Highlight the line
	 else
	    currentcolor = color4 'Otherwise colour the line's background white (normal)
	 endif

    if row = 0
	    currentcolor = color4 'Colour the line's background white (normal)
    endif

 	 CONTROLCMD w7,ListView,@LVGETTEXT,row,0,tempola

	 SELECT *<NMLVCUSTOMDRAW>lParam.nmcd.dwDrawStage

			  CASE CDDS_PREPAINT
				    rv = CDRF_NOTIFYITEMDRAW

			  CASE CDDS_ITEMPREPAINT
				    rv = CDRF_NOTIFYSUBITEMDRAW

			  CASE CDDS_SUBITEMPREPAINT
				    *<NMLVCUSTOMDRAW>lParam.clrText = color3
				    *<NMLVCUSTOMDRAW>lParam.clrTextBk = currentcolor
				    rv = CDRF_NEWFONT

			  DEFAULT
				    rv = CDRF_DODEFAULT
   ENDSELECT
RETURN rv
ENDSUB

SUB SubclassRichEdit(parent as WINDOW,id as INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    lpfn = SetWindowLongA(hEdit,-4,&Rich_Edit_Handler)
    SetPropA(hEdit,"edit_handler",lpfn)   
RETURN
ENDSUB
SUB UnSubclassRichEdit(parent as WINDOW,id as INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    SetWindowLongA(hEdit,-4,GetPropA(hEdit,"edit_handler"))
    RemovePropA(hEdit,"edit_handler")
RETURN
ENDSUB

SUB Rich_Edit_Handler(hwnd:int,uMsg:int,wParam:int,lParam:pointer),int

    SELECT uMsg

           '#####################
           '                    '
           '       Key Up       ' 
           '                    '
           '#####################
           case WM_KEYUP

                GetSelPos() 

                Debug()

					 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
					 CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line$,512)
					 MonitorLine(rHandle,cLine-1,line$,Offset)

					 'Does this line contain a sub routine name?
					 int c1 = 0 
					 int lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) - 1
					 string text2 = ""
					 string text4 = ""
					 LineHasSub = 0
					 for c1 = 0 to lvcount - 1
						  CONTROLCMD(w1,ListView2,@LVGETTEXT,c1,1,text2)
						  if val(text2) = cLine
							  LineHasSub = cLine 'Yes
							  breakfor
						  endif
					 next c1

					 if LineHasSub and WordCount = 0
						 'Delete sub from list
						 lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) - 1
						 for c1 = 0 to lvcount - 1
							  CONTROLCMD(w1,ListView2,@LVGETTEXT,c1,1,text)
							  if val(text) = LineHasSub
								  CONTROLCMD(w1,ListView2,@LVDELETEITEM,c1)
								  deletestring(w1,Combo2,c1)
								  breakfor
							  endif
						 next c1
					 endif 

					 if SubOpen = 2 'Amended existing sub routine
						 SubOpen = 0
					 endif

                if wParam = 17 'Ctrl Key
                   CtrlDown = 0
                endif

                if wParam = 37 'Left arrow Key

                endif

                Typing = 0
					 if wParam = 20 'Caps lock
					    CapsOn = 1 - CapsOn
					 endif

					 if wParam = RedoKey 'Redo
                   if Redo2Count[OnTab] > 0
                      RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)
                   endif
                endif

           '#####################
           '                    '
           '      Key Down      ' 
           '                    '
           '#####################
           case WM_KEYDOWN

print "KEY DOWN ",#w[TheWordSelected].aWord,"    ",InfoA,"     ",kw

                if wParam = 17 'Ctrl Key
                   CtrlDown = 1
                endif

					 IF CtrlDown = 1 and wParam = 67 or wParam = 88 'Ctrl + C / X - Copy / Cut
						 OpenClipboard(w1.hwnd)
						 EmptyClipboard()
						 CloseClipboard()
						 ClipText2 = CutLine
						 CtrlDown = 0
						 return 0
					 endif

					 IF CtrlDown = 1 and wParam = 65 'Select all
                   RTSelectAll(w1,RichEdit)
                   CopyStringToClipboard(CutLine)
                   RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
                endif

					 IF CtrlDown = 1 and wParam = 86 'Paste
                   RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)
                endif

					 IF CtrlDown = 1 and wParam = 70 'Ctrl + F - Find
                   'setfocus w1,CodeWordEdit1
                   return 0
                endif

					 IF CtrlDown = 1 and wParam = 82 'Ctrl + R - Replace
                   setfocus w1,CodePhraseEdit
                   return 0
                endif 

                Typing = 1

					 if wParam = UndoKey 'Undo
                   if AutoCompleteStore = 1
                      AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
                   endif
                   DoUndo(hwnd,uMsg,wParam,lParam) 
                   sleep(50)
                   if AutoCompleteStore = 1
                      AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
                   endif
					 endif

					 if wParam = RedoKey 'Redo
                   if Redo2Count[OnTab] > 0
							 if AutoCompleteStore = 1
								 AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
							 endif 
							 DoRedo(hwnd,uMsg,wParam,lParam)
							 sleep(50)
							 if AutoCompleteStore = 1
								 AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
							 endif  
                   endif 
					 endif

					 if wParam = UndoAllKey 'Undo all
                   Loading = 1
					    int StoreFirstVisLine = GETSCROLLPOS(w1,ScrollBar) + 1
                   sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace
                   int a1

                   conDrawOff(w1,RichEdit)
                   QuietMode(1) 
                   
                   for a1 = Undo2Count[OnTab]to 0 Step -1
                       DoUndo(hwnd,uMsg,wParam,lParam)
                   next a1

                   QuietMode(0)
                   conDrawOn(w1,RichEdit)

					    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)

                   QuietMode(1)
					    ColourNow(w1,1,rHandle)
                   QuietMode(0)

                   Loading = 0


                   Offset = SendMessage(rHandle,EM_LINEINDEX,StoreFirstVisLine,0)
                   SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
					    SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].Pos[Undo2Count[OnTab]+1],Undo2[OnTab].Pos[Undo2Count[OnTab]+1])
					    setfocus w1,RichEdit
						 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						 for a = 1 to 30
							  setcontroltext(w1,a+1000,str$(FirstVisLine+a))
							  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
							  if FirstVisLine+a = cLine
								  setcontroltext(w1,a+1000,"> " + getcontroltext(w1,a+1000))
								  SETCONTROLCOLOR w1,a+1000,Red,BackColour

							  endif
						 next a
   				 endif

					 if wParam = RedoAllKey 'Redo all
                   Loading = 1
                   if AutoCompleteStore = 1
                      AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
                   endif  

                   conDrawOff(w1,RichEdit)
                   QuietMode(1) 

                   for a1 = Redo2Count[OnTab] to 0 Step - 1
                       DoRedo(hwnd,uMsg,wParam,lParam)
                   next a1

                   'QuietMode(0)
                   conDrawOn(w1,RichEdit)

                   if AutoCompleteStore = 1
                      AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
                   endif  
                   Loading = 0
                   StoreFirstVisLine = GETSCROLLPOS(w1,ScrollBar) + 1
                   sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace

					    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)

                   QuietMode(1)
					    ColourNow(w1,1,rHandle)
                   QuietMode(0) 

                   Offset = SendMessage(rHandle,EM_LINEINDEX,StoreFirstVisLine,0)
                   SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
					    SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].Pos[Redo2Count[OnTab]+1]+1,Redo2[OnTab].Pos[Redo2Count[OnTab]+1]+1)
					    setfocus w1,RichEdit
						 for a = 1 to LinesPerPage
							  setcontroltext(w1,a+1000,str$(FirstVisLine+a))
							  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
							  if FirstVisLine+a = cLine
								  setcontroltext(w1,a+1000,"> " + getcontroltext(w1,a+1000))
								  SETCONTROLCOLOR w1,a+1000,Red,BackColour

							  endif
						 next a
   				 endif

                if wParam = 46 or wParam = 8 'Delete / backspace keys
                   StarTabs()
					    int varStart2,varEnd2
					    int xLine = 0
                   RetCount = 0

                   if len(Cliptext) > 1 then goto CarryOnDelete
						 if wParam = 8 'Backspace
							 BackSpacePressed = 1
						 endif 

						 xLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,-1)
						 CONTROLCMD(w1,RichEdit,@RTGETLINE,xLine,line$,512)
						 if wParam = 46 and len(Line$) <= 2 'Delete line
							 DoneBefore = 1
							 Undo2Count[OnTab]++
							 Undo2[OnTab].Press[Undo2Count[OnTab]] = 9
							 Undo2[OnTab].Typed[Undo2Count[OnTab]] = chr$(10) 
							 xLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,-1)
							 Undo2[OnTab].LineNo[Undo2Count[OnTab]] = xLine
							 CONTROLCMD(w1,RichEdit,@RTGETLINE,xLine,line$,512)
							 Offset = SendMessage(rHandle,EM_LINEINDEX,xLine,0)
							 Undo2[OnTab].Pos[Undo2Count[OnTab]] = Offset
							 Undo2[OnTab].Offset[Undo2Count[OnTab]] = Offset
							 Undo2[OnTab].Was[Undo2Count[OnTab]] = chr$(13) + chr$(0)
							 Undo2[OnTab].Colour = RGB(0,0,0)
                      Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
							 MoveBlocks(cLine,1,0,5082) 'Code deleted
							 RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
						 endif

						 if wParam = 8 and len(Line$) <= 2 'Backspace delete line
							 DoneBefore = 1
							 Undo2Count[OnTab]++
							 Undo2[OnTab].Press[Undo2Count[OnTab]] = 8
							 Undo2[OnTab].Typed[Undo2Count[OnTab]] = chr$(8)
							 Undo2[OnTab].DeleteLine[Undo2Count[OnTab]] = 1
							 xLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,-1)
							 Undo2[OnTab].LineNo[Undo2Count[OnTab]] = xLine
							 CONTROLCMD(w1,RichEdit,@RTGETLINE,xLine,line$,512)
							 Offset = SendMessage(rHandle,EM_LINEINDEX,xLine,0)
							 Undo2[OnTab].Pos[Undo2Count[OnTab]] = Offset
							 Undo2[OnTab].Offset[Undo2Count[OnTab]] = Offset
							 Undo2[OnTab].Was[Undo2Count[OnTab]] = chr$(13) + chr$(0)
							 Undo2[OnTab].Colour = RGB(0,0,0)
                      Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
							 MoveBlocks(cLine,1,0,5100) 'Code deleted
							 RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
						 endif

						 if DoneBefore = 1
							 DoneBefore = 0
						 endif 

                   label CarryOnDelete
                   CONTROLCMD w1,RichEdit,@RTSETMODIFIED,1
						 CONTROLCMD w1,RichEdit,@RTGETSELTEXT,ClipText
						 CutLine = ""
                   RetCount = 0
						 for a = 1 to len(ClipText)
							  if asc(mid$(ClipText,a,1)) = 13
                          RetCount ++
							  endif
							  if asc(mid$(ClipText,a,1)) <> 13
								  CutLine = CutLine + mid$(ClipText,a,1) 
							  endif
						 next a

                   if len(ClipText) > 1
                      SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
							 Undo2Count[OnTab]++
							 Undo2[OnTab].Press[Undo2Count[OnTab]] = 4
							 Undo2[OnTab].Length[Undo2Count[OnTab]] = len(ClipText)
                      Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
							 UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]] = ClipText
							 UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] = cr.cpMin
							 UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] = cr.cpMax
							 UndoBlock[OnTab].Length[Undo2Count[OnTab]] = len(ClipText)
							 MoveBlocks(cLine,LineDeleteCount,0,5131) 'Code deleted

							 SendMessage(rHandle,EM_SETSEL,cr.cpMin,cr.cpMax)
							 CONTROLCMD w1,RichEdit,@RTDELETESEL
				          FirstVisLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,cr.cpMin)
                      setcontroltext(w1,EDIT_1,ltrim$(str$(FirstVisLine)))
                      SendMessage(rHandle,EM_SETSEL,cr.cpMin,cr.cpMin)
                      setfocus w1,RichEdit
							 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
							 for a = 1 to 30
								  setcontroltext(w1,a+1000,str$(FirstVisLine+(a)))
								  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
							 next a
							 int dll = val(getcontroltext(w1,1000 + (cLine-FirstVisLine)))
							 if 1000 + (cLine-FirstVisLine) < 1001
                         if FontSize = 10
								    setcontroltext(w1,1029,"> " + getcontroltext(w1,1029))
								    SETCONTROLCOLOR w1,1029,Red,BackColour
                         endif 
                         if FontSize = 11
								    setcontroltext(w1,1027,"> " + getcontroltext(w1,1027))
								    SETCONTROLCOLOR w1,1027,Red,BackColour
                         endif 
							 else
							    setcontroltext(w1,1000 + (cLine-FirstVisLine),"> " + getcontroltext(w1,1000 + (cLine-FirstVisLine)))
							    SETCONTROLCOLOR w1,1000 + (cLine-FirstVisLine),Red,BackColour
                      endif
                      RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)
                   endif
                endif

                if wParam = 34 'Page down
                   Loading = 1
                   Scrolling = 1
                   int StoreTopLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                   if StoreTopLine + 30 > CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
                      RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)
                   endif 
                   ScrollDownPage()
                   int NewTopLine = StoreTopLine + LinesPerPage
                   setcontroltext(w1,EDIT_1,ltrim$(str$(NewTopLine)))
                   Offset = SendMessage(rHandle,EM_LINEINDEX,(NewTopLine + LinesPerPage) - 2,0)
                   cLine = (NewTopLine + LinesPerPage) - 1
                   StoreLine = cLine
						 GetSelPos()
						 setcontroltext(w1,LineNumberEdit,ltrim$(str$((NewTopLine + LinesPerPage) - 1)))
                   setcontroltext(w1,CharPosEdit,"1")

                   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                   setfocus w1,RichEdit
                   Loading = 0
                   Scrolling = 0
                   RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)
                endif

                if wParam = 33 'Page Up
                   Loading = 1
                   Scrolling = 1
                   StoreTopLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                   if StoreTopLine = 0
						    RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)
                   endif
						 ScrollUpPage()
                   StoreTopLine += 2
                   NewTopLine = StoreTopLine - LinesPerPage
                   setcontroltext(w1,EDIT_1,ltrim$(str$(NewTopLine)))

                   FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						 Offset = SendMessage(rHandle,EM_LINEINDEX,FirstVisLine,0)
						 SendMessage(rHandle,EM_SETSEL,Offset,Offset)
						 setfocus w1,RichEdit
                   Loading = 0
                   Scrolling = 0
						 RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)
                endif 

					 if wParam = 40 'Down arrow key
                   ScrollDownKey()
					 endif

					 if wParam = 38 'Up arrow key
						 if instr(getcontroltext(w1,1001),">")
							 KeyUp = 1
						 endif
					 endif

					 int xLine2
                xLine2 = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,-1)
                if wParam = 46 and len(xLine2) > 3 and DoneBefore = 0 'Delete
						 if Undo2Count[OnTab] = 0
							 Redo2Count[OnTab] = 0
						 endif
						 xLine2 = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,-1)
						 CONTROLCMD(w1,RichEdit,@RTGETLINE,xLine2,line2$,512)
						 int varStart22,varEnd22
						 CONTROLCMD w1,RichEdit,@EDGETSELECTION,varStart22,varEnd22
						 Offset = SendMessage(rHandle,EM_LINEINDEX,xLine2,0)
						 int Wass = (varStart - Offset) + 1
						 Undo2Count[OnTab]++
						 Undo2[OnTab].Press[Undo2Count[OnTab]] = 3
						 Undo2[OnTab].Typed[Undo2Count[OnTab]] = chr$(46)
						 Undo2[OnTab].Pos[Undo2Count[OnTab]] = varStart22
						 Undo2[OnTab].Offset[Undo2Count[OnTab]] = Offset
                   Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						 int Was = (varStart - Offset) + 1
                   Undo2[OnTab].Was[Undo2Count[OnTab]] = mid$(Line2$,Wass,1) 

                   CONTROLCMD w1,RichEdit,@RTGETSELECTION,varStart,varEnd

						 int OnATab = 0
						 string BeforeTab,AfterTab
						 SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset+(len(Line2$)))

						 for a = 1 to len(line2$)
						 if asc(mid$(line2$,a,1)) = 9 and a = 1
						    if a + (Offset-1) = varStart
							    OnATab = 1
							    AfterTab = mid$(Line2$,2,len(Line2$))
							    Line2$ = AfterTab
							    QuietMode(1)
							    CONTROLCMD w1,RichEdit,@RTREPLACESEL,Line2$
							    QuietMode(0)
						    endif
						    a++
						 endif

						 if asc(mid$(line2$,a,1)) = 9 and a > 1
						   if a + (Offset-1) = varStart
							   OnATab = 1
							   BeforeTab = mid$(Line2$,1,a-1)
							   AfterTab  = mid$(Line2$,a+1,len(Line2$))
							   Line2$ = BeforeTab + AfterTab
							   QuietMode(1)
							   CONTROLCMD w1,RichEdit,@RTREPLACESEL,Line2$
							   QuietMode(0)
						   endif
						 endif

						next a

						 if OnATab = 0
							 int DelThis = val(getcontroltext(w1,PosEdit))
							 SENDMESSAGE(rHandle,EM_SETSEL,varStart,varStart+1)
							 CONTROLCMD w1,RichEdit,@RTDELETESEL
						 endif
						 OnATab = 0

						 CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,#cp.ClipText,512)
						 if len(#cp.ClipText) > 2
							 Loading = 1
							 showcursor(FALSE)
							 ConDrawOff(w1,RichEdit)
                      QuietMode(1)

							 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
							 ColourLineP(rHandle,cLine-1,Offset)

                      QuietMode(0)
							 ConDrawOn(w1,RichEdit)
							 showcursor(TRUE)
							 Loading = 0
							 SENDMESSAGE(rHandle,EM_SETSEL,varStart,varStart)
						 endif
						 RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)
                endif 

						if wParam = 48 or wParam = 8                    
						   if DoneBefore = 1
							   DoneBefore = 0
							   Undo2Count[OnTab]++
							   Undo2[OnTab].Press[Undo2Count[OnTab]] = 3
							   Undo2[OnTab].Typed[Undo2Count[OnTab]] = chr$(10) 
							   Undo2[OnTab].Pos[Undo2Count[OnTab]] = varStart22
							   Undo2[OnTab].Offset[Undo2Count[OnTab]] = Offset
							   Undo2[OnTab].Was[Undo2Count[OnTab]] = chr$(10) 
                        Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						   endif
                  endif

                if wParam = 8 'Backspace
						 if Undo2Count[OnTab] = 0
							 Redo2Count[OnTab] = 0
						 endif
						 xLine2 = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,-1)
						 CONTROLCMD(w1,RichEdit,@RTGETLINE,xLine2,line2$,512)
						 CONTROLCMD w1,RichEdit,@EDGETSELECTION,varStart2,varEnd2
						 Undo2Count[OnTab]++
						 Undo2[OnTab].Press[Undo2Count[OnTab]] = 2
						 Undo2[OnTab].Pos[Undo2Count[OnTab]] = varStart2
						 Undo2[OnTab].LineNo[Undo2Count[OnTab]] = xLine2
						 Offset = SendMessage(rHandle,EM_LINEINDEX,xLine2,0)
						 Undo2[OnTab].Offset[Undo2Count[OnTab]] = Offset
						 Was = (varStart2 - Offset)
						 Undo2[OnTab].Was[Undo2Count[OnTab]] = mid$(Line2$,Was,1)
						 Undo2[OnTab].Typed[Undo2Count[OnTab]] = chr$(8)
                   Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						 RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
                endif

           '#####################
           '                    '
           '       WM_CHAR      ' 
           '                    '
           '##################### 

           case WM_CHAR
                CharTyped = chr$(wParam)
                StarTabs()

					 if CharTyped = " "
						 kw = 0 
					 endif

					 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
					 WordNumber = GetAllWordsOnLineKeyWord(rHandle,cLine-1,line$,Offset)
					 int TheWordSelected = val(getcontroltext(w1,WordNumberEdit))
					 #m[TheWordSelected].aWord = #m[TheWordSelected].aWord + CharTyped

					 if Undo2Count[OnTab] = 0
						 Redo2Count[OnTab] = 0
					 endif

                ManualChange = 0

                if wParam = 9 'Tab 
						 varStart2 = val(getcontroltext(w1,PosEdit))
						 varEnd2 = varStart2 + 1
						 SendMessage(rHandle,EM_SETSEL,varStart2,varEnd2)
                   CONTROLCMD w1,RichEdit,@RTGETSELTEXT,Line2$
                   string StoreTabString = Line2$

                   QuietMode(1)
                   CONTROLCMD w1,RichEdit,@RTREPLACESEL,chr$(9) + Line2$
						 SendMessage(rHandle,EM_SETSEL,varEnd2,varEnd2)

						 Undo2Count[OnTab]++
  						 Undo2[OnTab].Press[Undo2Count[OnTab]] = 6
						 Undo2[OnTab].Typed[Undo2Count[OnTab]] = chr$(9) + StoreTabString
						 Undo2[OnTab].Pos[Undo2Count[OnTab]] = varStart2 +1
						 xLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,-1)
						 Undo2[OnTab].LineNo[Undo2Count[OnTab]] = xLine
						 CONTROLCMD(w1,RichEdit,@RTGETLINE,xLine,line$,512)
						 Offset = SendMessage(rHandle,EM_LINEINDEX,xLine,0)
						 Undo2[OnTab].Offset[Undo2Count[OnTab]] = Offset
						 Undo2[OnTab].Was[Undo2Count[OnTab]] = StoreTabString
                   Undo2[OnTab].Colour = RGB(0,0,0)
                   Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                   QuietMode(0)
                   RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam) 

                endif  

                if wParam <> 8 and wParam <> 9  
                   if kw and wParam = 13
                      RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
                   endif 
						 CONTROLCMD w1,RichEdit,@EDGETSELECTION,varStart2,varEnd2
print "HERE ",#w[TheWordSelected].aWord,"    ",InfoA,"     ",kw
						 Undo2Count[OnTab]++
						 Undo2[OnTab].Press[Undo2Count[OnTab]] = 1
						 Undo2[OnTab].Typed[Undo2Count[OnTab]] = CharTyped
						 Undo2[OnTab].Pos[Undo2Count[OnTab]] = varStart2
						 xLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,-1)
						 Undo2[OnTab].LineNo[Undo2Count[OnTab]] = xLine
						 CONTROLCMD(w1,RichEdit,@RTGETLINE,xLine,line$,512)
						 Offset = SendMessage(rHandle,EM_LINEINDEX,xLine,0)
						 Undo2[OnTab].Offset[Undo2Count[OnTab]] = Offset
						 Was = (varStart - Offset) + 1
						 Undo2[OnTab].Was[Undo2Count[OnTab]] = mid$(Line$,Was,1)
                   Undo2[OnTab].Colour = RGB(0,0,0)
                   Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
					    SENDMESSAGE(rHandle,EM_SETSEL,varStart2,varStart2)

                   if wParam <> 39 'Not single comment character
							 if wParam = 13 and kw = 0
								 Undo2[OnTab].Pos[Undo2Count[OnTab]] = EditPos
							 endif 

                      QuietMode(1) 
                      #cp.ClipText = Line$
							 ColourLineP(rHandle,cLine-1,Offset)
                      QuietMode(0)

							 SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]],Undo2[OnTab].pos[Undo2Count[OnTab]]) 
                   else
                      QuotesOn = 0
                      for a = 1 to len(Line$)
                          string qs = mid$(Line$,a,1)
                          if qs = chr$(34)
                             QuotesOn = 1 - QuotesOn 
                          endif 
                          if varStart2 = Offset + a
                             breakfor   
                          endif
                      next a

							 cf.dwMask = CFM_COLOR
                      if QuotesOn = 0 
							    SENDMESSAGE(rHandle,EM_SETSEL,varStart2,len(Line$) + Offset)
                      else
							    SENDMESSAGE(rHandle,EM_SETSEL,varStart2,varStart2)
							    cf.crTextColor = Purple
                         ManualChange = 1
                         QuotesOn = 0
                      endif  
							 cf.cbSize = SIZEOF(cf)
							 SENDMESSAGE(rHandle,EM_SETCHARFORMAT,SCF_SELECTION,&cf)
							 SENDMESSAGE(rHandle,EM_SETSEL,varStart2,varStart2)
                    endif
                endif

                if wParam = 13 and kw = 0
                   Undo2[OnTab].Pos[Undo2Count[OnTab]] = EditPos
                   Undo2[OnTab].Typed[Undo2Count[OnTab]] = chr$(13) + chr$(10)
					    Undo2[OnTab].Was[Undo2Count[OnTab]] = Line$
                   Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                endif   

                CONTROLCMD w1,RichEdit,@RTSETMODIFIED,1
                sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace

                if wParam = 8
						 int b1 = 0
						 int DelS = varStart-1
						 int DelE = varStart
						 string DelChar = ""

                   'Colour line 
						 CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,#cp.ClipText,512)
						 if len(Line2$) > 2
							 Loading = 1
							 showcursor(FALSE)
							 ConDrawOff(w1,RichEdit)
                      QuietMode(1)

							 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
							 ColourLineP(rHandle,cLine-1,Offset)

                      QuietMode(0)
							 ConDrawOn(w1,RichEdit)
							 showcursor(TRUE)
							 Loading = 0
							 SENDMESSAGE(rHandle,EM_SETSEL,EditPos,EditPos)
						 endif

                   'Check for possible key word
						 char_index = CONTROLCMD (w1,RichEdit,@RTCHARFROMLINE,cLine-1)
						 eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
						 SendMessage(rHandle,WM_SETREDRAW,false,0)

                   'Word backwards from typing position to delimiter
						 for b1 = varStart to char_index + 1 step - 1
							  CONTROLCMD w1,RichEdit,@RTSETSELECTION,DelS,DelE
							  CONTROLCMD w1,RichEdit,@RTGETSELTEXT,DelChar
							  if INSTR(CheckLetter,DelChar) > 0 'Delimiter found
								  CONTROLCMD w1,RichEdit,@RTSETSELECTION,b1,varStart
								  CONTROLCMD w1,RichEdit,@RTGETSELTEXT,DelChar
								  setcontroltext(w1,KeyWordEdit,DelChar)
								  CONTROLCMD w1,RichEdit,@RTSETSELECTION,varStart,varStart
								  ttx = b1
								  varEnd = varStart
								  Search_And_Highlight(DelChar) 'Check for possible key word here
print "THIS ONE?"

								  breakfor
							  endif

							  DelS --
							  DelE --

						 next b1

						 if b1 = char_index
							 CONTROLCMD w1,RichEdit,@RTSETSELECTION,b1,varStart
							 CONTROLCMD w1,RichEdit,@RTGETSELTEXT,DelChar
							 setcontroltext(w1,KeyWordEdit,DelChar)
							 CONTROLCMD w1,RichEdit,@RTSETSELECTION,varStart,varStart
							 ttx = b1
							 varEnd = varStart
							 Search_And_Highlight(DelChar)
						 endif

                   QuietMode(0)

                endif 

           '########################
           '                       '
           '          Mouse        '
           '                       '
           '########################
 
		     case WM_LBUTTONDOWN
                LButtonDown = 1

		     case WM_LBUTTONUP
                GetSelPos() 
                LButtonDown = 0  
                SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
                CONTROLCMD w1,RichEdit,@RTGETSELTEXT,ClipText
                CutLine = ""
                LineDeleteCount = 0
                for a = 1 to len(ClipText)
                    if asc(mid$(ClipText,a,1)) = 13
                       LineDeleteCount ++
                    endif
                    if asc(mid$(ClipText,a,1)) <> 13
                       CutLine = CutLine + mid$(ClipText,a,1) 
                    endif
                next a

           case WM_MOUSEWHEEL
					 int zDelta = GET_WHEEL_DELTA_WPARAM(wParam)
					 if zDelta > 0                   
                   ScrollWheel(1) 'Scroll up 
					 else                   
                   ScrollWheel(2) 'Scroll down
					 endif

		     case WM_RBUTTONDOWN
					 POINT cursor2
					 GetCursorPos(cursor2) 
					 ScreenToClient(w1.hwnd, cursor2)
					 CONTEXTMENU w1,cursor2.x, cursor2.y
						 MENUITEM "Cut",0,401
                   separator
						 MENUITEM "Copy",0,402
                   separator
						 MENUITEM "Paste",0,403
                   separator
						 MENUITEM "Select All",0,404
                   separator
						 MENUITEM "Find First",0,205
                   separator 
						 MENUITEM "Find All",0,230
                   separator
						 MENUITEM "Find Last",0,231
                   separator
						 MENUITEM "Find this control",0,233
                   separator
						 MENUITEM "Swap round",0,232
					 ENDMENU

    ENDSELECT

RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
ENDSUB

sub SetLines()
'return
if Loading = 1 then return

CommentBlockStart = 0
CommentBlockEnd = 0

int sl = cLine
FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)

if sl - FirstVisLine = LinesPerPage
   int BottomLine = sl - FirstVisLine
   sl = val(getcontroltext(w1,1030))

    QuietMode(1)
	 showcursor(FALSE)

	 OnLine = FirstVisLine
	 for a = sl-1 to sl + 5
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.ClipText,512)
		  if len(ltrim$(#cp.ClipText)) < 3 then goto CheckNextLine
		  Offset = SendMessage(rHandle,EM_LINEINDEX,a-1,0)
		  ColourLineP(rHandle,a-1,Offset)
	 label CheckNextLine
	 next a

    BlockCommentCheck()

	 OldLine = OnLine

    string ActualLineNo = getcontroltext(w1,1000 + LinesPerPage)
    ActualLineNo = mid$(ActualLineNo,instr(ActualLineNo,">")+1,len(ActualLineNo))

	 Offset = SendMessage(rHandle,EM_LINEINDEX,val(ActualLineNo),0)
	 CONTROLCMD w1,RichEdit,@RTSETSELECTION,Offset,Offset

	 showcursor(TRUE)
    QuietMode(0)

    int dll = val(getcontroltext(w1,1000 + (cLine-FirstVisLine)))
    if 1000 + (cLine-FirstVisLine) < 1001
	    setcontroltext(w1,1000+LinesPerPage,"> " + getcontroltext(w1,1000+LinesPerPage))
	    SETCONTROLCOLOR w1,1000+LinesPerPage,Red,BackColour
    else
	   setcontroltext(w1,1000 + (cLine-FirstVisLine),"> " + getcontroltext(w1,1000 + (cLine-FirstVisLine)))
	   SETCONTROLCOLOR w1,1000 + (cLine-FirstVisLine),Red,BackColour
    endif

    Offset = SendMessage(rHandle,EM_LINEINDEX,dll-1,0)
    CONTROLCMD(w1,RichEdit,@RTGETLINE,dll-1,line$,512)

    cLine = dll
    StoreLine = cLine
    Skip = 1

return

endif

if Skip = 0
   FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
	for a = 1 to 30
		 setcontroltext(w1,a+1000,str$(FirstVisLine+(a)))
		 SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
	next a
   if 1000 + (cLine-FirstVisLine) < 1001
      if FontSize = 10 
	      setcontroltext(w1,1029,"> " + getcontroltext(w1,1029))
	      SETCONTROLCOLOR w1,1029,Red,BackColour
      endif
      if FontSize = 11 
	      setcontroltext(w1,1027,"> " + getcontroltext(w1,1027))
	      SETCONTROLCOLOR w1,1027,Red,BackColour
      endif
   else
	   setcontroltext(w1,1000 + (cLine-FirstVisLine),"> " + getcontroltext(w1,1000 + (cLine-FirstVisLine)))
	   SETCONTROLCOLOR w1,1000 + (cLine-FirstVisLine),Red,BackColour
   endif

endif

return
endsub

sub SetLines2()
return 'Change
	 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) ' + 1
	 'setcontroltext(w1,4,ltrim$(str$(FirstVisLine+1)))
    setscrollpos(w1,ScrollBar,FirstVisLine)
	 for a = 1 to 35
		  setcontroltext(w1,a+1000,str$(FirstVisLine+(a)))
		  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
	 next a

	 setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
	 SETCONTROLCOLOR w1,1001,Red,BackColour

	 sRange.Low = (GETSCROLLPOS(w1,ScrollBar) * LineSpace)
	 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)

return
endsub

sub ListViewUpdate(int Direction,int ToAdd)
int sl = 0
int el = 0
string text2 = ""
for a = 0 to CONTROLCMD(w1,ListView2,@LVGETCOUNT) - 1
    CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
    CONTROLCMD(w1,ListView2,@LVGETTEXT,a,2,text2)
    sl = val(text)
    el = val(text2)

    if Direction = 1
       if cLine < sl
          sl = sl + ToAdd
          el = el + ToAdd
       endif
       if cLine > sl and cLine < el 
          el = el + ToAdd
       endif 

    else

       if cLine < sl
          sl = sl - ToAdd
          el = el - ToAdd
       endif
       if cLine > sl and cLine < el 
          el = el - ToAdd
       endif 

    endif

    CONTROLCMD(w1,ListView2,@LVSETTEXT,a,1,str$(sl))
    CONTROLCMD(w1,ListView2,@LVSETTEXT,a,2,str$(el))
next a

for a = 0 to CONTROLCMD(w1,ListView4,@LVGETCOUNT) - 1
    CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text)
    CONTROLCMD(w1,ListView4,@LVGETTEXT,a,2,text2)
    sl = val(text)
    el = val(text2)

    if Direction = 1

       if cLine < sl
          sl = sl + ToAdd
          el = el + ToAdd
       endif
       if cLine > sl and cLine < el 
          el = el + ToAdd
       endif 

    else

       if cLine < sl
          sl = sl - ToAdd
          el = el - ToAdd
       endif
       if cLine > sl and cLine < el 
          el = el - ToAdd
       endif 

    endif

    CONTROLCMD(w1,ListView4,@LVSETTEXT,a,1,str$(sl))
    CONTROLCMD(w1,ListView4,@LVSETTEXT,a,2,str$(el))

next a

return
endsub

sub ColourText(opt int Switch)

    if Switch = 1
	    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 34 'Page down
    endif

    if Switch = 2
	    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) - 34 'Page up
    endif

    if Switch = 3
	    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
    endif

    if Switch = 4
	    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1
    endif

    if Switch = 8
	    FirstVisLine = Fvis - 1
    endif

    if Switch = 9
	    FirstVisLine = Fvis - 1
    endif
    
    if Switch = 0
	    FirstVisLine = getscrollpos(w1,ScrollBar) '- 1
    endif

    QuietMode(1)
	 ColourNow(w1,1,rHandle)
    QuietMode(0)

return
endsub

sub FocusMain()
    if Scrolling = 1 then return
    OnBlock = 0
    ShowMain()
	 showwindow w1,@SWHIDE,TextBlock1
	 showwindow w1,@SWHIDE,TextBlock2
	 showwindow w1,@SWHIDE,TextBlock3
	 showwindow w1,@SWHIDE,TextBlock4
	 showwindow w1,@SWSHOW,ScrollBar
	 showwindow w1,@SWSHOW,RichEdit
	 SETCONTROLCOLOR w1,ShowCode,RGB(255,255,255),BlueButton
	 SETCONTROLCOLOR w1,ShowBlock1,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock2,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock3,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock4,RGB(0,0,0),BackColour
	 setfocus w1
return
endsub

sub FocusBlock1()
    if Scrolling = 1 then return
    OnBlock = 1

	 showwindow w1,@SWHIDE,RichEdit

    HideMain()

	 showwindow w1,@SWHIDE,ScrollBar
	 showwindow w1,@SWHIDE,TextBlock2
	 showwindow w1,@SWHIDE,TextBlock3
	 showwindow w1,@SWHIDE,TextBlock4
    setcontroltext(w1,ShowBlock1,"1")
	 showwindow w1,@SWSHOW,TextBlock1
	 SETCONTROLCOLOR w1,ShowBlock1,RGB(255,255,255),BlueButton
	 SETCONTROLCOLOR w1,ShowBlock2,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock3,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock4,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowCode,RGB(0,0,0),BackColour
    enablecontrol w1,ShowBlock1,1
	 setfocus w1,TextBlock1
return
endsub

sub FocusBlock2()
    if Scrolling = 1 then return
    OnBlock = 2

    HideMain()

	 showwindow w1,@SWHIDE,RichEdit
	 showwindow w1,@SWHIDE,ScrollBar
	 showwindow w1,@SWHIDE,TextBlock1
	 showwindow w1,@SWHIDE,TextBlock3
	 showwindow w1,@SWHIDE,TextBlock4
	 showwindow w1,@SWSHOW,TextBlock2
	 SETCONTROLCOLOR w1,ShowBlock2,RGB(255,255,255),BlueButton
	 SETCONTROLCOLOR w1,ShowBlock1,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock3,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock4,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowCode,RGB(0,0,0),BackColour
	 setfocus w1,TextBlock2
return
endsub

sub FocusBlock3()
    if Scrolling = 1 then return
    OnBlock = 3

    HideMain()

	 showwindow w1,@SWHIDE,RichEdit
	 showwindow w1,@SWHIDE,ScrollBar
	 showwindow w1,@SWHIDE,TextBlock1
	 showwindow w1,@SWHIDE,TextBlock2
	 showwindow w1,@SWHIDE,TextBlock4
	 showwindow w1,@SWSHOW,TextBlock3
	 SETCONTROLCOLOR w1,ShowBlock3,RGB(255,255,255),BlueButton
	 SETCONTROLCOLOR w1,ShowBlock1,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock2,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock4,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowCode,RGB(0,0,0),BackColour
	 setfocus w1,TextBlock2
return
endsub

sub FocusBlock4()
    if Scrolling = 1 then return
    OnBlock = 4

    HideMain()

	 showwindow w1,@SWHIDE,RichEdit
	 showwindow w1,@SWHIDE,ScrollBar
	 showwindow w1,@SWHIDE,TextBlock1
	 showwindow w1,@SWHIDE,TextBlock2
	 showwindow w1,@SWHIDE,TextBlock3
	 showwindow w1,@SWSHOW,TextBlock4
	 SETCONTROLCOLOR w1,ShowBlock4,RGB(255,255,255),BlueButton
	 SETCONTROLCOLOR w1,ShowBlock1,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock2,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock3,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowCode,RGB(0,0,0),BackColour
	 setfocus w1,TextBlock2
return
endsub

sub GetSub(window WinIn,int id,opt int Bin)
    string text
    int ComboPos = getselected(w1,Combo2)
    if ComboPos = -1 then return 
	 CONTROLCMD(w1,ListView2,@LVGETTEXT,ComboPos,1,text)
    int StartOfSub = val(text)
	 int CodeEnd = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)

	 for a = StartOfSub to CodeEnd
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512) 
		  DoGetEndSubZ(a,Line$,1)
		  if EndSubFound = 1
			  breakfor
		  endif
	 next a

	 if EndSubFound = 1
		 EndSubFound = 0
		 int EndSubLine = a+1
	 endif

    CutLine = ""
	 for a = StartOfSub to EndSubLine
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,line$,255)
        CutLine = CutLine + line$
	 label CheckNextLine
	 next a

    CopyStringToClipboard(CutLine)

    LineCount = (EndSubLine - StartOfSub)+1
    if Bin
       SendToBlock() 
    endif
return
endsub

sub GetWindowE(window WinIn,int id,opt int Bin)
    string text
    int ComboPos = getselected(w1,Combo4)
    if ComboPos = -1 then return 
    CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,1,text)
	 int CodeEnd = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
	 for a = val(text) to CodeEnd
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512) 
        if len(ltrim$(line$)) < 3 then goto NextWinLine 
		  DoGetEndWinZ(a,Line$,1)
		  if EndWinFound = 1
			  breakfor
		  endif
    label NextWinLine
	 next a
	 if EndWinFound = 1
		 EndWinFound = 0
		 int EndWinLine = a + 1
	 endif

    int StartOfSub = val(text)
    int EndOfSub = EndWinLine
    CutLine = ""
	 for a = StartOfSub to EndWinLine
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,line$,255)
        CutLine = CutLine + line$
	 label CheckNextLine
	 next a
    CopyStringToClipboard(CutLine)
    if Bin
       SendToBlock() 
    endif
return
endsub

sub RemoveSub(window WinIn,int id,int ComboIn,opt int NoDelete)
    string text,text4
    int ComboPos = getselected(WinIn,ComboIn)
    if ComboPos = -1 then return 
    CONTROLCMD(WinIn,id,@LVGETTEXT,ComboPos,0,text4)
    CONTROLCMD(WinIn,id,@LVGETTEXT,ComboPos,1,text)

	 CONTROLCMD(w1,ListView2,@LVGETTEXT,ComboPos,1,text)
	 int CodeEnd = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)

    SaveSubDelete = val(text)

	 for a = val(text) to CodeEnd
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512) 
		  DoGetEndSubZ(a,Line$,1)
		  if EndSubFound = 1
			  breakfor
		  endif
	 next a
	 if EndSubFound = 1
		 EndSubFound = 0
		 int EndSubLine = a + 2
		 int PositionZ = CONTROLCMD(w1,ListView2,@LVFINDITEM,text4)
		 if PositionZ > -1
			 CONTROLCMD w1,ListView2,@LVSETTEXT,PositionZ,2,LTRIM$(STR$(EndSubLine))
		 endif
	 endif

    int StartOfSub = val(text)
    int EndOfSub = EndSubLine
    int LinesToDelete = (EndOfSub - StartOfSub)
    int OffsetS = SendMessage(rHandle,EM_LINEINDEX,StartOfSub-1,0)
    int OffsetE = SendMessage(rHandle,EM_LINEINDEX,EndOfSub,0)
    OffsetE --

    CONTROLCMD w1,RichEdit,@RTSETSELECTION,OffsetS,OffsetE 

    ClipText = ""
    CONTROLCMD w1,RichEdit,@RTGETSELTEXT,ClipText

	 if len(ClipText)
		 Undo2Count[OnTab]++
		 Undo2[OnTab].Press[Undo2Count[OnTab]] = 4
		 Undo2[OnTab].Length[Undo2Count[OnTab]] = len(ClipText)
       Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
		 UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]] = ClipText
		 UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] = OffsetS
		 UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] = OffsetE
		 UndoBlock[OnTab].Length[Undo2Count[OnTab]] = len(ClipText)
	 endif

    CONTROLCMD w1,RichEdit,@RTSETSELECTION,OffsetS,OffsetE
    CONTROLCMD w1,RichEdit,@RTDELETESEL
    deletestring WinIn,ComboIn,getselected(WinIn,ComboIn)

    int lvcount = CONTROLCMD(WinIn,id,@LVGETCOUNT) - 1
    for a = 0 to lvcount
        CONTROLCMD(WinIn,id,@LVGETTEXT,a,0,text)
        if text = text4
           if NoDelete = 0 
              CONTROLCMD(WinIn,id,@LVDELETEITEM,a)
           endif
           breakfor
        endif
    next a

    MoveBlocks(EndOfSub,LinesToDelete,0,5823)
    ColourText()

return
endsub

sub RemoveWindow(window WinIn,int id)
    string text,text2,text4
    int ComboPos = getselected(w1,Combo4)
    if ComboPos = -1 then return 
    CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,0,text4)
    CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,1,text)
    CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,2,text2)

	 int CodeEnd = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
	 for a = val(text) to CodeEnd
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512) 
		  DoGetEndWinZ(a,Line$,1)
		  if EndWinFound = 1
			  breakfor
		  endif
	 next a
	 if EndWinFound = 1
		 EndWinFound = 0
		 int EndWinLine = a + 1
		 CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,0,text4)
		 PositionZ = CONTROLCMD(w1,ListView4,@LVFINDITEM,text4)
		 if PositionZ > -1
			 CONTROLCMD w1,ListView4,@LVSETTEXT,PositionZ,2,LTRIM$(STR$(EndWinLine))
		 endif
	 endif

    int StartOfSub = val(text)
    int EndOfSub = EndWinLine
    int LinesToDelete = (EndOfSub - StartOfSub)
    int OffsetS = SendMessage(rHandle,EM_LINEINDEX,StartOfSub-1,0)
    int OffsetE = SendMessage(rHandle,EM_LINEINDEX,EndOfSub,0)
    OffsetE --

    CONTROLCMD WinIn,id,@RTSETSELECTION,OffsetS,OffsetE 
    CONTROLCMD WinIn,id,@RTDELETESEL

    int lvcount = CONTROLCMD(w1,ListView4,@LVGETCOUNT) - 1
    for a = 0 to lvcount
        CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text)
        if text = text4
           CONTROLCMD(w1,ListView4,@LVDELETEITEM,a)
           deletestring w1,Combo4,a
           breakfor
        endif
    next a

    MoveBlocks(EndOfSub,LinesToDelete,0,5857)
    ColourText()
    setfocus w1,RichEdit 
    setselected(w1,Combo4,-1)

return
endsub

sub SendToBlock()
	  uint bHandle = 0
	  CopyStringToClipboard(CutLine)

	  ReadClipBoardEditor()
	  int BlockX = 0

	  showwindow w1,@SWHIDE,RichEdit
	  showwindow w1,@SWHIDE,ScrollBar


	  if getcontroltext(w1,TextBlock1) = ""
		  FocusBlock1()
		  BlockX = TextBlock1
	     setcontroltext w1,BlockX,""
	     setcontroltext w1,BlockX,ClipText
        showwindow w1,@SWSHOW,BlockX
		  bHandle = getcontrolhandle(w1,TextBlock1)
		  enablecontrol w1,ShowBlock1,1 
		  'FocusBlock1()
	  else
		  if getcontroltext(w1,TextBlock2) = ""
			  BlockX = TextBlock2
			  bHandle = getcontrolhandle(w1,TextBlock2)
			  enablecontrol w1,ShowBlock2,1  
			  FocusBlock2()
		  else
			  if getcontroltext(w1,TextBlock3) = ""
				  BlockX = TextBlock3
				  bHandle = getcontrolhandle(w1,TextBlock3)
				  enablecontrol w1,ShowBlock3,1  
				  FocusBlock3()
			  else
				  if getcontroltext(w1,TextBlock4) = ""
					  BlockX = TextBlock4
					  bHandle = getcontrolhandle(w1,TextBlock4)
					  enablecontrol w1,ShowBlock4,1  
					  FocusBlock4()
				  endif 
			  endif
		  endif
	  endif 

     CommentBlockStart = 0
     CommentBlockEnd = 0

     QuietMode(1)

     ShowCursor(FALSE)
     conDrawOff(w1,BlockX)
	  for a = 1 to CONTROLCMD(w1,BlockX,@RTGETLINECOUNT)
			char_index = CONTROLCMD (w1,BlockX,@RTCHARFROMLINE,a-1)
			CONTROLCMD(w1,BlockX,@RTGETLINE,a-1,#cp.ClipText,255)
			ColourLineP(bHandle,a-1,char_index)
	  next a

     BlockCommentCheck()

     conDrawOn(w1,BlockX)
     QuietMode(0)

	  SendMessage(bHandle,EM_SETSEL,0,0)
	  ShowCursor(TRUE)
return
endsub

sub JumpLine(opt int Bin)
	 FocusMain()
	 if Bin
		 int bm = val(getstring(w1,Combo6,getselected(w1,Combo6))) 
		 sRange.Low = (bm * LineSpace) - LineSpace
		 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)

		 setscrollpos(w1,ScrollBar,bm)
	 else
	    ColourTextScroll()
		 sRange.Low = ((val(getcontroltext w1,EDIT_1)) * LineSpace) - LineSpace
		 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
		 setscrollpos(w1,ScrollBar,val(getcontroltext w1,EDIT_1))
	 endif

	 StartAt = CONTROLCMD(w1,RichEdit,@RTCHARFROMLINE,sRange)
	 setfocus w1,RichEdit
	 CONTROLCMD w1,RichEdit,@RTSETSELECTION,StartAt,StartAt
	 ppos = GETCARETPOSITION w1,AcrossX,DownY
	 lvX = AcrossX
	 lvY = DownY
	 if kw = 0
		 setsize w1,lvX+58,lvY+98,300,38,ListView
	 endif
	 AcrossX --
	 AcrossX = AcrossX / 8
	 AcrossX ++
	 EditPos = CONTROLCMD(w1,RichEdit,@RTCHARFROMLINE,cLine-1)
	 EditPos = EditPos + AcrossX
	 
	 StoreLine = val(getcontroltext w1,EDIT_1)
	 setscrollpos(w1,ScrollBar,StoreLine)
	 sRange.Low = (getscrollpos(w1,ScrollBar) * LineSpace) - LineSpace
	 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
	 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

	 for a = 1 to 30
		  setcontroltext(w1,a+1000,str$(FirstVisLine+(a-1)))
        SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour 
	 next a

	 if getcontroltext(w1,EDIT_1) = ""
		 for a = 1 to 30
			  setcontroltext(w1,a+1000,str$(a))
		 next a
	 endif 

	 if !Bin
		 setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
		 SETCONTROLCOLOR w1,1001,Red,BackColour
		 setfocus w1,EDIT_1
	 endif
return
endsub

sub DoLineUp()
    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
    if FirstVisLine = 0
		 for a = 1 to 30
			  setcontroltext(w1,a+1000,str$(a))
		 next a
       cLine = 1
       StoreLine = cLine
       return 
    endif
	 setscrollpos(w1,ScrollBar,getscrollpos(w1,ScrollBar)-1)
	 ColourText(3)  
	 sRange.Low = (GETSCROLLPOS(w1,ScrollBar) * LineSpace)
	 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
return
endsub

sub DoLineDown()
Loading = 1
stoptimer w1,MainTimer
	 setscrollpos(w1,ScrollBar,getscrollpos(w1,ScrollBar)+1)
	 sRange.Low = (GETSCROLLPOS(w1,ScrollBar) * LineSpace) - LineSpace
	 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
    QuietMode(1)
	 ColourNow(w1,1,rHandle)
    QuietMode(0)
starttimer w1,TimerSpeed,MainTimer
Loading = 0
return
endsub

Sub DoPaste()
    StarTabs()
	 ReadClipBoard()
	 StorecLine = cLine

    RetCount = 0
    OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)

    if PasteKey = 1 
       ClipText = ClipText2
    endif

	 if len(ClipText)
		 SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
		 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
		 Undo2Count[OnTab]++
		 Undo2[OnTab].Press[Undo2Count[OnTab]] = 5
		 Undo2[OnTab].Length[Undo2Count[OnTab]] = len(ClipText)
       Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
		 UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]] = ClipText
		 UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] = EditPos 
		 UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] = (EditPos + len(ClipText)) - 1 
		 UndoBlock[OnTab].Length[Undo2Count[OnTab]] = len(ClipText)
	 endif

	 rHandle = getcontrolhandle(w1,RichEdit)

    QuietMode(1) 

	 SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]],UndoBlock[OnTab].StartPos[Undo2Count[OnTab]])
	 CONTROLCMD w1,RichEdit,@RTDELETESEL
	 SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]],UndoBlock[OnTab].StartPos[Undo2Count[OnTab]])
	 CONTROLCMD w1,RichEdit,@RTREPLACESEL,ClipText

	 for a = cLine-(LineCount-1)-1 to StorecLine + (LineCount-1)
		  char_index = CONTROLCMD (w1,RichEdit,@RTCHARFROMLINE,a-1)
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.ClipText,512)
		  ColourLineP(rHandle,a-1,char_index)
	 next a

    QuietMode(0)
	 ShowCursor(TRUE)

    RetCount = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
    RetCount = abs(OldLines - RetCount)
    MoveBlocks(cLine,RetCount,1,6048) 'Add lines
	 SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]],UndoBlock[OnTab].EndPos[Undo2Count[OnTab]])

    RetCount  = 0
    ClipText  = ""
    ClipText2 = ""

	 RetCount = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
	 RetCount = abs(OldLines - RetCount)

	 'Add any sub routine that was cut back into the list of sub routines
	 int LastLineCut = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]])
	 int FirstLineCut = (LastLineCut-abs(RetCount))+1
	 LastLineCut ++

	 int a1
	 for a1 = FirstLineCut to LastLineCut
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a1-1,line$,512)
		  Offset = SendMessage(rHandle,EM_LINEINDEX,a1-1,0)
		  GetWordsOnLine(rHandle,a1-1,line$,Offset)

		  if ucase$(#w[1].aWord) = "SUB"
			  INT position = CONTROLCMD(w1,ListView2,@LVFINDITEM,#w[2].aWord)
			  if position = -1
				  int NoDelSub = 1
				  int NewInsertPos = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
				  CONTROLCMD w1,ListView2,@LVINSERTITEM,NewInsertPos,#w[2].aWord
				  position = CONTROLCMD(w1,ListView2,@LVFINDITEM,#w[2].aWord)
				  CONTROLCMD w1,ListView2,@LVSETTEXT,position,1,LTRIM$(STR$(a1))
				  CONTROLCMD w1,ListView2,@LVSETTEXT,position,2,LTRIM$(STR$(a1))
				  SendMessage(GetDlgItem(w1.hwnd,Combo2),CB_RESETCONTENT,0,0)
				  int lvcount22 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
				  if lvcount22 > 0 
					  StoreSubs()
					  PopulateSubRoutines()
				  endif
			  endif
		  endif

		  if ucase$(#w[1].aWord) = "ENDSUB"
			  CONTROLCMD w1,ListView2,@LVSETTEXT,position,2,LTRIM$(STR$(a1))
		  endif

		  if ucase$(#w[1].aWord) = "OPENWINDOW"
			  position = CONTROLCMD(w1,ListView4,@LVFINDITEM,#w[2].aWord)
			  if position = -1
				  int NoDelWin = 1
				  NewInsertPos = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
				  CONTROLCMD w1,ListView4,@LVINSERTITEM,NewInsertPos,#w[2].aWord
				  position = CONTROLCMD(w1,ListView4,@LVFINDITEM,#w[2].aWord)
				  CONTROLCMD w1,ListView4,@LVSETTEXT,position,1,LTRIM$(STR$(a1))
				  CONTROLCMD w1,ListView4,@LVSETTEXT,position,2,LTRIM$(STR$(a1))
				  SendMessage(GetDlgItem(w1.hwnd,Combo4),CB_RESETCONTENT,0,0)
				  lvcount22 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
				  if lvcount22 > 0 
					  PopulateWindows()
				  endif
			  endif
		  endif

		  if ucase$(#w[1].aWord) = "WAITUNTIL"
			  CONTROLCMD w1,ListView4,@LVSETTEXT,position,2,LTRIM$(STR$(a1))
		  endif

	  next a1

return
endsub

SUB printDir(path:STRING),INT
DEF count:INT
DEF dir,attrib=0:INT
DEF filename:STRING
DEF fullname:STRING
count = 0
dir = FINDOPEN(path + "*.*")

string Caption = getcaption w1
Caption = mid$(Caption,1,instr(Caption,".")-1)
IF(dir)
	DO
		filename = FINDNEXT(dir,attrib)
		IF len(filename)
			IF attrib & @FILE_DIRECTORY
				IF(filename <> ".") & (filename <> "..")
					fullname = path + filename + "\\"
					count = count + printdir(fullname)
				ENDIF
			ELSE
            if instr(filename,".ini") and instr(filename,Caption) = 0
               count = count + 1
               ADDSTRING w1,Combo1,filename
            endif
			ENDIF
		ENDIF
	UNTIL filename = ""
	FINDCLOSE dir
ENDIF
RETURN count
ENDSUB

Sub DoPasteSub()
    StarTabs()
	 ReadClipBoard()
	 StorecLine = cLine

	 if len(ClipText)
		 SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
		 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
		 Undo2Count[OnTab]++
		 Undo2[OnTab].Press[Undo2Count[OnTab]] = 5
		 Undo2[OnTab].Length[Undo2Count[OnTab]] = len(ClipText)
       Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
		 UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]] = ClipText
		 UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] = (Offset + ppos) -1 'cr.cpMin
		 UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] = (Offset + len(ClipText)) -1  'cr.cpMax
		 UndoBlock[OnTab].Length[Undo2Count[OnTab]] = len(ClipText)
	 endif

	 rHandle = getcontrolhandle(w1,RichEdit)

    QuietMode(1)

    Offset = SendMessage(rHandle,EM_LINEINDEX,textVV-1,0)
	 SendMessage(rHandle,EM_SETSEL,Offset,Offset)
	 CONTROLCMD w1,RichEdit,@RTREPLACESEL,ClipText

	 for a = cLine-(LineCount-1)-1 to StorecLine + (LineCount-1)
		  char_index = CONTROLCMD (w1,RichEdit,@RTCHARFROMLINE,a-1)
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.ClipText,512)
		  ColourLineP(rHandle,a-1,char_index)
	 next a

    QuietMode(0)

	 ShowCursor(TRUE)
    MoveBlocks(cLine,LineCount,1,6127)
	 SendMessage(rHandle,EM_SETSEL,1+char_index,1 + char_index)

return
endsub

sub ReadBlock(string FileIn),int
    int xx = 0
    int aa = 0
    int bb = 0

    CutLine = ""

	 OPENFILE(myFile,FileIn,"R")
       do 
			 READ myfile,dIn 
          xx ++
          if len(ltrim$(dIn))
             if Ucase <> 3
                dIn = ConvertWordsZ(xx,dIn,0)
             else
                dIn = Indent()
             endif  
          endif
          CutLine  = CutLine + rtrim$(dIn) + chr$(13) + chr$ (10)
          LineEndPos[xx-1] = len(ClipText)
       until eof(myFile)
       closefile myFile

return xx
endsub

sub MoveBlocks(int FromPoint,int CountIn,int Operator,opt int Switch)
if Operator = 0
''print "MOVE BLOCKS ",Switch,"   UP ",FromPoint,"   Count ",CountIn
endif

if Operator = 1
''print "MOVE BLOCKS ",Switch,"   DOWN ",FromPoint,"   Count ",CountIn
endif
 
    int ToPoint = FromPoint + (CountIn - 1)
    if CountIn = 1
       ToPoint = FromPoint
    endif
	 if Operator = 0
		 int lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
       string text2 = "" 
		 string text3 = ""
		 string text4 = ""

		 for c1 = FromPoint to ToPoint
			  for a = 0 to lvcount - 1
					CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text4)
					CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
					if val(text) = c1
						CONTROLCMD(w1,ListView2,@LVDELETEITEM,a)
						DELETESTRING w1,Combo2,a
						breakfor
					endif
			  next a
		 next c1

		 lvcount = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
		 text4 = ""
		 for c1 = FromPoint to ToPoint
			  for a = 0 to lvcount - 1
					CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text4)
					CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text)
					if val(text) = c1
						CONTROLCMD(w1,ListView4,@LVDELETEITEM,a)
						DELETESTRING w1,Combo4,a
						breakfor
					endif
			  next a
		 next c1

	 endif  

    if Operator = 1 'Code added
       'Sub routines
		 lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) 
		 for a = 0 to lvcount - 1
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,2,text2)
			  if val(text) >= FromPoint
				  int NewStart = val(text) + CountIn
			     text = ltrim$(str$(NewStart))
 				  int NewEnd = val(text2) + CountIn
				  text2  = ltrim$(str$(NewEnd))
				  CONTROLCMD(w1,ListView2,@LVSETTEXT,a,0,text4)
				  CONTROLCMD(w1,ListView2,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView2,@LVSETTEXT,a,2,text2)
			  endif
		 next a

       'Windows 
		 lvcount = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
		 for a = 0 to lvcount - 1
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,2,text2)
			  if val(text) >= FromPoint
				  NewStart = val(text) + CountIn
				  text  = ltrim$(str$(NewStart))
				  NewEnd = val(text2) + CountIn
				  text2  = ltrim$(str$(NewEnd))
			     CONTROLCMD(w1,ListView4,@LVSETTEXT,a,0,text4)
				  CONTROLCMD(w1,ListView4,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView4,@LVSETTEXT,a,2,text2)
			  endif
		 next a

/*
       'Selects 
		 lvcount = CONTROLCMD(w1,ListView8,@LVGETCOUNT) - 1
		 for a = 0 to lvcount
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,2,text2)
			  if val(text) >= FromPoint
				  NewStart = val(text) + CountIn
				  text  = ltrim$(str$(NewStart))
				  NewEnd = val(text2) + CountIn
				  text2  = ltrim$(str$(NewEnd))
				  CONTROLCMD(w1,ListView8,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView8,@LVSETTEXT,a,2,text2)
			  endif
		 next a
*/

       'BookMarks
		 lvcount = CONTROLCMD(w1,ListView6,@LVGETCOUNT)
       SendMessage(GetDlgItem(w1.hwnd,Combo6),CB_RESETCONTENT,0,0)

		 for a = 0 to lvcount - 1
			  CONTROLCMD(w1,ListView6,@LVGETTEXT,a,0,text)
			  CONTROLCMD(w1,ListView6,@LVGETTEXT,a,1,text2)
			  if val(text) >= FromPoint
				  NewStart = val(text) + (CountIn)
				  text = ltrim$(str$(NewStart))
				  CONTROLCMD(w1,ListView6,@LVSETTEXT,a,0,text)
				  CONTROLCMD(w1,ListView6,@LVSETTEXT,a,1,text2)
              addstring w1,Combo6,text + " " + text2
			  endif
		 next a

       if lvcount > 1
          SortBookMarks()
       endif
		 string MainName 
		 string StoreBookFile 

       'Navigation
       for a = 0 to getstringcount(w1,Combo18)
           text = getstring(w1,Combo18,a)
			  if val(text) >= FromPoint
				  NewStart = (val(text) + CountIn)
				  text  = ltrim$(str$(NewStart))
				  deletestring(w1,Combo18,a)
              addstring(w1,Combo18,text)
			  endif
       next a

    endif

    if Operator = 0 'Code deleted
       'Sub routines
		 lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) - 1
		 for a = 0 to lvcount
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,2,text2)
			  if val(text) >= FromPoint
				  NewStart = val(text) - CountIn
				  text  = ltrim$(str$(NewStart))
				  NewEnd = val(text2) - CountIn
				  text2  = ltrim$(str$(NewEnd))
				  CONTROLCMD(w1,ListView2,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView2,@LVSETTEXT,a,2,text2)
			  endif
		 next a
       'Windows
		 lvcount = CONTROLCMD(w1,ListView4,@LVGETCOUNT) - 1
		 for a = 0 to lvcount
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,2,text2)
			  if val(text) >= FromPoint
				  NewStart = val(text) - CountIn
				  text  = ltrim$(str$(NewStart))
				  NewEnd = val(text2) - CountIn
				  text2  = ltrim$(str$(NewEnd))
				  CONTROLCMD(w1,ListView4,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView4,@LVSETTEXT,a,2,text2)
			  endif
		 next a

/*
       'Selects 
		 lvcount = CONTROLCMD(w1,ListView8,@LVGETCOUNT) - 1
		 for a = 0 to lvcount
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,2,text2)
			  if val(text) >= FromPoint
				  NewStart = val(text) - CountIn
				  text  = ltrim$(str$(NewStart))
				  NewEnd = val(text2) - CountIn
				  text2  = ltrim$(str$(NewEnd))
				  CONTROLCMD(w1,ListView8,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView8,@LVSETTEXT,a,2,text2)
			  endif
		 next a
*/

       'BookMarks
		 lvcount = CONTROLCMD(w1,ListView6,@LVGETCOUNT) -1
       SendMessage(GetDlgItem(w1.hwnd,Combo6),CB_RESETCONTENT,0,0)

		 for a = 0 to lvcount 
			  CONTROLCMD(w1,ListView6,@LVGETTEXT,a,0,text)
			  CONTROLCMD(w1,ListView6,@LVGETTEXT,a,1,text2)
			  if val(text) >= FromPoint
				  NewStart = val(text) - (CountIn)
				  text  = ltrim$(str$(NewStart))
				  CONTROLCMD(w1,ListView6,@LVSETTEXT,a,0,text)
              addstring w1,Combo6,text + " " + text2
			  endif
		 next a

       if lvcount > 1
          SortBookMarks()
       endif
		 MainName = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
		 StoreBookFile = GETSTARTPATH() + "\\Res\\" + MainName + ".bmk"
		 deletefile StoreBookFile
       SaveBookMarks()

       for a = 0 to getstringcount(w1,Combo18)
           text = getstring(w1,Combo18,a)
			  if val(text) >= FromPoint + 1 'FromPoint
				  NewStart = (val(text) - CountIn)
				  text  = ltrim$(str$(NewStart))
				  deletestring(w1,Combo18,a)
              addstring(w1,Combo18,text)
			  endif
       next a

    endif

return
endsub

sub GetSubToFile(window WinIn,int id,opt int Bin)
    file MyFile2
    string text,text2

    openfile(MyFile2,GETSTARTPATH() + "\\Res\\xtemp.txt","W")

    if Bin = 0
       int ComboPos = getselected(w1,Combo2)
    else
       ComboPos = getselected(w1,Combo4)
    endif  
    if ComboPos = -1 then return 
    CONTROLCMD(WinIn,id,@LVGETTEXT,ComboPos,0,StoreSubName)
    CONTROLCMD(WinIn,id,@LVGETTEXT,ComboPos,1,text)
    CONTROLCMD(WinIn,id,@LVGETTEXT,ComboPos,2,text2)

    int StartOfSub = val(text)
    int EndOfSub = val(text2)
	 for a = StartOfSub to EndOfSub
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,line$,512)
        line$ = mid$(line$,1,instr(line$,chr$(13))-1)
        write MyFile2,line$
	 label CheckNextLine
	 next a

    closefile(MyFile2)

return
endsub

Sub SaveBookMarks()

	 'string MainName = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 'string StoreBookFile = GETSTARTPATH() + "\\Res\\" + MainName + ".bmk"

	 'openfile(MyFile2,StoreBookFile,"W")
		  'for a = 0 to getstringcount(w1,Combo6) - 1 
				'write MyFile2,getstring(w1,Combo6,a) 
		  'next a
	 'closefile MyFile2

return
endsub

sub ScrollUpPage()
    ColourScreenPageUp()
return
endsub

sub ScrollDownPage()
    ColourScreenPageDown()
    cLine -= 1
    StoreLine = cLine
return
endsub

sub ScrollDownKey()
Loading = 1
Scrolling = 1

print "SCROLL DOWN KEY ",getcontroltext(w1,1000+LinesPerPage)

    int BottomLine = StringToVal(getcontroltext(w1,1000+LinesPerPage))
    if cLine = BottomLine
       ColourScreenVisableDown()
    endif

							   FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
							   for a = 1 to 30
								    setcontroltext(w1,a+1000,str$(FirstVisLine + a))
								    SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
							   next a

Loading = 0
Scrolling = 0

ppos = GETCARETPOSITION w1,AcrossX,DownY
print "CASE EDIT_11 ",DownY,"     Line space ",LineSPace

return
endsub

sub ScrollUpKey()
    ColourScreenVisableUp()
return
endsub

sub Combo10Add()
	 int Combo10Count = getstringcount(w1,Combo10)
	 if Combo10Count > 0
       SendMessage(GetDlgItem(w1.hwnd,Combo10),CB_RESETCONTENT,0,0) 
	 endif
	 int LoopFrom = val(TextIn1)-1
	 int LoopTo =  val(TextIn2)-1
    CONTROLCMD(w1,ListView10,@LVDELETEALL)
	 ToAdd = -1
	 for a = LoopFrom to LoopTo
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,line$,512)
		  string SimpleCase = ltrim$(line$)
		  if !len(ltrim$(line$)) then goto CheckNextLine
            if mid$(ucase$(line$),1,6) = "ENDSUB" then breakfor
				if instr(ucase$(line$),"CASE") or instr(ucase$(line$),"DEFAULT")
					if mid$(ucase$(SimpleCase),1,4) = "CASE" or mid$(ucase$(SimpleCase),1,7) = "DEFAULT"
						ToAdd ++
                  if mid$(ucase$(SimpleCase),1,4) = "CASE"
                     SimpleCase = mid$(SimpleCase,5,len(SimpleCase))
                     SimpleCase = ltrim$(SimpleCase)
                     'SimpleCase = mid$(SimpleCase,1,len(SimpleCase)-1)
                  endif 
						CONTROLCMD w1,ListView10,@LVINSERTITEM,ToAdd,SimpleCase
					   CONTROLCMD w1,ListView10,@LVSETTEXT,ToAdd,1,ltrim$(str$(a))
					endif
				endif
	 label CheckNextLine
	 next a
	 'setcontroltext(w1,CaseStatic,"Cases (" + ltrim$(str$(ToAdd+1)) + ")")
    SortListView()
return
endsub

sub SortListView()
string text2,text3
int loops,count,swap
int lvcountIn = CONTROLCMD(w1,ListView10,@LVGETCOUNT)

if lvcountIn <= 2 
	SendMessage(GetDlgItem(w1.hwnd,Combo10),CB_RESETCONTENT,0,0)
	for a = 0 to lvcountIn - 1
		 CONTROLCMD(w1,ListView10,@LVGETTEXT,a,0,text)
		 addstring(w1,Combo10,text)
	next a
	return
endif

for a = 0 to lvcountIn - 1
    CONTROLCMD(w1,ListView10,@LVGETTEXT,a,0,text)
    CONTROLCMD(w1,ListView10,@LVGETTEXT,a,1,text2)
    CONTROLCMD(w1,ListView10,@LVGETTEXT,a,2,text3)

    Col1[a] = text

    if mid$(Col1[a],1,1) = "&"
       Col1[a] = ltrim$(mid$(Col1[a],2,len(Col1[a])))
    endif

    Col2[a] = text2
    Col3[a] = text3
    Col1[a+1] = ""
    Col2[a+1] = ""
    Col3[a+1] = ""

next a

count = lvcountIn
swap=0

int change,cnt_step 
string s_tmp1,s_tmp2,s_tmp3
cnt_step = (count-1)/2

do
	change=0
	loops++
	for x = 0 to count-cnt_step 
		if Col1[x]>Col1[x+cnt_step]
			s_tmp1 = Col1[x+cnt_step]
			Col1[x+cnt_step] = Col1[x]
			Col1[x] = s_tmp1
			s_tmp2 = Col2[x+cnt_step]
			Col2[x+cnt_step] = Col2[x]
			Col2[x] = s_tmp2
			s_tmp3 = Col3[x+cnt_step]
			Col3[x+cnt_step] = Col3[x]
			Col3[x] = s_tmp3
			swap++
			change++	
		endif
	next x
	if cnt_step>1
		cnt_step=cnt_step/2
	endif

until change < 1 and cnt_step = 1

CONTROLCMD(w1,ListView10,@LVDELETEALL)
SendMessage(GetDlgItem(w1.hwnd,Combo10),CB_RESETCONTENT,0,0)

for a = 0 to lvcountIn - 1
    if instr(Col1[a+1]," ") 
	    Col1[a+1] = mid$(Col1[a+1],1,instr(Col1[a+1]," ")-1)
    endif
	 CONTROLCMD w1,ListView10,@LVINSERTITEM,a,Col1[a+1]
	 CONTROLCMD w1,ListView10,@LVSETTEXT,a,1,Col2[a+1]
	 CONTROLCMD w1,ListView10,@LVSETTEXT,a,2,Col3[a+1]
	 addstring(w1,Combo10,Col1[a+1])
next a

CONTROLCMD w1,ListView10,@LVGETTEXT,a,0,text
if text = ""
   CONTROLCMD w1,ListView10,@LVDELETEITEM,0
   deletestring(w1,Combo10,0)
endif

return
endsub

sub SortBookmarks()
return
string text2
int loops,count,swap
int lvcountIn = CONTROLCMD(w1,ListView6,@LVGETCOUNT)

if lvcountIn = 1
    CONTROLCMD w1,ListView6,@LVGETTEXT,0,0,text
    CONTROLCMD w1,ListView6,@LVGETTEXT,0,1,text2
    insertstring(w1,Combo6,0,text + " " + text2)
    return
endif

if lvcountIn < 3 then return
for a = 0 to lvcountIn - 1
    CONTROLCMD w1,ListView6,@LVGETTEXT,a,0,text
    CONTROLCMD w1,ListView6,@LVGETTEXT,a,1,text2
    Col1[a] = text
    Col1[a+1] = ""
    Col2[a] = text2
    Col2[a+1] = ""
next a

count = lvcountIn
swap = 0

int change,cnt_step 
string s_tmp1,s_tmp2
cnt_step = (count-1)/2

do
	change = 0
	loops++
	for x = 0 to count-cnt_step 
       if val(Col1[x]) > val(Col1[x + cnt_step])
			 s_tmp1 = Col1[x + cnt_step]
			 Col1[x + cnt_step] = Col1[x]
			 Col1[x] = s_tmp1
			 s_tmp2 = Col2[x+cnt_step]
			 Col2[x+cnt_step] = Col2[x]
			 Col2[x] = s_tmp2
			 swap++
			 change++	
		endif
	next x
	if cnt_step>1
		cnt_step=cnt_step/2
	endif

	if cnt_step = 0 and count = 2 then break
	until change < 1 and cnt_step = 1

	int EmptyCount = -1
	CONTROLCMD(w1,ListView6,@LVDELETEALL)
	SendMessage(GetDlgItem(w1.hwnd,Combo6),CB_RESETCONTENT,0,0)
	for a = 0 to lvcountIn 
		 if len(Col1[a]) > 0 
			 EmptyCount ++
			 CONTROLCMD w1,ListView6,@LVINSERTITEM,EmptyCount,Col1[a]
			 CONTROLCMD w1,ListView6,@LVSETTEXT,EmptyCount,1,Col2[a]
			 insertstring(w1,Combo6,EmptyCount,Col1[a]+ " " + Col2[a])
		 endif 
	next a

return
ENDSUB

sub WindowSearchPhrase()

ReplaceNow = 0
StopGo = 0
StoppedAt = 0
Toggle = 0
InsertAt = -1 
SearchEnabled = 0

showwindow w1,@SWHIDE,ListView
OPENWINDOW w6,0,0,800,640,@MINBOX|@MAXBOX|@TOPMOST|@CAPTION,0,"Searching...",&SearchPhraseHandler
  Setwindowcolor w6,BackColour
  CONTROL w6,@LISTVIEW,"",12,10,770,312,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			 SENDMESSAGE w6,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			 CONTROLCMD w6,ListViewResult,@LVINSERTCOLUMN,0,"Line"
			 CONTROLCMD w6,ListViewResult,@LVSETCOLWIDTH,0,80
			 CONTROLCMD w6,ListViewResult,@LVINSERTCOLUMN,1,""
			 CONTROLCMD w6,ListViewResult,@LVSETCOLWIDTH,1,490
			 CONTROLCMD w6,ListViewResult,@LVINSERTCOLUMN,2,"Subroutine / Window"
			 CONTROLCMD w6,ListViewResult,@LVSETCOLWIDTH,2,200
          SendMessage w6,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
          SendMessage w6,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
          SETFONT w6,"Arial",11,400,0,ListViewResult

  CONTROL w6,@BUTTON,"Replace",12,340,80,25,0,ReplaceButton
          SETFONT w6,"Arial",10,500,0,ReplaceButton
          SETCONTROLCOLOR w6,ReplaceButton,RGB(0,0,0),RGB(255,255,255)
          showwindow w6,@SWHIDE,ReplaceButton

  CONTROL w6,@CHECKBOX,"Go to line",12,370,100,25,@CTEDITLEFT,NoJumpR
          SETCONTROLCOLOR w6,NoJumpR,RGB(0,0,0),BackColour
          SETFONT w6,"Arial",11,400,0,NoJumpR

  CONTROL w6,@STATIC,"Searching",10,410,68,20,@CTEDITLEFT|0x200,4 
          SETFONT w6,"Arial",11,500,0,4
          SETCONTROLCOLOR w6,4,RGB(0,0,0),BackColour

  CONTROL w6,@BUTTON,"",253,435,30,30,@CTLBTNBITMAP,StopButton
          SETCONTROLTEXT w6,StopButton,GETSTARTPATH() + "\\Res\\stop.bmp"

  CONTROL w6,@BUTTON,"",213,435,30,30,@CTLBTNBITMAP,StopGoButton
          SETCONTROLTEXT w6,StopGoButton,GETSTARTPATH() + "\\Res\\pause.bmp"

  CONTROL w6,@BUTTON,"Select All",12,580,80,25,0,SelectAllButton
          SETFONT w6,"Arial",10,500,0,SelectAllButton
          SETCONTROLCOLOR w6,SelectAllButton,RGB(0,0,0),RGB(255,255,255)
          showwindow w6,@SWHIDE,SelectAllButton

  CONTROL w6,@BUTTON,"Clear All",100,580,80,25,0,ClearAllButton
          SETFONT w6,"Arial",10,500,0,ClearAllButton
          SETCONTROLCOLOR w6,ClearAllButton,RGB(0,0,0),RGB(255,255,255)
          showwindow w6,@SWHIDE,ClearAllButton

  CONTROL w6,@BUTTON,"Close",705,580,80,25,0,CloseButton
          SETFONT w6,"Arial",10,500,0,CloseButton
          SETCONTROLCOLOR w6,CloseButton,RGB(0,0,0),RGB(255,255,255)

   CONTROL w6,@EDIT,getcontroltext(w1,CodePhraseEdit),100,340,210,25,@CTEDITAUTOH|@CTEDITLEFT,ReplaceWhat
           CONTROLCMD w6,ReplaceWhat,@EDSETLIMITTEXT,255
	        SETFONT w6,"Arial",10,400,0,ReplaceWhat
           setcontrolnotify(w6,ReplaceWhat,1,1)
           showwindow w6,@SWHIDE,ReplaceWhat

   CONTROL w6,@STATIC,"With",314,340,35,20,@CTEDITRIGHT|0x200,ReplaceStatic 
           SETFONT w6,"Arial",10,500,0,ReplaceStatic
           SETCONTROLCOLOR w6,ReplaceStatic,RGB(0,0,0),BackColour
           showwindow w6,@SWHIDE,ReplaceStatic

   CONTROL w6,@EDIT,"",360,340,210,25,@CTEDITAUTOH|@CTEDITLEFT,ReplaceWith
           CONTROLCMD w6,ReplaceWhat,@EDSETLIMITTEXT,255
	        SETFONT w6,"Arial",10,400,0,ReplaceWith
           setcontrolnotify(w6,ReplaceWith,1,1)
           showwindow w6,@SWHIDE,ReplaceWith

   CONTROL w6,@BUTTON,"Replace now",580,340,110,25,0,GoReplace
           SETFONT w6,"Arial",10,500,0,GoReplace
           SETCONTROLCOLOR w6,GoReplace,RGB(0,0,0),rgb(255,255,255)
           enablecontrol w6,GoReplace,0
           showwindow w6,@SWHIDE,GoReplace

   'Key words
   CONTROL w6,@LISTVIEW,"",100,545,300,58,@BORDER|@LVSNOCOLUMNHEADER|@LVSSHOWSELALWAYS|@LVSREPORT,ListView
           SENDMESSAGE w6,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView
           CONTROLCMD w6,ListView,@LVINSERTCOLUMN,0,""
           CONTROLCMD w6,ListView,@LVSETCOLWIDTH,0,280
           CONTROLCMD w6,ListView,@LVINSERTITEM,0,""
			  SETFONT w6,"Arial",11,400,0,ListView
           SHOWWINDOW w6,@SWHIDE,ListView

			  'Load key words into a list view...
			  CONTROLCMD w6,ListView,@LVINSERTITEM,0," "
				  FOR a = 1 TO 1661
						CONTROLCMD w6,ListView,@LVINSERTITEM,a,#p[a].words
				  NEXT a

   'Phrase search
   CONTROL w6,@STATIC,"Find exact",10,490,80,25,@CTEDITLEFT|0x200,CodePhraseStatic
			  SETCONTROLCOLOR w6,CodePhraseStatic,RGB(0,0,0),WindowBackColour
			  SETFONT w6,"Arial",11,400,0,CodePhraseStatic

   CONTROL w6,@EDIT,"",100,490,235,25,@CTEDITAUTOH|@CTEDITLEFT,CodePhraseEdit
           CONTROLCMD w6,CodePhraseEdit,@EDSETLIMITTEXT,255
	        SETFONT w6,"Arial",12,400,0,CodePhraseEdit
           SETCONTROLNOTIFY(w6,CodePhraseEdit,1,1)
           SubclassEditFind(w6,CodePhraseEdit)

           setcontroltext(w6,CodePhraseEdit,getcontroltext(w1,CodePhraseEdit))

			  CONTROL w6,@BUTTON,"",345,490,25,25,@CTLBTNBITMAP,CodePhraseSearch 
						 SETCONTROLTEXT w6,CodePhraseSearch,GETSTARTPATH() + "\\Res\\find.bmp"

           CONTROL w6,@BUTTON,"",345,518,25,25,@CTLBTNBITMAP,PhraseDeleteButton
                   SETCONTROLTEXT w6,PhraseDeleteButton,GETSTARTPATH() + "\\Res\\delete.bmp"

			  CONTROL w6,@CHECKBOX,"Find exact",100,520,90,20,@CTEDITRIGHT,CodePhrase
					    SETCONTROLCOLOR w6,CodePhrase,RGB(0,0,0),WindowBackColour
					    SETFONT w6,"Arial",11,400,0,CodePhrase
                   setstate(w6,CodePhrase,getstate(w1,CodePhrase))

			  CONTROL w6,@CHECKBOX,"Specific words",210,520,120,20,@CTEDITRIGHT,CodePhraseWords
					    SETCONTROLCOLOR w6,CodePhraseWords,RGB(0,0,0),WindowBackColour
					    SETFONT w6,"Arial",11,400,0,CodePhraseWords
                   setstate(w6,CodePhraseWords,getstate(w1,CodePhraseWords))

			  CONTROL w6,@CHECKBOX,"First",385,490,50,25,@CTEDITLEFT,FindFirst
					    SETCONTROLCOLOR w6,FindFirst,RGB(0,0,0),WindowBackColour
					    SETFONT w6,"Arial",11,400,0,FindFirst
                   setstate(w6,FindFirst,getstate(w1,FindFirst))

			  CONTROL w6,@CHECKBOX,"All",450,490,50,25,@CTEDITLEFT,FindAll
					    SETCONTROLCOLOR w6,FindAll,RGB(0,0,0),WindowBackColour
					    SETFONT w6,"Arial",11,400,0,FindAll
                   setstate(w6,FindAll,getstate(w1,FindAll))

			  CONTROL w6,@CHECKBOX,"Last",505,490,50,25,@CTEDITLEFT,FindLast
					    SETCONTROLCOLOR w6,FindLAst,RGB(0,0,0),WindowBackColour
					    SETFONT w6,"Arial",11,400,0,FindLast
                   setstate(w6,FindLast,getstate(w1,FindLast))

			  CONTROL w6,@CHECKBOX,"And",385,518,45,25,@CTEDITLEFT,CodeWordAnd
					    SETCONTROLCOLOR w6,CodeWordAnd,RGB(0,0,0),WindowBackColour
					    SETFONT w6,"Arial",11,400,0,CodeWordAnd
                   setstate(w6,CodeWordAnd,getstate(w1,CodeWordAnd))

			  CONTROL w6,@CHECKBOX,"Or",450,518,45,25,@CTEDITLEFT,CodeWordOr
					    SETCONTROLCOLOR w6,CodeWordOr,RGB(0,0,0),WindowBackColour
					    SETFONT w6,"Arial",11,400,0,CodeWordOr
                   setstate(w6,CodeWordOr,getstate(w1,CodeWordOr)) 

                   if getstate(w6,CodePhraseWords) = 0
                      showwindow w6,@SWHIDE,CodeWordAnd
                      showwindow w6,@SWHIDE,CodeWordOr
                   endif

			  InsertPosAt = -1
			  OnePercent = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT) / 100
			  wW = 83
			  wH = 415
			  PercentDone = 0
			  PercentCount = 0
			  rect w6,wW,wH,200,10,BackColour,rgb(255,255,255)

			  Graph2(getcontroltext(w6,CodePhraseEdit))

WAITUNTIL IsWindowClosed(w6)

return 
endsub

SUB SearchPhraseHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w6

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w6

           CASE @IDCONTROL
                SELECT @CONTROLID
							  CASE ListView
									 SELECT @NOTIFYCODE
											  CASE NM_CUSTOMDRAW '<--- Do something when list view is being re-drawn
													 RETURN ColourListViewSearch(w1.hWnd,@LPARAM) '<--- Color the list view items
									 endselect

							  case CodePhrase
									 if @NOTIFYCODE = 0
										 Loading = 1
										 CodePhraseWordsV  = 0
										 CodePhraseV       = 1
										 setstate w6,CodePhrase,CodePhraseV 
										 setstate w6,CodePhraseWords,CodePhraseWordsV
										 AppendEdit(w6,CodePhraseEdit,"",0)
										 setcontroltext(w6,CodePhraseStatic,"Find exact")
										 showwindow w6,@SWSHOW,MaxWordsStatic
										 showwindow w6,@SWHIDE,CodeWordAnd
										 showwindow w6,@SWHIDE,CodeWordOr
										 setfocus w6,CodePhraseEdit 
										 showwindow w6,@SWHIDE,ListView 
										 Loading = 0
									 endif

							  case CodeWordAnd
									 if @NOTIFYCODE = 0
										 if getstate(w6,CodeWordAnd) = 1
											 AndV = 1
											 OrV  = 0
											 setstate w6,CodeWordOr,0 
										 else
											 AndV = 0
											 OrV  = 1
											 setstate w6,CodeWordOr,1
										 endif
										 setfocus w6 
									 endif 

							  case CodeWordOr
									 if @NOTIFYCODE = 0
										 if getstate(w6,CodeWordOr) = 1
											 AndV = 0
											 OrV  = 1
											 setstate w6,CodeWordAnd,0 
										 else
											 AndV = 1
											 OrV  = 0
											 setstate w6,CodeWordAnd,1
										 endif
										 setfocus w6 
									 endif 

							  case FindFirst
									 if @NOTIFYCODE = 0
										 if getstate(w6,FindFirst)
											 setstate w6,FindAll,0
											 setstate w6,FindLast,0
											 setfocus w6
										 endif 
									 endif

							  case FindAll
									 if @NOTIFYCODE = 0
										 if getstate(w6,FindAll)
											 setstate w6,FindFirst,0
											 setstate w6,FindLast,0
											 setfocus w6
										 endif 
									 endif

							  case FindLast
									 if @NOTIFYCODE = 0
										 if getstate(w6,FindLast)
											 setstate w6,FindFirst,0
											 setstate w6,FindAll,0
											 setfocus w6
										 endif 
									 endif

							  case CodePhraseWords
									 if @NOTIFYCODE = 0
										 Loading = 1
										 CodePhraseWordsV  = 1
										 CodePhraseV       = 0
										 setstate w6,CodePhrase,CodePhraseV 
										 setstate w6,CodePhraseWords,CodePhraseWordsV
										 AppendEdit(w6,CodePhraseEdit,"",0)
										 setcontroltext(w6,CodePhraseStatic,"Find words")
										 showwindow w6,@SWSHOW,MaxWordsStatic
										 showwindow w6,@SWSHOW,CodeWordAnd
										 showwindow w6,@SWSHOW,CodeWordOr
										 setfocus w6,CodePhraseEdit 
										 showwindow w6,@SWHIDE,ListView 
										 Loading = 0
									 endif

                       case PhraseDeleteButton
                            if @NOTIFYCODE = 0
										 ReplaceNow = 0
										 StopGo     = 0
										 StoppedAt  = 0
										 Toggle     = 0
									    PercentCount = 0
									    PercentDone = 0 
										 InsertAt   = -1
										 SearchEnabled = 1
										 setsize w6,10,395,700,50,4
										 rect w6,wW,wH,700,20,BackColour,BackColour
										 showwindow w6,@SWHIDE,StopGoButton
										 showwindow w6,@SWHIDE,StopButton
                               enablecontrol(w6,CodePhraseSearch,1)
										 setcontroltext(w6,4,"")
                               setcontroltext(w6,CodePhraseEdit,"")
                               setfocus w6,CodePhraseEdit
                            endif

							  case CodePhraseEdit
									 if @NOTIFYCODE = @ENCHANGE and Loading = 0
										 string ThePhrase = getcontroltext(w6,CodePhraseEdit)
										 for a = ePos to 1 step -1
											  if mid$(ThePhrase,a,1) = " "
												  SpacePosX = a + 1
												  breakfor
											  endif
										 next a

										 if a = 1
											 SpacePosX = 0
										 endif

										 Rlen = (ePos - SpacePosX) + 1
										 WordToLookUp = mid$(ThePhrase,SpacePosX,Rlen)

										 if SpacePosX = 0
											 WordToLookUp = mid$(getcontroltext(w6,CodePhraseEdit),0,ePos)
										 else
											 WordToLookUp = mid$(getcontroltext(w6,CodePhraseEdit),(ePos-Rlen)+1,(ePos+Rlen))
										 endif

										 WordToLookUp = ltrim$(rtrim$(WordTOLookUp))
										 if instr(WordToLookUp," ")
											 WordToLookUp = mid$(WordToLookUp,1,instr(WordToLookUp," ")-1) 
										 endif

										 if len(WordToLookUp) >= 2
											 Loading = 0
											 Search_And_Highlight_Find(WordToLookUp)
										 endif
									 endif

									 if @NOTIFYCODE = @ENENTERKEY
										 if SpacePosX = 0
											 SENDMESSAGE(getcontrolhandle(w6,CodePhraseEdit),EM_SETSEL,0,ePos)
										 else
											 SENDMESSAGE(getcontrolhandle(w6,CodePhraseEdit),EM_SETSEL,(ePos-Rlen)-1,ePos)
										 endif

										 showwindow w6,@SWHIDE,ListView
										 if (getcontroltext(w6,CodePhraseEdit)) = "" 
											 Loading = 0
											 InfoA = ""
											 WordToLookup = ""
											 SpacePosX = 0
											 showwindow w6,@SWHIDE,ListView
											 setfocus w6,CodePhraseEdit
											 return 0
										 endif
										 Loading = 1
										 CONTROLCMD w6,CodePhraseEdit,@RTDELETESEL 
										 SENDMESSAGE(getcontrolhandle(w6,CodePhraseEdit),EM_SETSEL,(ePos-Rlen)-1,(ePos-Rlen)-1)
										 CONTROLCMD w6,CodePhraseEdit,@RTREPLACESEL,InfoA + " "
										 Loading = 0
										 InfoA = ""
										 WordToLookup = ""
										 SpacePosX = 0
										 showwindow w6,@SWHIDE,ListView
									 endif

                       case CodePhraseSearch
                            IF @NOTIFYCODE = 0
                               if SearchEnabled = 0 then return 0
                               if getcontroltext(w6,CodePhraseEdit) = ""
                                  setfocus w6,CodePhraseEdit
                                  return 0
                               endif 
									    wW = 83
									    wH = 415
									    PercentDone = 0
									    PercentCount = 0
                               SearchEnabled = 0
									    rect w6,wW,wH,200,10,BackColour,rgb(255,255,255)
										 SETCONTROLTEXT w6,StopGoButton,GETSTARTPATH() + "\\Res\\pause.bmp"
                               setsize w6,10,410,68,20,4
                               setcontroltext(w6,4,"Searching")
		                         showwindow w6,@SWSHOW,StopGoButton
		                         showwindow w6,@SWSHOW,StopButton
                               setfocus w6 
                               CONTROLCMD(w6,ListViewResult,@LVDELETEALL)
                               enablecontrol(w6,CodePhraseSearch,0)
                               Graph2(getcontroltext(w6,CodePhraseEdit))
                               enablecontrol(w6,CodePhraseSearch,1) 
                           endif                           

                       case NoJumpR
                            IF @NOTIFYCODE = 0
                               NoJumpRV = 1 - NoJumpRV
                               setfocus w6 
                           endif 

                       case ReplaceWhat
                            IF @NOTIFYCODE = @ENCHANGE 
                               if getcontroltext(w6,ReplaceWhat) <> "" and getcontroltext(w6,ReplaceWith) <> ""
                                  enablecontrol w6,GoReplace,1
                               else
                                  enablecontrol w6,GoReplace,0          
                               endif                                
                            endif

                            IF @NOTIFYCODE = @ENENTERKEY
                               setfocus w6,ReplaceWith 
                            endif
                            IF @NOTIFYCODE = @ENTABKEY
                               setfocus w6,ReplaceWith 
                            endif

                       case ReplaceWith
                            IF @NOTIFYCODE = @ENCHANGE 
                               if getcontroltext(w6,ReplaceWhat) <> "" and getcontroltext(w6,ReplaceWith) <> ""
                                  enablecontrol w6,GoReplace,1
                               else
                                  enablecontrol w6,GoReplace,0          
                               endif                                
                            endif

                            IF @NOTIFYCODE = @ENENTERKEY
                               goto GoReplaceNow
                            endif

							  case ListViewResult
									 if @NOTIFYCODE=@NMCLICK
										 lvpos=*<NMLISTVIEW>@LPARAM.iItem 

										 label ClickListViewResult
                               if NoJumpRV = 1
										    lvpos=*<NMLISTVIEW>@LPARAM.iItem
										    CONTROLCMD(w6,ListViewResult,@LVGETTEXT,lvpos,0,text)
										    setcontroltext(w1,EDIT_1,text)
                                  setfocus w6 
                               endif

                               if ReplaceNow = 1 
											 If lvpos > -1
											    If conLVGetCheckState(w6,ListViewResult,lvpos)
													 conLVSetCheckState(w6,ListViewResult,lvpos,0) 
												 Else                        
													 conLVSetCheckState(w6,ListViewResult,lvpos,1) 
												 EndIf
											 endif
                               endif
 
									 endif

                       case SelectAllButton 
									 if @NOTIFYCODE = 0
                               conLVSetCheckState(w6,ListViewResult,-1,1)
                               setfocus w6 
                            endif

                       case ClearAllButton 
									 if @NOTIFYCODE = 0
                               conLVSetCheckState(w6,ListViewResult,-1,0)
                               setfocus w6
                            endif

                       case ReplaceButton 
									 if @NOTIFYCODE = 0
                               ReplaceNow = 1 - ReplaceNow
                               if ReplaceNow = 0
                                  showwindow w6,@SWHIDE,ReplaceWhat
                                  showwindow w6,@SWHIDE,ReplaceStatic
                                  showwindow w6,@SWHIDE,ReplaceWith
                                  showwindow w6,@SWHIDE,GoReplace
                                  showwindow w6,@SWHIDE,SelectAllButton
                                  showwindow w6,@SWHIDE,ClearAllButton
                                  setcontroltext(w6,ReplaceButton,"Replace")
                                  conLVSetCheckState(w6,ListViewResult,-1,0)
                                  setfocus w6
                               else 
                                  showwindow w6,@SWSHOW,ReplaceWhat
                                  showwindow w6,@SWSHOW,ReplaceStatic
                                  showwindow w6,@SWSHOW,ReplaceWith
                                  showwindow w6,@SWSHOW,GoReplace
                                  showwindow w6,@SWSHOW,SelectAllButton
                                  showwindow w6,@SWSHOW,ClearAllButton
                                  setcontroltext(w6,ReplaceButton,"Hide")
                                  AppendEdit(w6,ReplaceWhat,"",0)  
                                  setfocus w6,ReplaceWhat
                               endif
                            endif

                       case GoReplace
									 if @NOTIFYCODE = 0
                               StarTabs() 
                               label GoReplaceNow 
                               stoptimer w1,MainTimer
                               int WasOnLine = getscrollpos(w1,ScrollBar)
										 int lvr = CONTROLCMD(w6,ListViewResult,@LVGETCOUNT)
										 for a = 0 to lvr
                                   If conLVGetCheckState(w6,ListViewResult,a)
												  CONTROLCMD(w6,ListViewResult,@LVGETTEXT,a,1,text)
												  if Instr(ucase$(text),ucase$(getcontroltext(w6,ReplaceWhat)))
													  int Rpos = Instr(ucase$(text),ucase$(getcontroltext(w6,ReplaceWhat)))
													  string Before = mid$(text,1,Rpos-1)
													  string After =  mid$(text,(Rpos + len(getcontroltext(w6,ReplaceWhat))),len(text))
													  text = Before + getcontroltext(w6,ReplaceWith) + After
													  CONTROLCMD(w6,ListViewResult,@LVSETTEXT,a,1,text)
													  CONTROLCMD(w6,ListViewResult,@LVGETTEXT,a,0,text)

													  int textV = val(text)-1
													  CONTROLCMD(w1,RichEdit,@RTGETLINE,textV,line$,512)
													  int ROffset = SendMessage(rHandle,EM_LINEINDEX,textV,0)
													  int REnd = (ROffset + len(line$))-2
													  Rpos = Instr(ucase$(line$),ucase$(getcontroltext(w6,ReplaceWhat)))
													  Before = mid$(line$,1,Rpos-1)
													  After =  mid$(line$,(Rpos + len(getcontroltext(w6,ReplaceWhat))),len(line$))
													  if instr(After,chr$(13))
														  After = mid$(After,1,instr(After,chr$(13))-1)
													  endif
													  line2$ = Before + getcontroltext(w6,ReplaceWith) + After
													  CONTROLCMD w1,RichEdit,@RTSETSELECTION,ROffset,REnd 
													  CONTROLCMD w1,RichEdit,@RTREPLACESEL,line2$
                                         #cp.ClipText = line2$
													  ColourLineP(rHandle,textV,ROffset)
													  Undo2Count[OnTab]++
													  Undo2[OnTab].Press[Undo2Count[OnTab]] = 7
													  Undo2[OnTab].Typed[Undo2Count[OnTab]] = Line2$ 'Changed line
													  Undo2[OnTab].Pos[Undo2Count[OnTab]] = ROffset
													  Undo2[OnTab].Offset[Undo2Count[OnTab]] = ROffset
													  Undo2[OnTab].Was[Undo2Count[OnTab]] = mid$(Line$,1,len(Line$)-2) 'Line was  
													  Undo2[OnTab].LineNo[Undo2Count[OnTab]] = textV 
                                         textV -= 14
                                         if textV < 0 then textV = 0 
'
                                         Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = textV
'
												endif
                                 endif
										 next a 
                               setcontroltext(w1,EDIT_1,ltrim$(str$(textV+1))) 
                               closewindow w6
                               showwindow w1,@SWHIDE,ListView
                               starttimer w1,TimerSpeed,MainTimer
                            endif

							  case StopButton
									 if @NOTIFYCODE = 0
                               StopGo = 100
                            endif

							  case StopGoButton
									 if @NOTIFYCODE = 0
                               Toggle = 1 - Toggle
										 if Toggle = 0
											 SETCONTROLTEXT w6,StopGoButton,GETSTARTPATH() + "\\Res\\pause.bmp"
                                  setsize w6,10,410,68,20,4
                                  setcontroltext(w6,4,"Searching")
                                  setfocus w6 
											 StopGo = 0
											 Graph2(getcontroltext(w6,CodePhraseEdit))
										 else
                                  setsize w6,10,410,700,20,4
                                  SETCONTROLTEXT w6,StopGoButton,GETSTARTPATH() + "\\Res\\jump.bmp"
											 StopGo = 1 
                                  setfocus w6
										 endif
                            endif

							  case CloseButton
									 if @NOTIFYCODE = 0
                               closewindow w6
                            endif 

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

sub MaskedEditHandler(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam),LRESULT
    pointer mask = GetWindowLong(hwnd, GWL_USERDATA)
    SELECT uMsg
           case WM_NCDESTROY
                delete mask
           CASE @IDCHAR
                if #<int>mask[wParam & 0xff] = FALSE
                   return 0
                endif
    ENDSELECT
RETURN CallWindowProcA(#<int>mask[256],hWnd,uMsg,wParam,lParam)
ENDSUB

SUB MaskEditControl(WINDOW parent,INT id,string szMask)
    HWND hEdit = GETCONTROLHANDLE(parent,id)
    LONG lpFn = GetWindowLong(hEdit, GWL_WNDPROC)
    pointer mask
    int i
    if lpFn <> &MaskedEditHandler
       mask = new(int, 257)
    else
       mask = GetWindowLong(hEdit, GWL_USERDATA)
    endif
    for i = 0 to 255
        #<int>mask[i] = FALSE
    next i
    for i = 0 to len(szMask)
        #<int>mask[szMask[i]] = TRUE
    next i
    if lpFn <> &MaskedEditHandler
       #<int>mask[256] = SetWindowLongA(hEdit,GWL_WNDPROC,&MaskedEditHandler)
       SetWindowLong(hEdit, GWL_USERDATA, mask)
    endif
ENDSUB

sub ResetScroll()
	 SENDMESSAGE(w1.hWnd,EM_GETSCROLLPOS,0,sRange,RichEdit)
    StoreLine = cLine
	 OldsRange = (sRange.Low / LineSpace) + LinesPerPage
	 Once = 0
return
endsub

sub WindowDetails(int Switch)
SwitchIn = Switch
if Switch = 2
   string TheCaption = "Subroutine details - multi select option"
endif

if Switch = 4
   TheCaption = "Window details - multi select option"
endif

OPENWINDOW w8,0,0,470,400,@MINBOX|@MAXBOX|@TOPMOST|@CAPTION,0,TheCaption,&DetailsHandler
  Setwindowcolor w8,BackColour

  CONTROL w8,@BUTTON,"",10,340,25,25,@CTLBTNBITMAP,CopySubButton 
          SETCONTROLTEXT w8,CopySubButton,GETSTARTPATH() + "\\Res\\copy2.bmp"

  CONTROL w8,@BUTTON,"",40,340,25,25,@CTLBTNBITMAP,CopySubBlockButton 
          SETCONTROLTEXT w8,CopySubBlockButton,GETSTARTPATH() + "\\Res\\block2.bmp"

  CONTROL w8,@BUTTON,"Close",377,340,80,25,0,2
          SETFONT w8,"Arial",10,500,0,2
          SETCONTROLCOLOR w8,2,RGB(0,0,0),RGB(255,255,255)

if Switch = 2
  CONTROL w8,@LISTVIEW,"",10,10,446,320,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			 SENDMESSAGE w8,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,0,"Subroutine"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,0,226
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,1,"Starts"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,1,100
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,2,"Ends"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,2,100
          SendMessage w8,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
          SendMessage w8,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
          SETFONT w8,"Arial",11,400,0,ListViewResult

          string text2,text4
			 int lvcountIn = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
			 for a = 0 to lvcountIn - 1
				  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text)
				  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text2)
				  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,2,text4)
				  CONTROLCMD w8,ListViewResult,@LVINSERTITEM,a,text
				  CONTROLCMD w8,ListViewResult,@LVSETTEXT,a,1,text2
				  CONTROLCMD w8,ListViewResult,@LVSETTEXT,a,2,text4
          next a
endif

if Switch = 4
  CONTROL w8,@LISTVIEW,"",10,10,446,320,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			 SENDMESSAGE w8,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,0,"Window"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,0,226
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,1,"Starts"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,1,110
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,2,"Ends"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,2,110
          SendMessage w8,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
          SendMessage w8,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
          SETFONT w8,"Arial",11,400,0,ListViewResult
          text2 = "" 
          text4 = ""
			 lvcountIn = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
			 for a = 0 to lvcountIn - 1
				  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text)
				  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text2)
				  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,2,text4)
				  CONTROLCMD w8,ListViewResult,@LVINSERTITEM,a,text
				  CONTROLCMD w8,ListViewResult,@LVSETTEXT,a,1,text2
				  CONTROLCMD w8,ListViewResult,@LVSETTEXT,a,2,text4
          next a
endif

WAITUNTIL IsWindowClosed(w8)

return 
endsub

SUB DetailsHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w8

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w8

           CASE @IDCONTROL
                SELECT @CONTROLID

							  case ListViewResult
									 if @NOTIFYCODE=@NMCLICK 
										 label ClickListViewResult
										 lvpos=*<NMLISTVIEW>@LPARAM.iItem
										 CONTROLCMD(w8,ListViewResult,@LVGETTEXT,lvpos,0,text)
										 'setcontroltext(w1,EDIT_1,text)
									 endif

							  case 2
									 if @NOTIFYCODE = 0
                               closewindow w8
                            endif

                       case CopySubButton
                            if @NOTIFYCODE = 0
                               if SwitchIn = 2
                                  int cnt2 = CopyMultiSubs(w1,ListView2)
                               endif
                               if SwitchIn = 4
                                  cnt2 = CopyMultiSubs(w1,ListView4)
                               endif
                               if cnt2
                                  if iswindowclosed(w8) = 0
                                     ShowConfirm(1)
                                  endif 
                               endif
                               setfocus w8
                            endif 

                       case CopySubBlockButton
                            if @NOTIFYCODE = 0
                               if SwitchIn = 2
                                  cnt2 = CopyMultiSubs(w1,ListView2,1)
                               endif
                               if SwitchIn = 4
                                  cnt2 = CopyMultiSubs(w1,ListView4,1)
                               endif
                               if cnt2
                                  if iswindowclosed(w8) = 0
                                     ShowConfirm(2)
                                  endif
                               endif
                               setfocus w8
                            endif

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

sub CopyMultiSubs(window WinIn,int id,opt int Bin),int
	 lvcountIn = CONTROLCMD(w8,ListViewResult,@LVGETCOUNT) 
	 int cnt = SendMessage(w8,LVM_GETSELECTEDCOUNT,0,0,ListViewResult)
    LineCount = 0
		  if cnt > 0
			  CutLine = ""
			  for x = 0 to lvcountIn - 1
					if CONTROLCMD(w8,ListViewResult,@LVGETSELECTED,x)
						string text2 
						CONTROLCMD(WinIn,id,@LVGETTEXT,x,0,text)
						CONTROLCMD(WinIn,id,@LVGETTEXT,x,1,text)
						CONTROLCMD(WinIn,id,@LVGETTEXT,x,2,text2)
						int StartOfSub = val(text)
						int EndOfSub = val(text2)
						for a = StartOfSub to EndOfSub
                      LineCount ++
							 CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,line$,512)
							 CutLine = CutLine + line$
						label CheckNextLine
						next a
						CutLine = CutLine + chr$(13)
                  LineCount ++
					endif
			  next x
			  CopyStringToClipboard(CutLine)
           if Bin
              SendToBlock() 
           endif
		  endif

return cnt
endsub

sub ShowConfirm(int Switch)
    if ConfirmMessage = 0 and Switch > 0 then return
    string TheCaption = ""
	 string TheMessage = ""
	 if Switch = -1
       TheCaption = "Selection"
		 TheMessage = "Select code first please"
	 endif
	 if Switch = -2
       TheCaption = "Selection"
		 TheMessage = "Select a subroutine first please"
	 endif
	 if Switch = -4
       TheCaption = "Selection"
		 TheMessage = "Select a window first please"
	 endif
	 if Switch = -6
       TheCaption = "Selection"
		 TheMessage = "Select a bookmark first please"
	 endif
	 if Switch = -11
       TheCaption = "Select a line"
		 TheMessage = "Click where you want to insert code first please"
	 endif
	 if Switch = -16
       TheCaption = "Selection"
		 TheMessage = "Pick a Select first please"
	 endif
	 if Switch = -40
       TheCaption = "Not allowed"
		 TheMessage = "Saving to your IWBDev include folder is not allowed"
	 endif
	 if Switch = -66
       TheCaption = "Select a line"
		 TheMessage = "Click the line you want to bookmark first please"
	 endif
	 if Switch = -100
       TheCaption = "Done"
		 TheMessage = "File has been re-indexed"
	 endif
	 if Switch = -110
       TheCaption = "Done"
		 TheMessage = "Undos and redos have been cleared"
	 endif
	 if Switch = -120
       TheCaption = "Please wait"
		 TheMessage = "Saving file, please wait"
	 endif
	 if Switch = 1
       TheCaption = "Done"
		 TheMessage = "Copied to clipboard"
	 endif
	 if Switch = 2
       TheCaption = "Done"
		 TheMessage = "Copied to block"
	 endif
	 if Switch = 6
       TheCaption = "Done"
		 TheMessage = "Line bookmarked"
	 endif
	 if Switch = 18
       TheCaption = "Done"
		 TheMessage = "Added to navigation"
	 endif
	 if Switch = 66
       TheCaption = "Already done"
		 TheMessage = "Line already bookmarked"
	 endif
	 if Switch = 99
       TheCaption = "Please wait"
		 TheMessage = "Please wait confirmation message..."
	 endif
	 if Switch = 100
       TheCaption = "Done"
		 TheMessage = "File has been saved"
	 endif
    OPENWINDOW w10,0,0,470,200,@TOPMOST|@CAPTION,0,TheCaption,&ConfirmHandler
    Setwindowcolor w10,WindowBackColour
    CONTROL w10,@STATIC,TheMessage,0,65,470,25,@CTEDITCENTER|0x200,4 
            SETCONTROLCOLOR w10,4,RGB(0,0,0),WindowBackColour
            SETFONT w10,"Arial",12,500,0,4
            if Switch < 1
               sleep(2000)
            else  
               sleep(1000)
            endif 
    closewindow w10
return 
endsub

SUB ConfirmHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w10

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w10

    ENDSELECT
RETURN 0
ENDSUB

sub BookmarkWindow()
    OPENWINDOW w12,0,0,470,200,@TOPMOST|@CAPTION,0,"Description",&BookmarkHandler
    Setwindowcolor w12,WindowBackColour

    CONTROL w12,@STATIC,"Add a description - optional",12,40,470,25,@CTEDITLEFT|0x200,4 
            SETCONTROLCOLOR w12,4,RGB(0,0,0),WindowBackColour
            SETFONT w12,"Arial",12,500,0,4

    CONTROL w12,@EDIT,"",10,70,440,25,@CTEDITLEFT,EDIT_1 
            SETCONTROLCOLOR w12,EDIT_1,RGB(0,0,0),rgb(255,255,255)
            SETFONT w12,"Arial",12,500,0,EDIT_1
            setcontrolnotify(w12,EDIT_1,1,1)

    CONTROL w12,@BUTTON,"OK",10,140,80,25,0,1
            SETCONTROLCOLOR w12,1,RGB(0,0,0),RGB(255,255,255)
            SETFONT w12,"Arial",10,500,0,1

    CONTROL w12,@BUTTON,"Close",377,140,80,25,0,2
            SETCONTROLCOLOR w12,2,RGB(0,0,0),RGB(255,255,255)
            SETFONT w12,"Arial",10,500,0,2
  
    setfocus w12,EDIT_1
    WAITUNTIL IsWindowClosed(w12)

return 
endsub

SUB BookmarkHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w12

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w12

           CASE @IDCONTROL
                SELECT @CONTROLID
                       case EDIT_1
                            if @NOTIFYCODE = @ENENTERKEY
                               BookMarkDesc = getcontroltext(w12,EDIT_1)
                               closewindow w12
                            endif

                       case 1
                            if @NOTIFYCODE = 0
                               BookMarkDesc = getcontroltext(w12,EDIT_1)
                               closewindow w12
                            endif 

                       case 2
                            if @NOTIFYCODE = 0
                               closewindow w12
                            endif 

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

sub WindowDelete(int Switch)

OPENWINDOW w13,0,0,470,200,@MINBOX|@MAXBOX|@TOPMOST|@CAPTION,0,"Please confirm",&DeleteHandler

if Switch = 6
    Setwindowcolor w13,WindowBackColour
endif

  uint Theme = 0
  if !CloseDown
     Theme = ScreenColour
  else
     Theme = BackColour
  endif

if Switch <> 6
  Setwindowcolor w13,Theme
endif

  CONTROL w13,@STATIC,"",0,25,470,25,@CTEDITCENTER|0x200,1
          SETFONT w13,"Arial",12,500,0,1
          if Switch <> 6
             SETCONTROLCOLOR w13,1,RGB(0,0,0),Theme
          else 
             SETCONTROLCOLOR w13,1,RGB(0,0,0),WindowBackColour
          endif

  CONTROL w13,@STATIC,"",0,60,470,25,@CTEDITCENTER|0x200,2
          SETFONT w13,"Arial",12,500,0,2
          if Switch <> 6
             SETCONTROLCOLOR w13,2,RGB(0,0,0),Theme
          else 
             SETCONTROLCOLOR w13,2,RGB(0,0,0),WindowBackColour
          endif

          if CloseDown
             select OnTab
                    case 1
								 RealTabName = getcontroltext(w1,FileTab1)
                         if instr(RealTabName,"*")
								    RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1)   
                         endif  

                    case 2
								 RealTabName = getcontroltext(w1,FileTab2)
                         if instr(RealTabName,"*")
								    RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1)   
                         endif 

                    case 3
								 RealTabName = getcontroltext(w1,FileTab3)
                         if instr(RealTabName,"*")
								    RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1)   
                         endif 

                    case 4
								 RealTabName = getcontroltext(w1,FileTab4)
                         if instr(RealTabName,"*")
								    RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1)   
                         endif 

                    case 5
								 RealTabName = getcontroltext(w1,FileTab5)
                         if instr(RealTabName,"*")
								    RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1)   
                         endif 

                    case 6
								 RealTabName = getcontroltext(w1,FileTab6)
                         if instr(RealTabName,"*")
								    RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1)   
                         endif 
             endselect

			    setcontroltext(w13,1,"Do you want to save the changes for")
			    setcontroltext(w13,2,RealTabName)
		    endif

		    if Switch = 2
			    setcontroltext(w13,1,"Are you sure you want to delete the subroutine")
			    setcontroltext(w13,2,getstring(w1,Combo2,getselected(w1,Combo2)) + "?")   
		    endif

		    if Switch = 4
			    setcontroltext(w13,1,"Are you sure you want to delete the window")
			    setcontroltext(w13,2,getstring(w1,Combo4,getselected(w1,Combo4)) + "?")   
		    endif

		    if Switch = 6
			    setcontroltext(w13,2,"Are you sure you want to clear undos and redos?")   
		    endif

  CONTROL w13,@BUTTON,"Yes",140,110,80,25,0,4
          SETFONT w13,"Arial",12,500,0,4
          if Switch <> 6
             SETCONTROLCOLOR w13,4,RGB(0,0,0),Theme
          else 
             SETCONTROLCOLOR w13,4,RGB(0,0,0),WindowBackColour
          endif

  CONTROL w13,@BUTTON,"No",240,110,80,25,0,8
          SETFONT w13,"Arial",12,500,0,8
          if Switch <> 6
             SETCONTROLCOLOR w13,8,RGB(0,0,0),Theme
          else 
             SETCONTROLCOLOR w13,8,RGB(0,0,0),WindowBackColour
          endif

			 if CloseDown > 0
			    setfocus w13,4
			 else
			    setfocus w13,8
			 endif

WAITUNTIL IsWindowClosed(w13)

return 
endsub

SUB DeleteHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w13

           CASE @IDCLOSEWINDOW
                DelConfirm = 0
                CLOSEWINDOW w13

	        case @IDKEYDOWN
		          if @CODE = 37
                   setfocus w13,4
                endif 
		          if @CODE = 39
                   setfocus w13,8
                endif   

           CASE @IDCONTROL
                SELECT @CONTROLID
                       case 4 'Yes
                            if @NOTIFYCODE = 0
                               DelConfirm = 1
                               closewindow w13
                            endif 

                       case 8 'No
                            if @NOTIFYCODE = 0
                               DelConfirm = 0
                               closewindow w13
                            endif 

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

sub AddToCombo16()
	 int lvcountIn = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
	 for a = 0 to lvcountIn - 1
		  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,3,text)
		  int combocountIn = getstringcount(w1,Combo16)
		  int alreadyadded = 0 
		  for b = 0 to combocountin - 1
				if getstring(w1,Combo16,b) = text
					alreadyadded = 1
					breakfor
				endif
		  next b 
		  if alreadyadded = 0
			  addstring w1,Combo16,text
		  endif
	 next a
return
endsub

sub JumpLineUser(int EditIn,opt int Bin)
	 FocusMain()
	 if Bin
		 int bm = val(getstring(w1,Combo6,getselected(w1,Combo6))) 
		 sRange.Low = (bm * LineSpace) - LineSpace
		 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
		 setscrollpos(w1,ScrollBar,bm)
	 else
		 sRange.Low = ((val(getcontroltext w1,EditIn)) * LineSpace) '- LineSpace
		 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
		 setscrollpos(w1,ScrollBar,val(getcontroltext w1,EditIn))
	 endif

	 StartAt = CONTROLCMD(w1,RichEdit,@RTCHARFROMLINE,sRange)
	 setfocus w1,RichEdit
	 CONTROLCMD w1,RichEdit,@RTSETSELECTION,StartAt,StartAt
	 ppos = GETCARETPOSITION w1,AcrossX,DownY
	 lvX = AcrossX
	 lvY = DownY
	 if kw = 0
		 setsize w1,lvX+58,lvY+98,300,38,ListView
	 endif
	 AcrossX --
	 AcrossX = AcrossX / 8
	 AcrossX ++
	 EditPos = CONTROLCMD(w1,RichEdit,@RTCHARFROMLINE,cLine-1)
	 EditPos = EditPos + AcrossX
	 ColourText()
	 
	 StoreLine = val(getcontroltext w1,EditIn)
	 setscrollpos(w1,ScrollBar,StoreLine)
	 sRange.Low = (getscrollpos(w1,ScrollBar) * LineSpace) - LineSpace
	 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
	 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

	 for a = 1 to 30
		  setcontroltext(w1,a+1000,str$(FirstVisLine+(a-1)))
        SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour 
	 next a

	 if getcontroltext(w1,EditIn) = ""
		 for a = 1 to 30
			  setcontroltext(w1,a+1000,str$(a))
		 next a
	 endif 

	 if !Bin
		 setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
		 SETCONTROLCOLOR w1,1001,Red,BackColour
		 setfocus w1,EditIn
	 endif
return
endsub

sub StartUp()
	 WordCount = 0
	 y = 0
    x = GetLines()
	 SETSCROLLRANGE w1,ScrollBar,0,x
	 SETSCROLLPOS w1, -2, 0

    'Load controls
    setcontroltext w1,RichEdit,ClipText 'Load file into the rich edit
    if instr(getcontroltext(w1,1001),">") = 0
       setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
    endif
    GetFileName(w1,0,ProgPath,1)
    setcaption w1,FileNameIs + ProgramTitle
    FileNameIs = mid$(getcaption(w1),1,instr(getcaption(w1),ProgramTitle)-1)
    SETCONTROLCOLOR w1,1001,Red,BackColour
    setcontroltext(w1,EDIT_1,ltrim$(str$(StartUpAt)))
	 setcaption w1,FileNameIs + ProgramTitle
    setfocus w1,RichEdit

    StoreLine = cLine
    Skip = 1
    CreateDetailsFile()
return
endsub

sub ClearEditor()

    setcontroltext(w1,RichEdit,"")

	 for a = 1 to LinesPerPage
        setcontroltext(w1,a+1000,ltrim$(str$(a)))
	 next a

    setscrollpos(w1,ScrollBar,0)

    setcaption w1,"" + ProgramTitle

    CONTROLCMD(w1,ListView2,@LVDELETEALL)
    CONTROLCMD(w1,ListView4,@LVDELETEALL)
    CONTROLCMD(w1,ListView6,@LVDELETEALL)
    CONTROLCMD(w1,ListView8,@LVDELETEALL)
    CONTROLCMD(w1,ListView10,@LVDELETEALL)

    SendMessage(GetDlgItem(w1.hwnd,Combo2),CB_RESETCONTENT,0,0)
    SendMessage(GetDlgItem(w1.hwnd,Combo4),CB_RESETCONTENT,0,0)
    SendMessage(GetDlgItem(w1.hwnd,Combo6),CB_RESETCONTENT,0,0)
    SendMessage(GetDlgItem(w1.hwnd,Combo8),CB_RESETCONTENT,0,0)
    SendMessage(GetDlgItem(w1.hwnd,Combo10),CB_RESETCONTENT,0,0)
    SendMessage(GetDlgItem(w1.hwnd,Combo12),CB_RESETCONTENT,0,0)
    SendMessage(GetDlgItem(w1.hwnd,Combo14),CB_RESETCONTENT,0,0)
    SendMessage(GetDlgItem(w1.hwnd,Combo16),CB_RESETCONTENT,0,0)
    SendMessage(GetDlgItem(w1.hwnd,Combo18),CB_RESETCONTENT,0,0)
    SendMessage(GetDlgItem(w1.hwnd,Combo88),CB_RESETCONTENT,0,0)

    showwindow w1,@SWHIDE,NavBackButton
    showwindow w1,@SWSHOW,NavBackGrey
    showwindow w1,@SWHIDE,NavForwardButton
    showwindow w1,@SWSHOW,NavForwardGrey

    return
endsub

sub DoMinimise(opt int Switch)
	 string CloseLine = ltrim$(getcontroltext(w1,1001))
	 if instr(CloseLine,">")
		 CloseLine = mid$(CloseLine,instr(CloseLine,">")+3,len(CloseLine))
	 endif
    if Switch = 1 then ProgPath = RecentProgs[1]
    if Switch = 2 then ProgPath = RecentProgs[2]
    if Switch = 3 then ProgPath = RecentProgs[3]
    if Switch = 4 then ProgPath = RecentProgs[4]
    if Switch = 5 then ProgPath = RecentProgs[5]
    if Switch = 6 then ProgPath = RecentProgs[6]
    GetFileName(w1,0,ProgPath,1)
    CreateDetailsFile()
	 ClearEditor()
    if !Switch
	    DoSaveToTab()
    endif
	 ClearEditor()
return
endsub

sub DoRestore(int Switch,opt int TabName)
Loading = 1
    if Switch = 1 then goto LoadFromFile
    if InitialLoad = 1
       setcontroltext(w1,RichEdit,buffer1)
       goto LoadFromFile
    endif
    if TabName = 1
       setcontroltext(w1,RichEdit,buffer1)
    endif
    if TabName = 2
       setcontroltext(w1,RichEdit,buffer2) 
    endif
    if TabName = 3
       setcontroltext(w1,RichEdit,buffer3)
''print "h4 ",FileNameIs 
    endif
    if TabName = 4
       setcontroltext(w1,RichEdit,buffer4) 
    endif
    if TabName = 5
       setcontroltext(w1,RichEdit,buffer5) 
    endif
    if TabName = 6
       setcontroltext(w1,RichEdit,buffer6) 
    endif

    label LoadFromFile
	 string MainNameD = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 string StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".pth"
	 if openfile(MyFile2,StoreBookFileD,"R") = 0
		 read MyFile2,dIn 
	 endif
	 closefile MyFile2
	 ProgPath = dIn

	 GetFileName(w1,0,ProgPath,1)
	 setcaption w1,FileNameIs + ProgramTitle

	 MainNameD = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".txt"
    int AddBackIn = 0
    int LineRead = 0
    string text2,text3,text4
	 if openfile(MyFile2,StoreBookFileD,"R") = 0
       do
          read Myfile2,dIn

             'Get Sub routines
				 if instr(dIn,":lv2")      
					 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
             endif

             if AddBackIn = 0
                break
             endif

             if AddBackIn > 0
					  LineRead ++
					  read MyFile,dIn 
					  text  = mid$(dIn,1,instr(dIn,"|")-1)
					  text2 = mid$(dIn,instr(dIn,"|")+1,len(dIn))
					  text2 = mid$(text2,1,instr(text2,"!")-1)
					  text3 = mid$(dIn,instr(dIn,"!")+1,len(dIn))

                 ConDrawOn(w1,ListView2)
                 ConDrawOn(w1,Combo2)
					  if !instr(text,":")
						  int position = CONTROLCMD(w1,ListView2,@LVFINDITEM,text)
                    if position = -1
						     CONTROLCMD w1,ListView2,@LVINSERTITEM,a,text
						     CONTROLCMD w1,ListView2,@LVSETTEXT,position,1,text2
						     CONTROLCMD w1,ListView2,@LVSETTEXT,position,2,text3
						     ADDSTRING w1,Combo2,text
                    endif 
					  endif
                 ConDrawOn(w1,ListView2)
                 ConDrawOn(w1,Combo2)
             endif
 
       until LineRead > AddBackIn or EOF(MyFile2)

       'Get Windows 
       if !EOF(MyFile2)
			 AddBackIn = 0
			 LineRead = 0
			 do
				 read Myfile2,dIn
					 if instr(dIn,":lv4")      
						 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
					 endif

                if AddBackIn = 0
                   break
                endif

					 if AddBackIn > 0
						  LineRead ++
						  read MyFile,dIn 
						  text  = mid$(dIn,1,instr(dIn,"|")-1)
						  text2 = mid$(dIn,instr(dIn,"|")+1,len(dIn))
						  text2 = mid$(text2,1,instr(text2,"!")-1)
						  text3 = mid$(dIn,instr(dIn,"!")+1,len(dIn))
						  text3 = mid$(text3,1,instr(text3,"#")-1)
						  text4 = mid$(dIn,instr(dIn,"#")+1,len(dIn))
                          ConDrawOff(w1,ListView4)
                          ConDrawOff(w1,Combo4)
						  if !instr(text,":")
							  position = CONTROLCMD(w1,ListView4,@LVFINDITEM,text)
                       If position = -1 
							     CONTROLCMD w1,ListView4,@LVINSERTITEM,a,text
							     CONTROLCMD w1,ListView4,@LVSETTEXT,position,1,text2
							     CONTROLCMD w1,ListView4,@LVSETTEXT,position,2,text3
							     CONTROLCMD w1,ListView4,@LVSETTEXT,position,3,text4
							     ADDSTRING w1,Combo4,text
                       endif
						  endif
                    ConDrawOn(w1,ListView4)
                    ConDrawOn(w1,Combo4)
					 endif
			 until LineRead > AddBackIn or EOF(MyFile2)
       endif

       'Get Selects
       if !EOF(MyFile2)
			 AddBackIn = 0
			 LineRead = 0
          string LastEntry = ""
			 do
				 read Myfile2,dIn
					 if instr(dIn,":lv8")      
						 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
					 endif

                if AddBackIn = 0
                   break
                endif

					 if AddBackIn > 0
						 LineRead ++
						 read MyFile,dIn 
						 text  = mid$(dIn,1,instr(dIn,"|")-1)
						 text2 = mid$(dIn,instr(dIn,"|")+1,len(dIn))
						 text2 = mid$(text2,1,instr(text2,"!")-1)
						 text3 = mid$(dIn,instr(dIn,"!")+1,len(dIn))
						 text3 = mid$(text3,1,instr(text3,"#")-1)
						 text4 = mid$(dIn,instr(dIn,"#")+1,len(dIn))
                   ConDrawOff(w1,ListView8)
                   ConDrawOff(w1,Combo8)
						 if !instr(text,":")
							 CONTROLCMD w1,ListView8,@LVINSERTITEM,a,text
							 position = CONTROLCMD(w1,ListView8,@LVFINDITEM,text)
							 CONTROLCMD w1,ListView8,@LVSETTEXT,position,1,text2
							 CONTROLCMD w1,ListView8,@LVSETTEXT,position,2,text3
							 CONTROLCMD w1,ListView8,@LVSETTEXT,position,3,text4
						 endif
                   ConDrawOn(w1,ListView8)
                   ConDrawOn(w1,Combo8)
					 endif
			 until LineRead > AddBackIn or EOF(MyFile2)
          AddToCombo16()
       endif

       'Get Bookmarks 
       if !EOF(MyFile2) and getstringcount(w1,Combo6) = 0
			 AddBackIn = 0
			 LineRead = 0
			 do
				 read Myfile2,dIn
					 if instr(dIn,":bmk")
                   int ResetCount = -1      
						 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
					 endif

                if AddBackIn = 0
                   break
                endif

					 if AddBackIn > 0
						  LineRead ++
						  read MyFile,dIn
                    ConDrawOff(w1,ListView6)
					     if !instr(dIn,":")
                       if ltrim$(rtrim$(dIn)) <> "" 
                          ResetCount ++
                          insertstring w1,Combo6,ResetCount,dIn
                       endif
                       if instr(dIn," ")
                          string StringLineNo = mid$(dIn,1,instr(dIn," ")-1)
                          string BookMarkDesc = mid$(dIn,instr(dIn," ")+1,len(dIn))
                       else
                          StringLineNo = dIn
                          BookMarkDesc = ""
                       endif
					        CONTROLCMD w1,ListView6,@LVINSERTITEM,ResetCount,StringLineNo
							  position = CONTROLCMD(w1,ListView6,@LVFINDITEM,StringLineNo)
							  CONTROLCMD w1,ListView6,@LVSETTEXT,position,1,BookMarkDesc
                    endif 
                    ConDrawOn(w1,ListView6)
					 endif
			 until LineRead > AddBackIn or EOF(MyFile2)
         
          AddToBookStore()

       endif

       'Get Includes 
       if !EOF(MyFile2)
			 AddBackIn = 0
			 LineRead = 0
          ConDrawOff(w1,Combo88)
			 do
				 read Myfile2,dIn
					 if instr(dIn,":inc")      
						 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
					 endif

                if AddBackIn = 0
                   break
                endif

					 if AddBackIn > 0
						  LineRead ++
						  read MyFile,dIn
					     if !instr(dIn,":")
                       ADDSTRING w1,Combo88,dIn
                    endif 
					 endif
			 until LineRead > AddBackIn or EOF(MyFile2)
          ConDrawOn(w1,Combo88)
       endif 

       'Get scroll range
       int scMin,scMax
       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":sr")      
				 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
				 read MyFile,dIn 
				 scMin = AddBackIn
				 scMax = val(mid$(dIn,instr(dIn,"!")+1,len(dIn)))
             if scMax = 0
                scMax = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
                setscrollrange(w1,ScrollBar,scMin,scMax)
             else
                setscrollrange(w1,ScrollBar,scMin,scMax)
             endif
			 endif
       endif

       'User go to lines
       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":u1")      
				 string AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn 
             if AddBackInS <> "0"
                setcontroltext(w1,EDIT_11,ltrim$(AddBackInS))
                showwindow w1,@SWSHOW,BUTTON_4
             else
                setcontroltext(w1,EDIT_11,"")
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":u2")      
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn 
             if AddBackInS <> "0"
                setcontroltext(w1,EDIT_111,ltrim$(AddBackInS))
                showwindow w1,@SWSHOW,BUTTON_44
             else
                setcontroltext(w1,EDIT_111,"")
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":u3")      
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn 
             if AddBackInS <> "0"
                setcontroltext(w1,EDIT_1111,ltrim$(AddBackInS))
                showwindow w1,@SWSHOW,BUTTON_444
             else
                setcontroltext(w1,EDIT_1111,"")
             endif
			 endif
       endif

       'Sub routines selections etc
       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c2")      
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn 
             if AddBackInS <> "!"
                setselected(w1,Combo2,val(AddBackInS))
             else
                setselected(w1,Combo2,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c4")      
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn 
             if AddBackInS <> "!"
                setselected(w1,Combo4,val(AddBackInS))
             else
                setselected(w1,Combo4,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c6")      
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn 
             if AddBackInS <> "!"
                setselected(w1,Combo6,val(AddBackInS))
             else
                setselected(w1,Combo6,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c8")      
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn 
             if AddBackInS <> "!"
                setselected(w1,Combo8,val(AddBackInS))
             else
                setselected(w1,Combo8,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c10")      
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn 
             if AddBackInS <> "!"
                setselected(w1,Combo10,val(AddBackInS))
             else
                setselected(w1,Combo10,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c12")      
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn 
             if AddBackInS <> "!"
                setselected(w1,Combo12,val(AddBackInS))
             else
                setselected(w1,Combo12,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c14")      
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn 
             if AddBackInS <> "!"
                setselected(w1,Combo14,val(AddBackInS))
             else
                setselected(w1,Combo14,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c16")  
             'setcontroltext(w1,CaseStatic,"Cases")    
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn 
             if AddBackInS <> "!"
                setselected(w1,Combo16,val(AddBackInS))
                DoSelect16()
                DoCombo8() 
             else
                setselected(w1,Combo16,-1)
             endif
			 endif
       endif

       'Get scroll position
       int scPos
       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":sp")      
				 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
				 read MyFile,dIn 
				 scPos = AddBackIn
             setcontroltext(w1,EDIT_1,ltrim$(str$(scPos)))
             cLine = scPos
             StoreLine = cLine
             ScrollPoint = cLine
          else
             setcontroltext(w1,EDIT_1,"1")
             cLine = 1
             StoreLine = cLine
             ScrollPoint = 1
			 endif
       endif

       'Get Places 
       if !EOF(MyFile2) and getstringcount(w1,Combo18) = 0
			 AddBackIn = 0
			 LineRead  = 0
			 do
				 read Myfile2,dIn
					 if instr(dIn,":nav")
                   ResetCount = -1
						 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
					 endif

                if AddBackIn = 0
                   break
                endif

					 if AddBackIn > 0
						  LineRead ++
						  read MyFile,dIn
					     if !instr(dIn,":")
                       if ltrim$(rtrim$(dIn)) <> ""
                          ResetCount ++
                          insertstring w1,Combo18,ResetCount,dIn
                       endif
                    endif 
					 endif
			 until LineRead > AddBackIn or EOF(MyFile2)

          AddToNavStore()   
          
          if getstringcount(w1,Combo18) > 0
		       showwindow w1,@SWSHOW,NavBackButton
		       showwindow w1,@SWSHOW,NavForwardButton
		       showwindow w1,@SWHIDE,NavBackGrey
		       showwindow w1,@SWHIDE,NavForwardGrey
          endif

          if getstringcount(w1,Combo18) > 1
		       showwindow w1,@SWSHOW,NavBackButton
		       showwindow w1,@SWHIDE,NavBackGrey
          endif

          NavMax = getstringcount(w1,Combo18)
          NavPos = NavMax

       endif 

    endif
    closefile MyFile2

    'Load bookmarks
    Load_Bookmarks()

	 'Load text and controls
	 if instr(getcontroltext(w1,1001),">") = 0
		 setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
	 endif
	 GetFileName(w1,0,ProgPath,1)
	 setcaption w1,FileNameIs + ProgramTitle
	 SETCONTROLCOLOR w1,1001,Red,BackColour
	 setcaption w1,FileNameIs + ProgramTitle

    InitialLoadDisplay()

	 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
	 QuietMode(1)
	 for a = FirstVisLine to FirstVisLine + LinesPerPage
		  char_index = CONTROLCMD (w1,RichEdit,@RTCHARFROMLINE,a-1)
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.ClipText,512)
		  ColourLineP(rHandle,a-1,char_index)
	 next a
    QuietMode(0)

    Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
    SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset)
    setfocus w1,RichEdit

	 StoreLine = cLine
	 Skip = 1
    Mod = 0
Loading = 0
return
endsub

sub FileOpenedBefore(),int
    GetFileName(w1,0,ProgPath,1)
    int OpenedBefore = 0
	 string MainNameD = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 string StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".txt"
    int AddBackIn = 0
    int LineRead = 0
	 if openfile(MyFile2,StoreBookFileD,"R") = 0
       closefile MyFile2
       OpenedBefore = 1
    endif

return OpenedBefore
endsub

sub RecentFiles()
    ProgCount = 0
	 if openfile(MyFile2,getstartpath + "\\Res\\"+ "xeditor4.ini","R") = 0
       do 
           read MyFile2,dIn
           if dIn <> "" and mid$(dIn,1,1) <> "!"
              ProgCount ++   
              RecentProgs[ProgCount] = dIn
           endif
           if mid$(dIn,1,1) = "!"
              InitialTab = val(mid$(dIn,2,1))
              OnTab = InitialTab
           endif 
       until EOF(MyFile2)
    endif
    closefile MyFile2
  
    string StoreFileName = FileNameIs
    string StoreProgPath = ProgPath
    if ProgCount > 0
       if RecentProgs[1]<> ""
          ProgPath = RecentProgs[1]
          GetFileName(w1,0,ProgPath,1)
          RecentName[1] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             showwindow w1,@SWSHOW,FileTab1
             setcontroltext(w1,FileTab1,FileNameIs)
		       x = GetLines(1)
             buffer1 = ClipText
          'endif
       endif
       if RecentProgs[2]<> ""
          ProgPath = RecentProgs[2]
          GetFileName(w1,0,ProgPath,1)
          RecentName[2] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             showwindow w1,@SWSHOW,FileTab2
             setcontroltext(w1,FileTab2,FileNameIs)
		       x = GetLines(1)
             buffer2 = ClipText
          'endif
       endif
       if RecentProgs[3]<> ""
          ProgPath = RecentProgs[3]
          GetFileName(w1,0,ProgPath,1)
          RecentName[3] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             showwindow w1,@SWSHOW,FileTab3
             setcontroltext(w1,FileTab3,FileNameIs)
		       x = GetLines(1)
             buffer3 = ClipText
          'endif
       endif
       if RecentProgs[4]<> ""
          ProgPath = RecentProgs[4]
          GetFileName(w1,0,ProgPath,1)
          RecentName[4] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             showwindow w1,@SWSHOW,FileTab4
             setcontroltext(w1,FileTab4,FileNameIs)
		       x = GetLines(1)
             buffer4 = ClipText
          'endif
       endif
       if RecentProgs[5]<> ""
          ProgPath = RecentProgs[5]
          GetFileName(w1,0,ProgPath,1)
          RecentName[5] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             showwindow w1,@SWSHOW,FileTab5
             setcontroltext(w1,FileTab5,FileNameIs)
		       x = GetLines(1)
             buffer5 = ClipText
          'endif
       endif
       if RecentProgs[6]<> ""
          ProgPath = RecentProgs[6]
          GetFileName(w1,0,ProgPath,1)
          RecentName[6] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             showwindow w1,@SWSHOW,FileTab6
             setcontroltext(w1,FileTab6,FileNameIs)
		       x = GetLines(1)
             buffer6 = ClipText
          'endif
       endif
    endif

    ProgPath = StoreProgPath
    FileNameIs = StoreFileName
    TabTaken = ProgCount

return
endsub

sub BackupWindow()
    Confirm = 0
    string TimeString = mid$(time$,1,2)
    TimeString = Timestring + "-" + mid$(time$,4,2)
    BackupDesc = mid$(FileNameIs,1,instr(FileNameIs,".")-1) + "-" + date$ + "-at-" + TimeString + mid$(FileNameIs,instr(FileNameIs,"."),len(FileNameIs))
    OPENWINDOW w15,0,0,470,200,@TOPMOST|@CAPTION,0,"Backup file name",&BackupHandler
    Setwindowcolor w15,WindowBackColour

    CONTROL w15,@STATIC,"Backup file name",12,40,470,25,@CTEDITLEFT|0x200,4 
            SETCONTROLCOLOR w15,4,RGB(0,0,0),WindowBackColour
            SETFONT w15,"Arial",12,500,0,4

    CONTROL w15,@EDIT,"",10,70,440,25,@CTEDITLEFT,EDIT_1 
            SETCONTROLCOLOR w15,EDIT_1,RGB(0,0,0),rgb(255,255,255)
            SETFONT w15,"Arial",12,500,0,EDIT_1
            setcontrolnotify(w15,EDIT_1,1,1)
            setcontroltext(w15,EDIT_1,BackupDesc)

    CONTROL w15,@BUTTON,"Save",10,140,80,25,0,1
            SETCONTROLCOLOR w15,1,RGB(0,0,0),RGB(255,255,255)
            SETFONT w15,"Arial",10,500,0,1

    CONTROL w15,@BUTTON,"Cancel",377,140,80,25,0,2
            SETCONTROLCOLOR w15,2,RGB(0,0,0),RGB(255,255,255)
            SETFONT w15,"Arial",10,500,0,2
  
    setfocus w15,EDIT_1
    WAITUNTIL IsWindowClosed(w15)

return 
endsub

SUB BackupHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w15

           CASE @IDCLOSEWINDOW
                Confirm = 0
                CLOSEWINDOW w15

           CASE @IDCONTROL
                SELECT @CONTROLID
                       case EDIT_1
                            if @NOTIFYCODE = @ENENTERKEY
                               if rtrim$(ltrim$(getcontroltext(w15,EDIT_1))) <> ""
											 Confirm = 1
											 BackupDesc = getcontroltext(w15,EDIT_1)
											 closewindow w15
                               else
                                  setfocus w15,EDIT_1
                               endif
                            endif

                       case 1
                            if @NOTIFYCODE = 0
                               if rtrim$(ltrim$(getcontroltext(w15,EDIT_1))) <> ""
											 Confirm = 1
											 BackupDesc = getcontroltext(w15,EDIT_1)
											 closewindow w15
                               else
                                  setfocus w15,EDIT_1
                               endif
                            endif 

                       case 2
                            if @NOTIFYCODE = 0
                               Confirm = 0
                               closewindow w15
                            endif 

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

sub DoSelect16()
	 SendMessage(GetDlgItem(w1.hwnd,Combo8),CB_RESETCONTENT,0,0)
	 int SelectThis = 0
	 int AddStringCount = -1 
	 lvcountIn = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
	 for a = 0 to lvcountIn - 1
		  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,3,text)
		  if text = getstring(w1,Combo16,getselected(w1,Combo16))
			  string text2
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,0,text2)
			  addstring(w1,Combo8,text2 + " - " + ltrim$(str$(a)))
			  AddStringCount ++ 
			  if ucase$(text2) = DefaultSelect and SelectThis = 0
				  SelectThis = AddStringCount
			  endif
		  endif
	 next a

	 setselected w1,Combo8,SelectThis

	 setcontroltext(w1,EDIT_4,"")
	 setselected(w1,Combo14,-1)
	 string SelectedSelect = getstring(w1,Combo8,getselected(w1,Combo8))
	 string Combo14String = SelectedSelect
	 int Combo14Select = instr(Combo14String,"-") + 2
	 string Combo10Pos$ = mid$(Combo14String,Combo14Select,len(Combo14String))
	 int GetThis = val(Combo10Pos$)
	 lvcountIn = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
	 if lvcountIn > 0
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,0,TextInName)
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,1,TextIn1)
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,2,TextIn2)
		 setselected(w1,Combo10,-1)
		 Combo10Add()
	 endif 
	 setfocus w1
return
endsub

sub DoCombo8()
	 setcontroltext(w1,EDIT_4,"")
	 setselected(w1,Combo14,-1)
	 string SelectedSelect = getstring(w1,Combo8,getselected(w1,Combo8))
	 string Combo14String = SelectedSelect
	 int Combo14Select = instr(Combo14String,"-") + 2
	 string Combo10Pos$ = mid$(Combo14String,Combo14Select,len(Combo14String))
	 int GetThis = val(Combo10Pos$)
	 int lvcountIn = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
	 if lvcountIn > 0
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,0,TextInName)
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,1,TextIn1)
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,2,TextIn2)
	 'endif 
	 setselected(w1,Combo10,-1)
	 Combo10Add()
	 setselected(w1,Combo10,0)
	 endif
	 setfocus w1
return
endsub

sub LoadTab(int Switch)
	 enablecontrol (w1,FileTab1,0)
	 enablecontrol (w1,FileTab2,0)
	 enablecontrol (w1,FileTab3,0)
	 enablecontrol (w1,FileTab4,0)
	 enablecontrol (w1,FileTab5,0)
	 enablecontrol (w1,FileTab6,0)
	 
	 ResetScroll()

	 if cLine = 0
		 cLine = 1
		 StoreLine = 1
	 endif

    if Switch = 1
		 if getcontroltext(w1,FileTab1) <> ""
			 OnTab = 1
			 if !instr(getcaption(w1),getcontroltext(w1,FileTab1))
				 stoptimer w1,MainTimer

				 if instr(getcontroltext(w1,FileTab2),"*")
					 RealTabName = getcontroltext(w1,FileTab2)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab2)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer2 = ""
					 buffer2 = getcontroltext(w1,RichEdit)
					 DoMinimise(2)
				 endif
				 if instr(getcontroltext(w1,FileTab3),"*")
					 RealTabName = getcontroltext(w1,FileTab3)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab3)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer3 = ""
					 buffer3 = getcontroltext(w1,RichEdit)
					 DoMinimise(3)
				 endif
				 if instr(getcontroltext(w1,FileTab4),"*")
					 RealTabName = getcontroltext(w1,FileTab4)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab4)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer4 = ""
					 buffer4 = getcontroltext(w1,RichEdit)
					 DoMinimise(4)
				 endif
				 if instr(getcontroltext(w1,FileTab5),"*")
					 RealTabName = getcontroltext(w1,FileTab5)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab5)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer5 = ""
					 buffer5 = getcontroltext(w1,RichEdit)
					 DoMinimise(5)
				 endif
				 if instr(getcontroltext(w1,FileTab6),"*")
					 RealTabName = getcontroltext(w1,FileTab6)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab6)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer6 = ""
					 buffer6 = getcontroltext(w1,RichEdit)
					 DoMinimise(6)
				 endif
				 FileNameIs = getcontroltext(w1,FileTab1)
             if instr(FileNameIs,"*")
                FileNameIs = mid$(FileNameIs,1,instr(FileNameIs,"*")-1)
             endif
				 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 if Tab1Loaded = 0
					 ProgPath = RecentProgs[1]
					 GetFileName(w1,0,ProgPath,1)
					 setcontroltext(w1,FileTab1,FileNameIs)
					 DoOpen(1)
					 Tab1Loaded = 1 
					 setcontroltext(w1,FileTab1,FileNameIs)
                buffer1 = ""
                buffer1 = getcontroltext(w1,RichEdit)  
                OnTab = 1
                goto EndOfSub
				 else
                OnTab = 1 
                Tab1Loaded = 1
					 DoRestore(0,1)
					 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),BlueButton
					 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                goto EndOfSub
				 endif
			 endif
			 DoRestore(0,1)
			 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
		 endif
    endif
    if Switch = 2
		 if getcontroltext(w1,FileTab2) <> ""
			 OnTab = 2
			 if !instr(getcaption(w1),getcontroltext(w1,FileTab2))
				 if instr(getcontroltext(w1,FileTab1),"*")
					 RealTabName = getcontroltext(w1,FileTab1)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab1)
				 endif
				 if instr(getcaption(w1),RealTabName)
					 buffer1 = ""
					 buffer1 = getcontroltext(w1,RichEdit)
					 DoMinimise(1)
				 endif
				 if instr(getcontroltext(w1,FileTab3),"*")
					 RealTabName = getcontroltext(w1,FileTab3)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab3)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer3 = ""
					 buffer3 = getcontroltext(w1,RichEdit)
					 DoMinimise(3)
				 endif
				 if instr(getcontroltext(w1,FileTab4),"*")
					 RealTabName = getcontroltext(w1,FileTab4)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab4)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer4 = ""
					 buffer4 = getcontroltext(w1,RichEdit)
					 DoMinimise(4)
				 endif
				 if instr(getcontroltext(w1,FileTab5),"*")
					 RealTabName = getcontroltext(w1,FileTab5)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab5)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer5 = ""
					 buffer5 = getcontroltext(w1,RichEdit)
					 DoMinimise(5)
				 endif
				 if instr(getcontroltext(w1,FileTab6),"*")
					 RealTabName = getcontroltext(w1,FileTab6)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab6)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer6 = ""
					 buffer6 = getcontroltext(w1,RichEdit)
					 DoMinimise(6)
				 endif
				 FileNameIs = getcontroltext(w1,FileTab2)
             if instr(FileNameIs,"*")
                FileNameIs = mid$(FileNameIs,1,instr(FileNameIs,"*")-1)
             endif
				 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 if Tab2Loaded = 0
					 ProgPath = RecentProgs[2]
					 GetFileName(w1,0,ProgPath,1)
					 setcontroltext(w1,FileTab2,FileNameIs)
					 DoOpen(1)
					 Tab2Loaded = 1 
					 setcontroltext(w1,FileTab2,FileNameIs)
                buffer2 = ""
                buffer2 = getcontroltext(w1,RichEdit)  
                OnTab = 2
                goto EndOfSub 
				 else
                OnTab = 2 
                Tab2Loaded = 1
					 DoRestore(0,2)
					 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),BlueButton
					 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                goto EndOfSub
				 endif
			 endif
			 DoRestore(0,2)
			 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
		 endif
    endif
    if Switch = 3
		 if getcontroltext(w1,FileTab3) <> ""
			 OnTab = 3
			 if !instr(getcaption(w1),getcontroltext(w1,FileTab3))
				 if instr(getcontroltext(w1,FileTab1),"*")
					 RealTabName = getcontroltext(w1,FileTab1)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab1)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer1 = ""
					 buffer1 = getcontroltext(w1,RichEdit)
					 DoMinimise(1)
				 endif
				 if instr(getcontroltext(w1,FileTab2),"*")
					 RealTabName = getcontroltext(w1,FileTab2)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab2)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer2 = ""
					 buffer2 = getcontroltext(w1,RichEdit)
					 DoMinimise(2)
				 endif
				 if instr(getcontroltext(w1,FileTab4),"*")
					 RealTabName = getcontroltext(w1,FileTab4)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab4)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer4 = ""
					 buffer4 = getcontroltext(w1,RichEdit)
					 DoMinimise(4)
				 endif
				 if instr(getcontroltext(w1,FileTab5),"*")
					 RealTabName = getcontroltext(w1,FileTab5)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab5)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer5 = ""
					 buffer5 = getcontroltext(w1,RichEdit)
					 DoMinimise(5)
				 endif
				 if instr(getcontroltext(w1,FileTab6),"*")
					 RealTabName = getcontroltext(w1,FileTab6)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab6)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer6 = ""
					 buffer6 = getcontroltext(w1,RichEdit)
					 DoMinimise(6)
				 endif
				 FileNameIs = getcontroltext(w1,FileTab3)
             if instr(FileNameIs,"*")
                FileNameIs = mid$(FileNameIs,1,instr(FileNameIs,"*")-1)
             endif
				 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 if Tab3Loaded = 0
					 ProgPath = RecentProgs[3]
					 GetFileName(w1,0,ProgPath,1)
					 setcontroltext(w1,FileTab3,FileNameIs)
					 DoOpen(1)
					 Tab3Loaded = 1 
					 setcontroltext(w1,FileTab3,FileNameIs)
                buffer3 = ""
                buffer3 = getcontroltext(w1,RichEdit) 
                OnTab = 3
                goto EndOfSub
				 else
                OnTab = 3 
                Tab3Loaded = 1
					 DoRestore(0,3)
					 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),BlueButton
					 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                goto EndOfSub
				 endif
			 endif
          DoRestore(0,3)
			 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
		 endif
    endif
    if Switch = 4
		 if getcontroltext(w1,FileTab4) <> ""
			 OnTab = 4
			 if !instr(getcaption(w1),getcontroltext(w1,FileTab4))
				 if instr(getcontroltext(w1,FileTab2),"*")
					 RealTabName = getcontroltext(w1,FileTab1)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab1)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer1 = ""
					 buffer1 = getcontroltext(w1,RichEdit)
					 DoMinimise(1)
				 endif
				 if instr(getcontroltext(w1,FileTab2),"*")
					 RealTabName = getcontroltext(w1,FileTab2)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab2)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer2 = ""
					 buffer2 = getcontroltext(w1,RichEdit)
					 DoMinimise(2)
				 endif
				 if instr(getcontroltext(w1,FileTab3),"*")
					 RealTabName = getcontroltext(w1,FileTab3)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab3)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer3 = ""
					 buffer3 = getcontroltext(w1,RichEdit)
					 DoMinimise(3)
				 endif
				 if instr(getcontroltext(w1,FileTab5),"*")
					 RealTabName = getcontroltext(w1,FileTab5)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab5)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer5 = ""
					 buffer5 = getcontroltext(w1,RichEdit)
					 DoMinimise(5)
				 endif
				 if instr(getcontroltext(w1,FileTab6),"*")
					 RealTabName = getcontroltext(w1,FileTab6)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab6)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer6 = ""
					 buffer6 = getcontroltext(w1,RichEdit)
					 DoMinimise(6)
				 endif
				 FileNameIs = getcontroltext(w1,FileTab4)
             if instr(FileNameIs,"*")
                FileNameIs = mid$(FileNameIs,1,instr(FileNameIs,"*")-1)
             endif
				 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 if Tab4Loaded = 0
					 ProgPath = RecentProgs[4]
					 GetFileName(w1,0,ProgPath,1)
					 setcontroltext(w1,FileTab4,FileNameIs)
					 DoOpen(1)
					 Tab4Loaded = 1 
					 setcontroltext(w1,FileTab4,FileNameIs)
                buffer4 = ""
                buffer4 = getcontroltext(w1,RichEdit)  
                OnTab = 4
                goto EndOfSub
				 else
                OnTab = 4 
                Tab4Loaded = 1
					 DoRestore(0,4)
					 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),BlueButton
					 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                goto EndOfSub
				 endif
			 endif
			 DoRestore(0,4)
			 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
		 endif
    endif
    if Switch = 5
		 if getcontroltext(w1,FileTab5) <> ""
			 OnTab = 5
			 if !instr(getcaption(w1),getcontroltext(w1,FileTab5))
				 if instr(getcontroltext(w1,FileTab1),"*")
					 RealTabName = getcontroltext(w1,FileTab1)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab1)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer1 = ""
					 buffer1 = getcontroltext(w1,RichEdit)
					 DoMinimise(1)
				 endif
				 if instr(getcontroltext(w1,FileTab2),"*")
					 RealTabName = getcontroltext(w1,FileTab2)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab2)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer2 = ""
					 buffer2 = getcontroltext(w1,RichEdit)
					 DoMinimise(2)
				 endif
				 if instr(getcontroltext(w1,FileTab3),"*")
					 RealTabName = getcontroltext(w1,FileTab3)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab3)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer3 = ""
					 buffer3 = getcontroltext(w1,RichEdit)
					 DoMinimise(3)
				 endif
				 if instr(getcontroltext(w1,FileTab4),"*")
					 RealTabName = getcontroltext(w1,FileTab4)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab4)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer4 = ""
					 buffer4 = getcontroltext(w1,RichEdit)
					 DoMinimise(4)
				 endif
				 if instr(getcontroltext(w1,FileTab6),"*")
					 RealTabName = getcontroltext(w1,FileTab6)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab6)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer6 = ""
					 buffer6 = getcontroltext(w1,RichEdit)
					 DoMinimise(6)
				 endif
				 FileNameIs = getcontroltext(w1,FileTab5)
             if instr(FileNameIs,"*")
                FileNameIs = mid$(FileNameIs,1,instr(FileNameIs,"*")-1)
             endif
				 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 if Tab5Loaded = 0
					 ProgPath = RecentProgs[5]
					 GetFileName(w1,0,ProgPath,1)
					 setcontroltext(w1,FileTab5,FileNameIs)
					 DoOpen(1)
					 Tab5Loaded = 1 
					 setcontroltext(w1,FileTab5,FileNameIs)
                buffer5 = ""
                buffer5 = getcontroltext(w1,RichEdit)  
                OnTab = 5
                goto EndOfSub
				 else
                OnTab = 5 
                Tab5Loaded = 1
					 DoRestore(0,5)
					 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),BlueButton
					 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                goto EndOfSub 
				 endif
			 endif
			 DoRestore(0,5)
			 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
		 endif
    endif
    if Switch = 6
		 if getcontroltext(w1,FileTab6) <> ""
			 OnTab = 6
			 if !instr(getcaption(w1),getcontroltext(w1,FileTab6))
				 if instr(getcontroltext(w1,FileTab1),"*")
					 RealTabName = getcontroltext(w1,FileTab1)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab1)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer1 = ""
					 buffer1 = getcontroltext(w1,RichEdit)
					 DoMinimise(1)
				 endif
				 if instr(getcontroltext(w1,FileTab2),"*")
					 RealTabName = getcontroltext(w1,FileTab2)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab2)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer2 = ""
					 buffer2 = getcontroltext(w1,RichEdit)
					 DoMinimise(2)
				 endif
				 if instr(getcontroltext(w1,FileTab3),"*")
					 RealTabName = getcontroltext(w1,FileTab3)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab3)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer3 = ""
					 buffer3 = getcontroltext(w1,RichEdit)
					 DoMinimise(3)
				 endif
				 if instr(getcontroltext(w1,FileTab4),"*")
					 RealTabName = getcontroltext(w1,FileTab4)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab4)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer4 = ""
					 buffer4 = getcontroltext(w1,RichEdit)
					 DoMinimise(4)
				 endif
				 if instr(getcontroltext(w1,FileTab5),"*")
					 RealTabName = getcontroltext(w1,FileTab5)
					 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
				 else
					 RealTabName = getcontroltext(w1,FileTab5)
				 endif

				 if instr(getcaption(w1),RealTabName)
					 buffer5 = ""
					 buffer5 = getcontroltext(w1,RichEdit)
					 DoMinimise(5)
				 endif
				 FileNameIs = getcontroltext(w1,FileTab6)
             if instr(FileNameIs,"*")
                FileNameIs = mid$(FileNameIs,1,instr(FileNameIs,"*")-1)
             endif
				 SETCONTROLCOLOR w1,FileTab6,RGB(255,255,255),BlueButton
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 ClearEditor()
				 if Tab6Loaded = 0
					 ProgPath = RecentProgs[6]
					 GetFileName(w1,0,ProgPath,1)
					 setcontroltext(w1,FileTab6,FileNameIs)
					 DoOpen(1)
					 Tab6Loaded = 1 
					 setcontroltext(w1,FileTab6,FileNameIs)
                buffer6 = ""
                buffer6 = getcontroltext(w1,RichEdit)  
                OnTab = 6
                goto EndOfSub
				 else
                OnTab = 6 
                Tab6Loaded = 1
					 DoRestore(0,6)
					 SETCONTROLCOLOR w1,FileTab6,RGB(255,255,255),BlueButton
					 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
					 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
                goto EndOfSub
				 endif
			 endif
			 DoRestore(0,6)
			 SETCONTROLCOLOR w1,FileTab6,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
		 endif
    endif

    label EndOfSub
    if cLine = 0
       cLine = 1
       StoreLine = 1
       ScrollPoint = 1
    endif

	 enablecontrol (w1,FileTab1,1)
	 enablecontrol (w1,FileTab2,1)
	 enablecontrol (w1,FileTab3,1)
	 enablecontrol (w1,FileTab4,1)
	 enablecontrol (w1,FileTab5,1)
	 enablecontrol (w1,FileTab6,1)

	 if getselected(w1,Combo2) > -1
		 ShowSubroutineButtons(1)
	 else
		 ShowSubroutineButtons(0)
	 endif
	 if getselected(w1,Combo4) > -1
		 ShowWindowButtons(1)
	 else
		 ShowWindowButtons(0)
	 endif

starttimer w1,TimerSpeed,MainTimer
return
endsub

sub CreateDetailsFile()
	 string MainNameD 
	 string StoreBookFileD
	 MainNameD = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".txt"
	 if openfile(MyFile2,StoreBookFileD,"W") = 0
       string text2,text3,text4 
		 int lvcount2 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
		 lvcount2 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
       write MyFile2,":lv2-" + ltrim$(str$(lvcount2))
		 for a = 0 to lvcount2 -1
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text2)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,2,text3)
           write MyFile2,text + "|" + text2 + "!" + text3
		 next a

		 lvcount2 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
		 lvcount2 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
       write MyFile2,":lv4-" + ltrim$(str$(lvcount2))
		 for a = 0 to lvcount2 -1
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text2)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,2,text3)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,3,text4)
           write MyFile2,text + "|" + text2 + "!" + text3 + "#" + text4
		 next a

		 lvcount2 = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
		 lvcount2 = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
       write MyFile2,":lv8-" + ltrim$(str$(lvcount2))
		 for a = 0 to lvcount2 -1
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,0,text)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,1,text2)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,2,text3)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,3,text4)
           write MyFile2,text + "|" + text2 + "!" + text3 + "#" + text4
		 next a

       'Bookmarks
       write MyFile2,":bmk-" + ltrim$(str$(getstringcount(w1,Combo6)))
		 for a = 0 to getstringcount(w1,Combo6) - 1 
			  write MyFile2,getstring(w1,Combo6,a) 
		 next a

       'Includes
       write MyFile2,":inc-" + ltrim$(str$(getstringcount(w1,Combo88)))
		 for a = 0 to getstringcount(w1,Combo88) - 1 
			  write MyFile2,getstring(w1,Combo88,a) 
		 next a

       'Scroll range
       int scMin,scMax
       scMin = 0 
       scMax = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
       write MyFile2,":sr-" + ltrim$(str$(scMin)) + "!" + ltrim$(str$(scMax))

       'User go to lines
       if rtrim$(ltrim$(getcontroltext(w1,EDIT_11))) <> ""
          write MyFile2,":u1-" + rtrim$(ltrim$(getcontroltext(w1,EDIT_11)))
       else
          write MyFile2,":u1-0"
       endif 
       if rtrim$(ltrim$(getcontroltext(w1,EDIT_111))) <> ""
          write MyFile2,":u2-" + rtrim$(ltrim$(getcontroltext(w1,EDIT_111)))
       else
          write MyFile2,":u2-0"
       endif 

       if rtrim$(ltrim$(getcontroltext(w1,EDIT_1111))) <> ""
          write MyFile2,":u3-" + rtrim$(ltrim$(getcontroltext(w1,EDIT_1111)))
       else
          write MyFile2,":u3-0"
       endif 

       'Sub routines etc
       if (getselected(w1,Combo2)) > - 1
          write MyFile2,":c2-" + ltrim$(str$(getselected(w1,Combo2)))
       else
          write MyFile2,":c2-!"
       endif 

       if (getselected(w1,Combo4)) > - 1
          write MyFile2,":c4-" + ltrim$(str$(getselected(w1,Combo4)))
       else
          write MyFile2,":c4-!"
       endif 

       if (getselected(w1,Combo6)) > - 1
          write MyFile2,":c6-" + ltrim$(str$(getselected(w1,Combo6)))
       else
          write MyFile2,":c6-!"
       endif 

       if (getselected(w1,Combo8)) > - 1
          write MyFile2,":c8-" + ltrim$(str$(getselected(w1,Combo8)))
       else
          write MyFile2,":c8-!"
       endif 

       if (getselected(w1,Combo10)) > - 1
          write MyFile2,":c10-" + ltrim$(str$(getselected(w1,Combo10)))
       else
          write MyFile2,":c10-!"
       endif 

       if (getselected(w1,Combo12)) > - 1
          write MyFile2,":c12-" + ltrim$(str$(getselected(w1,Combo12)))
       else
          write MyFile2,":c12-!"
       endif 

       if (getselected(w1,Combo14)) > - 1
          write MyFile2,":c14-" + ltrim$(str$(getselected(w1,Combo14)))
       else
          write MyFile2,":c14-!"
       endif 

       if (getselected(w1,Combo16)) > - 1
          write MyFile2,":c16-" + ltrim$(str$(getselected(w1,Combo16)))
       else
          write MyFile2,":c16-!"
       endif 

       if getscrollpos(w1,ScrollBar) = 0
          write MyFile2,":sp-1"
       else   
          write MyFile2,":sp-" + ltrim$(str$(getscrollpos(w1,ScrollBar)))
       endif

       'Places
       write MyFile2,":nav-" + ltrim$(str$(getstringcount(w1,Combo18)))
		 for a = 0 to getstringcount(w1,Combo18) - 1 
			  write MyFile2,getstring(w1,Combo18,a) 
		 next a

    endif
    closefile MyFile2
return
endsub

sub DoMinimiseAll()
	 if OnTab = 1
		 if instr(getcaption(w1),getcontroltext(w1,FileTab1))
			 buffer1 = ""
			 buffer1 = getcontroltext(w1,RichEdit)
			 DoMinimise(1)
			 Tab1Loaded = 1
		 endif
	 endif
	 if OnTab = 2
		 if instr(getcaption(w1),getcontroltext(w1,FileTab2))
			 buffer2 = ""
			 buffer2 = getcontroltext(w1,RichEdit)
			 DoMinimise(2)
			 Tab1Loaded = 1
			 Tab2Loaded = 1
		 endif
	 endif
	 if OnTab = 3
		 if instr(getcaption(w1),getcontroltext(w1,FileTab3))
			 buffer3 = ""
			 buffer3 = getcontroltext(w1,RichEdit)
			 DoMinimise(3)
			 Tab1Loaded = 1
			 Tab2Loaded = 1
			 Tab3Loaded = 1
		 endif
	 endif
	 if OnTab = 4
		 if instr(getcaption(w1),getcontroltext(w1,FileTab4))
			 buffer4 = ""
			 buffer4 = getcontroltext(w1,RichEdit)
			 DoMinimise(4)
			 Tab1Loaded = 1
			 Tab2Loaded = 1
			 Tab3Loaded = 1
			 Tab4Loaded = 1
		 endif
	 endif
	 if OnTab = 5
		 if instr(getcaption(w1),getcontroltext(w1,FileTab5))
			 buffer5 = ""
			 buffer5 = getcontroltext(w1,RichEdit)
			 DoMinimise(5)
			 Tab1Loaded = 1
			 Tab2Loaded = 1
			 Tab3Loaded = 1
			 Tab4Loaded = 1
			 Tab5Loaded = 1
		 endif
	 endif
	 if OnTab = 6
		 if instr(getcaption(w1),getcontroltext(w1,FileTab6))
			 buffer6 = ""
			 buffer6 = getcontroltext(w1,RichEdit)
			 DoMinimise(6)
			 Tab1Loaded = 1
			 Tab2Loaded = 1
			 Tab3Loaded = 1
			 Tab4Loaded = 1
			 Tab5Loaded = 1
			 Tab6Loaded = 1
		 endif
	 endif
return
endsub

sub CreatePathFile()
	 GetFileName(w1,0,ProgPath,1)
	 string MainNameD = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 string StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".pth"
	 if openfile(MyFile2,StoreBookFileD,"W") = 0
		 write MyFile2,ltrim$(ProgPath) 
	 endif
	 closefile MyFile2
return
endsub

sub LoadIncludePath()
	 if openfile(MyFile,getstartpath + "\\Res\\" + "IncludeFilesPath.ini","R") = 0
		 read MyFile,IncludePath
	 endif
	 closefile MyFile
	 if openfile(MyFile,getstartpath + "\\Res\\" + "IncludeFilesPath.ini","R") = 1
		 LocateIniFile()
		 if StopNow = 1
			 IncludePath = FrontPath + IncludePath
			 if openfile(MyFile,getstartpath + "\\Res\\" + "IncludeFilesPath.ini","W") = 0
		 		 write MyFile,IncludePath
			 endif
			 closefile MyFile
		 endif
		 if StopNow = 0
			 if openfile(MyFile,getstartpath + "\\Res\\" + "IncludeFilesPath.ini","W") = 0
				 write MyFile,"C:" + chr$(92) + "IWBDev" + chr$(92) + "Include" + chr$(92)
			 endif
			 closefile MyFile
		 endif
	 endif
	 closefile MyFile
return
endsub

sub DoInitialLoad()
    ConDrawOff(w1,RichEdit)
    RecentFiles()
    if ProgPath <> ""
       if FileOpenedBefore()
		    DoOpen(1)
		    TabTaken = 1
		    setcontroltext(w1,FileTab1,FileNameIs)
		    SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),BlueButton
          Tab1Loaded = 1
       else
          StartUp() 
          buffer1 = ClipText 
          CreatePathFile()  
			 TabTaken = 1 
			 setcontroltext(w1,FileTab1,FileNameIs)
			 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),BlueButton
			 Tab1Loaded = 1
			 setfocus w1,RichEdit
       endif
       if ProgCount = 0
          ProgCount = 1
          RecentProgs[1] = ProgPath
       endif 
    endif

    OnTab = InitialTab
    TabTaken = ProgCount

    if ProgCount > 0
       LoadTab(1)
    else
       OnTab = 0
       TabTaken = 0
       ProgCount = 0
		 Tab2Loaded = 0
		 Tab3Loaded = 0
		 Tab4Loaded = 0
		 Tab5Loaded = 0
		 Tab6Loaded = 0
       HideFileButtons()
       return
    endif

    if RecentProgs[1] <> ""
       setcontroltext(w1,FileTab1,RecentName[1])
    endif
    if RecentProgs[2] <> ""
       setcontroltext(w1,FileTab2,RecentName[2])
    endif
    if RecentProgs[3] <> ""
       setcontroltext(w1,FileTab3,RecentName[3])
    endif
    if RecentProgs[4] <> ""
       setcontroltext(w1,FileTab4,RecentName[4])
    endif
    if RecentProgs[5] <> ""
       setcontroltext(w1,FileTab5,RecentName[5])
    endif
    if RecentProgs[6] <> ""
       setcontroltext(w1,FileTab6,RecentName[6])
    endif
    ConDrawOn(w1,RichEdit)

	 showwindow w1,@SWSHOW,RichEdit
	 Loading = 1
	 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
	 QuietMode(1)
	 ColourNow(w1,0,rHandle)
	 QuietMode(0)
	 Loading = 0
'
return
endsub

sub CloseFiles()
    if iswindowclosed(w16) = 0
       closewindow w16
    endif
    Loading = 1
    RealTabName = ""
    string CloseLine = ltrim$(getcontroltext(w1,1001))
    if instr(CloseLine,">")
	    CloseLine = mid$(CloseLine,instr(CloseLine,">")+3,len(CloseLine))
    endif
    showwindow w1,@SWHIDE,RichEdit

    if AutoSaveOnExit = 1

       if OnTab = 1
          if instr(getcontroltext(w1,FileTab1),"*")
             buffer1 = ""
             buffer1 = getcontroltext(w1,RichEdit)
          endif
       endif

       if OnTab = 2
          if instr(getcontroltext(w1,FileTab2),"*")
             buffer2 = ""
             buffer2 = getcontroltext(w1,RichEdit)
          endif
       endif

       if OnTab = 3
          if instr(getcontroltext(w1,FileTab3),"*")
             buffer3 = ""
             buffer3 = getcontroltext(w1,RichEdit)
          endif
       endif

       if OnTab = 4
          if instr(getcontroltext(w1,FileTab4),"*")
             buffer4 = ""
             buffer4 = getcontroltext(w1,RichEdit)
          endif
       endif

       if OnTab = 5
          if instr(getcontroltext(w1,FileTab5),"*")
             buffer5 = ""
             buffer5 = getcontroltext(w1,RichEdit)
          endif
       endif

       if OnTab = 6
          if instr(getcontroltext(w1,FileTab6),"*")
             buffer6 = ""
             buffer6 = getcontroltext(w1,RichEdit)
          endif
       endif

	    if getcontroltext(w1,FileTab1) <> ""
			 RealTabName = getcontroltext(w1,FileTab1)
			 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
			 CloseDown = 1 
			 DoMinimiseAll()
			 DoRestore(0,1)
			 setcaption w1,RealTabName + ProgramTitle + "*"
			 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour

			 if instr(getcontroltext(w1,FileTab1),"*")
				 DelConfirm = 0
				 WindowDelete(0)
			 endif

			 if DelConfirm = 1 
				 DelConfirm = 0
				 goto s1
			 else
				 goto l2
			 endif
		 label s1
		 int b1 = 0
		 int ProgMatch = 0
		 for b1 = 1 to MaxTabs
			  GetFileName(w1,0,RecentProgs[b1],1)
			  if FileNameIs = RealTabName
				  ProgPath = RecentProgs[b1]
				  ProgMatch = 1
				  breakfor
			  endif
		 next b1
		 GetFileName(w1,0,ProgPath,1)
		 if !instr(ProgPath,IncludePath) and ProgMatch = 1
			 DoSave()
		 endif
	    endif
       label l2
       RealTabName = ""
	    if getcontroltext(w1,FileTab2) <> ""
			 RealTabName = getcontroltext(w1,FileTab2)
			 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
			 CloseDown = 2 
			 DoMinimiseAll()
			 DoRestore(0,2)
			 setcaption w1,RealTabName + ProgramTitle + "*"
			 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour

			 if instr(getcontroltext(w1,FileTab2),"*")
				 DelConfirm = 0
				 WindowDelete(0)
			 endif

			 if DelConfirm = 1 
				 DelConfirm = 0
				 goto s2
			 else
				 goto l3
			 endif
          label s2
          ProgMatch = 0
          for b1 = 1 to MaxTabs
              GetFileName(w1,0,RecentProgs[b1],1)
              if FileNameIs = RealTabName
		           ProgPath = RecentProgs[b1]
                 ProgMatch = 1
                 breakfor
              endif
          next b1
		    GetFileName(w1,0,ProgPath,1)
		    if !instr(ProgPath,IncludePath) and ProgMatch = 1
			    DoSave()
		    endif
	    endif
       label l3
       RealTabName = ""
	    if getcontroltext(w1,FileTab3) <> ""
			 RealTabName = getcontroltext(w1,FileTab3)
			 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
			 CloseDown = 3 
			 DoMinimiseAll()
			 DoRestore(0,3)
			 setcaption w1,RealTabName + ProgramTitle + "*"
			 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour

			 if instr(getcontroltext(w1,FileTab3),"*")
				 DelConfirm = 0
				 WindowDelete(0)
			 endif

			 if DelConfirm = 1 
				 DelConfirm = 0
				 goto s3
			 else
				 goto l4
			 endif

          label s3
          ProgMatch = 0
          for b1 = 1 to MaxTabs
              GetFileName(w1,0,RecentProgs[b1],1)
              if FileNameIs = RealTabName
		           ProgPath = RecentProgs[b1]
                 ProgMatch = 1
                 breakfor
              endif
          next b1
		    GetFileName(w1,0,ProgPath,1)
		    if !instr(ProgPath,IncludePath) and ProgMatch = 1
			    DoSave()
		    endif
	    endif

       label l4 
       RealTabName = ""
	    if getcontroltext(w1,FileTab4) <> ""
			 RealTabName = getcontroltext(w1,FileTab4)
			 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
			 CloseDown = 4
			 DoMinimiseAll()
			 DoRestore(0,4)
			 setcaption w1,RealTabName + ProgramTitle + "*"
			 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour 

			 if instr(getcontroltext(w1,FileTab4),"*")
				 DelConfirm = 0
				 WindowDelete(0)
			 endif

			 if DelConfirm = 1 
				 DelConfirm = 0
				 goto s4
			 else
				 goto l5
			 endif

          label s4 
          ProgMatch = 0
          for b1 = 1 to MaxTabs
              GetFileName(w1,0,RecentProgs[b1],1)
              if FileNameIs = RealTabName
		           ProgPath = RecentProgs[b1]
                 ProgMatch = 1
                 breakfor
              endif
          next b1
		    GetFileName(w1,0,ProgPath,1)
		    if !instr(ProgPath,IncludePath) and ProgMatch = 1
			    DoSave()
		    endif
	    endif

       label l5
       RealTabName = ""
	    if getcontroltext(w1,FileTab5) <> ""
			 RealTabName = getcontroltext(w1,FileTab5)
			 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
			 CloseDown = 5 
			 DoMinimiseAll()
			 DoRestore(0,5)
			 setcaption w1,RealTabName + ProgramTitle + "*"
			 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour

			 if instr(getcontroltext(w1,FileTab5),"*")
				 DelConfirm = 0
				 WindowDelete(0)
			 endif

			 if DelConfirm = 1 
				 DelConfirm = 0
				 goto s5
			 else
				 goto l6
			 endif

          label s5
          ProgMatch = 0 
          for b1 = 1 to MaxTabs
              GetFileName(w1,0,RecentProgs[b1],1)
              if FileNameIs = RealTabName
		           ProgPath = RecentProgs[b1]
                 ProgMatch = 1
                 breakfor
              endif
          next b1
		    GetFileName(w1,0,ProgPath,1)
		    if !instr(ProgPath,IncludePath) and ProgMatch = 1
			    DoSave()
		    endif
	    endif

       label l6
       RealTabName = "" 
	    if getcontroltext(w1,FileTab6) <> ""
			 RealTabName = getcontroltext(w1,FileTab6)
			 RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1) 
			 CloseDown = 6 
			 DoMinimiseAll()
			 DoRestore(0,6)
			 setcaption w1,RealTabName + ProgramTitle + "*"
			 SETCONTROLCOLOR w1,FileTab6,RGB(255,255,255),BlueButton
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour

			 if instr(getcontroltext(w1,FileTab6),"*")
				 DelConfirm = 0
				 WindowDelete(0)
			 endif

			 if DelConfirm = 1 
				 DelConfirm = 0
				 goto s6
			 else
				 goto l7
			 endif

          label s6
          ProgMatch = 0
          for b1 = 1 to MaxTabs
              GetFileName(w1,0,RecentProgs[b1],1)
              if FileNameIs = RealTabName
		           ProgPath = RecentProgs[b1]
                 ProgMatch = 1
                 breakfor
              endif
          next b1
		    GetFileName(w1,0,ProgPath,1)
		    if !instr(ProgPath,IncludePath) and ProgMatch = 1
			    DoSave()
		    endif
	    endif

       label l7
       RealTabName = ""

	    endif

       if openfile(MyFile2,getstartpath + "\\Res\\" + "xeditor4.ini","W") = 0
	       for a = 1 to ProgCount
			     if rtrim$(ltrim$(RecentProgs[a])) <> "" 
				     write MyFile2,RecentProgs[a]
			     endif
	       next a
          write MyFile2,"!" + ltrim$(str$(OnTab))
	       closefile MyFile2
       endif

       if hIcon then DELETEIMAGE hIcon,@IMGICON

return
endsub

sub ScrollWheel(int Direction)
stoptimer w1,MainTimer
	 int z1
    if Direction = 1 'Scroll up
		 for z1 = 1 to WheelScrollLines 
			  DoLineUp()
		 next z1

		 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
		 for a = 1 to LinesPerPage
			  setcontroltext(w1,a+1000,ltrim$(str$(FirstVisLine+a)))
			  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
		 next a
		 cLine = FirstVisLine+1
		 StoreLine = cLine
    endif

    if Direction = 2 'Scroll down
		 for z1 = 1 to WheelScrollLines 
			  DoLineDown()
           sRange.Low = (getscrollpos(w1,ScrollBar)*LineSpace) - LineSpace
           SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)

/*
    if 1000 + (cLine-FirstVisLine) < 1001
       if FontSize = 10
	       setcontroltext(w1,1029,"> " + getcontroltext(w1,1029))
	       SETCONTROLCOLOR w1,1029,Red,BackColour
       endif
       if FontSize = 11
	       setcontroltext(w1,1027,"> " + getcontroltext(w1,1027))
	       SETCONTROLCOLOR w1,1027,Red,BackColour
       endif
    else
	    setcontroltext(w1,1000 + (cLine-FirstVisLine),"> " + getcontroltext(w1,1000 + (cLine-FirstVisLine)))
	    SETCONTROLCOLOR w1,1000 + (cLine-FirstVisLine),Red,BackColour
    endif
*/

		 next z1

		 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
		 for a = 1 to LinesPerPage
			  setcontroltext(w1,a+1000,ltrim$(str$(FirstVisLine+a)))
			  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
		 next a
		 cLine = FirstVisLine+a
		 StoreLine = cLine

'setcontroltext(w1,1029,"> " + getcontroltext(w1,1029))

'SetLines()
'setcontroltext(w1,EDIT_1,ltrim$(str$(FirstVisLine+1)))


    endif
starttimer w1,TimerSpeed,MainTimer
return
endsub

sub ShowSubRoutineButtons(opt int Switch)
return
Switch = 1
    if Switch = 0
		 showwindow w1,@SWHIDE,SubJump
		 showwindow w1,@SWHIDE,EndSubb
		 showwindow w1,@SWHIDE,CopySubButton 
		 showwindow w1,@SWHIDE,CopySubBlockButton 
		 showwindow w1,@SWHIDE,MoveSubButton 
		 showwindow w1,@SWHIDE,DeleteSubButton
		 showwindow w1,@SWHIDE,ShowSubButton
		 showwindow w1,@SWHIDE,ClearSubs
    else
		 showwindow w1,@SWSHOW,SubJump
		 showwindow w1,@SWSHOW,EndSubb
		 showwindow w1,@SWSHOW,CopySubButton 
		 showwindow w1,@SWSHOW,CopySubBlockButton 
		 showwindow w1,@SWSHOW,MoveSubButton 
		 showwindow w1,@SWSHOW,DeleteSubButton
		 showwindow w1,@SWSHOW,ShowSubButton
		 showwindow w1,@SWSHOW,ClearSubs
   endif
return
endsub

sub ShowWindowButtons(opt int Switch)
return
    if Switch = 0
		 showwindow w1,@SWHIDE,WinJump
		 showwindow w1,@SWHIDE,EndWin
		 showwindow w1,@SWHIDE,WinHandler 
		 showwindow w1,@SWHIDE,CopyWinButton 
		 showwindow w1,@SWHIDE,CopyWinBlockButton 
		 showwindow w1,@SWHIDE,MoveWinButton 
		 showwindow w1,@SWHIDE,DeleteWinButton
		 showwindow w1,@SWHIDE,ShowWindowButton
		 showwindow w1,@SWHIDE,ClearWins
    else
		 showwindow w1,@SWSHOW,WinJump
		 showwindow w1,@SWSHOW,EndWin
		 showwindow w1,@SWSHOW,WinHandler 
		 showwindow w1,@SWSHOW,CopyWinButton 
		 showwindow w1,@SWSHOW,CopyWinBlockButton 
		 showwindow w1,@SWSHOW,MoveWinButton 
		 showwindow w1,@SWSHOW,DeleteWinButton
		 showwindow w1,@SWSHOW,ShowWindowButton
		 showwindow w1,@SWSHOW,ClearWins
    endif
return
endsub

sub ColourScreenPageDown(opt int Switch)
    Scrolling = 1
    stoptimer w1,MainTimer
    int FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) 
	 int StorecLine = cLine
	 showcursor(FALSE)
    ConDrawOff(w1,RichEdit)

    QuietMode(1)
	 for a = (FirstVisLine + (LinesPerPage-1)) to (FirstVisLine + LinesPerPage) + LinesPerPage
		  cLine = a + 1
		  StoreLine = cLine 
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.Cliptext,512)
		  if !len(ltrim$(line$)) then goto CheckNextLineA
		  Offset = SendMessage(rHandle,EM_LINEINDEX,a-1,0)
		  ColourLineP(rHandle,a-1,Offset)
	 label CheckNextLineA
	 next a

    QuietMode(0)

	 showcursor(TRUE)
    ConDrawOn(w1,RichEdit)

	 cLine = StorecLine
    StoreLine = cLine
	 OldLine = OnLine
    starttimer w1,TimerSpeed1,MainTimer
'setfocus w1,RichEdit
    Scrolling = 0
return
endsub

sub ColourScreenPageUp(opt int Switch)
    Scrolling = 1
    stoptimer w1,MainTimer
    int b2 = 0
    int LineHasBeenColoured = 0
    int FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) 
	 int StorecLine = cLine
	 showcursor(FALSE)
    ConDrawOff(w1,RichEdit)

    QuietMode(1)

	 for a = FirstVisLine - LinesPerPage to FirstVisLine
		  cLine = a + 1
		  StoreLine = cLine 
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.ClipText,512)
		  if !len(ltrim$(line$)) then goto CheckNextLineA
		  Offset = SendMessage(rHandle,EM_LINEINDEX,a-1,0)
		  ColourLineP(rHandle,a-1,Offset)
	 label CheckNextLineA
    LineHasBeenColoured = 0
	 next a

    QuietMode(0)

	 showcursor(TRUE)
    ConDrawOn(w1,RichEdit)

	 cLine = FirstVisLine - (LinesPerPage-1)
    StoreLine = cLine
	 OldLine = OnLine
    starttimer w1,TimerSpeed1,MainTimer
    Scrolling = 0
return
endsub

sub ColourScreenVisableUp(opt int Switch)
    stoptimer w1,MainTimer
    int FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) 
	 int StorecLine = cLine

    CommentBlockStart = 0
    CommentBlockEnd = 0
	 showcursor(FALSE)

    QuietMode(1)

    int StoreFvis = FirstVisLine
	 for a = FirstVisLine - 34 to FirstVisLine
		  cLine = a + 1
		  StoreLine = cLine 
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.ClipText,512)
		  if len(ltrim$(#cp.ClipText)) < 3 then goto CheckNextLineA
		  Offset = SendMessage(rHandle,EM_LINEINDEX,a-1,0)
		  ColourLineP(rHandle,a-1,Offset)
	 label CheckNextLineA
	 next a

    BlockCommentCheck()

	 cLine = StorecLine
    StoreLine = cLine

	 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
	 SendMessage(rHandle,EM_SETSEL,Offset,Offset)
	 OldLine = OnLine
	 StoreLine = cLine 

    QuietMode(0)
	 showcursor(TRUE)

    sRange.Low = StoreFvis
    sRange.Low = sRange.Low * LineSpace

    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
'print "SET 7"
	 setscrollpos(w1,ScrollBar,sRange.Low/LineSpace)
    starttimer w1,TimerSpeed1,MainTimer
return
endsub

sub StringToVal(string StringIn),int
    string StringOut = ""
    string StringBit = "" 
    int TheValue = 0
    int Loop = 0
    for Loop = 1 to len(StringIn)
        StringBit = mid$(StringIn,Loop,1)
        if StringBit >= chr$(48) and StringBit <= chr$(57)
           StringOut = StringOut + StringBit
        endif  
    next Loop
    TheValue = val(StringOut)
return TheValue
endsub

sub ColourScreenVisableDown(opt int Switch)

    ConDrawOff(w1,RichEdit)
    stoptimer w1,MainTimer
    int FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
    int StorecLine = cLine
    CommentBlockStart = 0
    CommentBlockEnd = 0
    showcursor(FALSE)

    QuietMode(1)

    for a = FirstVisLine to FirstVisLine + 34
        cLine = a + 1
        StoreLine = cLine
        CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.ClipText,255)
        if len(ltrim$(#cp.ClipText)) < 3 then goto CheckNextLineA
        Offset = SendMessage(rHandle,EM_LINEINDEX,a-1,0)
        ColourLineP(rHandle,a-1,Offset)
    label CheckNextLineA
    next a

    BlockCommentCheck()

    QuietMode(0)

    cLine = StorecLine
    StoreLine = cLine

    Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)

    SendMessage(rHandle,EM_SETSEL,Offset,Offset)
    OldLine = OnLine
    StoreLine = cLine

    showcursor(TRUE)

    for a = 1 to LinesPerPage
        if instr(getcontroltext(w1,a+1000),">")
           sRange.Low = StringToVal(getcontroltext(w1,a+1000))
           sRange.Low = (sRange.Low - (LinesPerPage - 1)) * LineSpace
           breakfor
        endif
    next a
    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
'print "SET 8"
    setscrollpos(w1,ScrollBar,sRange.Low / LineSpace)
    starttimer w1,TimerSpeed1,MainTimer
    ConDrawOn(w1,RichEdit)

return
endsub

sub DoCloseProgram()
    CloseProgram = 1
    'closeconsole
    'showwindow w1,@SWMINIMIZED
    CloseFiles()
    UnSubclassRichEdit(w1,RichEdit)
    UnSubclassEdit(w1,CodePhraseEdit)
    UnSubclassEditFind(w6,CodePhraseEdit)
    closewindow w14
    closewindow w8
    closewindow w6
    closewindow w4
    closewindow w2
    CLOSEWINDOW w1
return
endsub

sub DoRebuild()
    int c2Restore = getselected(w1,Combo2)
    int c4Restore = getselected(w1,Combo4)
    CONTROLCMD(w1,ListView2,@LVDELETEALL)
    CONTROLCMD(w1,ListView4,@LVDELETEALL)
    CONTROLCMD(w1,ListView10,@LVDELETEALL)
    SendMessage(GetDlgItem(w1.hwnd,Combo2),CB_RESETCONTENT,0,0)
    SendMessage(GetDlgItem(w1.hwnd,Combo4),CB_RESETCONTENT,0,0)
    SendMessage(GetDlgItem(w1.hwnd,Combo88),CB_RESETCONTENT,0,0)

	 for a = 1 to CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
        CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,line$,512)
		  if len(ltrim$(line$)) < 3 then goto CheckNextLine
           DoGetSubZ(a,line$,2)
    label CheckNextLine
	 next a

    int lvcount22 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
    if lvcount22 > 0 
       PopulateSubRoutines()
    endif
    setselected(w1,Combo2,c2Restore)

    lvcount22 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
    if lvcount22 > 0 
       PopulateWindows()
    endif
    setselected(w1,Combo4,c4Restore)

    'CreateDetailsFile()

return
endsub

sub DoUndo(hwnd:int,uMsg:int,wParam:int,lParam:pointer)

    label DoUndoAgain
    showwindow w1,@SWHIDE,ListView
    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
    int LinesBeforeUndo = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
    if Undo2Count[OnTab] = 0 then return

	 if Undo2[OnTab].Typed[Undo2Count[OnTab]] = chr$(13) + chr$(10)
       RetCount = 0
       OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
		 SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]],Undo2[OnTab].pos[Undo2Count[OnTab]]+2)
		 CONTROLCMD w1,RichEdit,@RTDELETESEL

	    if FirstVisLine <> Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
		    sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
		    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
		    for a = 1 to 30
				  setcontroltext(w1,a+1000,str$(FirstVisLine+a))
				  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
				  if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
					  cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
					  StoreLine = cLine
				  endif
		    next a
	    endif

	    QuietMode(1)
       FirstVisLine = Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
	    ColourNow(w1,1,rHandle)
	    QuietMode(0)

	    sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
	    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
	    SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]],Undo2[OnTab].pos[Undo2Count[OnTab]])

       'MoveBlocks(cLine,1,0) 'Line delete

	 else

		 'Ignore these chars
		 if asc(Undo2[OnTab].Typed[Undo2Count[OnTab]]) = 22 or asc(Undo2[OnTab].Typed[Undo2Count[OnTab]]) = 24
			  goto RedoIncrement
		 endif
		 select Undo2[OnTab].Press[Undo2Count[OnTab]]
				  Case  1 'Char Undo
						  Loading = 1
                    QuietMode(1)
                    OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
						  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]],Undo2[OnTab].pos[Undo2Count[OnTab]]+1)
						  CONTROLCMD w1,RichEdit,@RTDELETESEL
                    QuietMode(0)
						  CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line$,512)
                    Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)

						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  if FirstVisLine <> Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
							  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
							  for a = 1 to 30
									setcontroltext(w1,a+1000,str$(Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+a))
									SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
									if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										StoreLine = cLine
									endif
							  next a
						  endif

                    QuietMode(1)
                    #cp.ClipText = line$
						  ColourLineP(rHandle,cLine-1,Offset)
                    QuietMode(0)

						  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                    setscrollpos(w1,ScrollBar,Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+1)
						  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]],Undo2[OnTab].pos[Undo2Count[OnTab]]) 
						  Loading = 0

				  case  2 'Backspace Undo Single character
				  case& 3 'Delete Undo Single character
                    kw = 0  
			           FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)

	   				  Loading = 1 
						  if Undo2[OnTab].Press[Undo2Count[OnTab]] = 2 'Backspace
							  'Insert before the carriage return
							  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]]-1,Undo2[OnTab].pos[Undo2Count[OnTab]]-1)
						  else
							  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]],Undo2[OnTab].pos[Undo2Count[OnTab]])
						  endif
                    Loading = 1
						  if len(Undo2[OnTab].Was[Undo2Count[OnTab]]) = 1 and asc(mid$(Undo2[OnTab].Was[Undo2Count[OnTab]],1,1)) = 13
							  CONTROLCMD w1,RichEdit,@RTREPLACESEL,chr$(10) 
						  else
							  CONTROLCMD w1,RichEdit,@RTREPLACESEL,Undo2[OnTab].Was[Undo2Count[OnTab]]
						  endif 
						  CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line$,512)
                    Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)

                    if FirstVisLine <> Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
						     sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
						     SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                    endif

                    QuietMode(1)
                    #cp.ClipText = line$
			           ColourLineP(rHandle,cLine-1,Offset)
                    StorecLine = cLine
						  CONTROLCMD(w1,RichEdit,@RTGETLINE,StorecLine,line$,512)
                    Offset = SendMessage(rHandle,EM_LINEINDEX,StorecLine,0)
                    #cp.ClipText = line$ 
			           ColourLineP(rHandle,StorecLine,Offset)
                    QuietMode(0)

                    'Only renumber lines if scroll position has changed.
                    if FirstVisLine <> Undo2[OnTab].FirstVis[Undo2Count[OnTab]]   
							  FirstVisLine = Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
							  for a = 1 to 30
								   setcontroltext(w1,a+1000,str$(FirstVisLine+a))
								   SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
								   if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
									   cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
									   StoreLine = cLine
								   endif
							  next a
                    endif 
						  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                    setscrollpos(w1,ScrollBar,Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+1)
						  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]]+1,Undo2[OnTab].pos[Undo2Count[OnTab]]+1)
                    setfocus w1,RichEdit 
                    setcontroltext(w1,LineNumberEdit,ltrim$(str$(CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,Undo2[OnTab].Pos[Undo2Count[OnTab]]))))
                    Loading = 0

				  case  4 'Cut Undo
						  Loading = 1
                    RetCount = 0
                    OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
						  SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]],UndoBlock[OnTab].StartPos[Undo2Count[OnTab]])
						  CONTROLCMD w1,RichEdit,@RTREPLACESEL,UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]

						  Redo2Count[OnTab]++
						  Redo2[OnTab].Press[Redo2Count[OnTab]] = Undo2[OnTab].Press[Undo2Count[OnTab]]
                    Redo2[OnTab].FirstVis[Redo2Count[OnTab]] = Undo2[OnTab].FirstVis[Undo2Count[OnTab]]

						  setscrollpos(w1,ScrollBar,UndoBlock[OnTab].LineNo[Undo2Count[OnTab]])
						  sRange.Low = GETSCROLLPOS(w1,ScrollBar) * LineSpace
						  cLine = GETSCROLLPOS(w1,ScrollBar) + 1
						  StoreLine = cLine
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)

						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  if FirstVisLine <> Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
							  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
							  for a = 1 to 30
									setcontroltext(w1,a+1000,str$(FirstVisLine+a))
									SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
									if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										StoreLine = cLine
									endif
							  next a
						  endif

						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)

                    QuietMode(1)
						  ColourNow(w1,0,rHandle)
                    QuietMode(0)

						  SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]],UndoBlock[OnTab].EndPos[Undo2Count[OnTab]])
						  setfocus w1,RichEdit

						  RedoBlock[OnTab].UndoCount[Redo2Count[OnTab]]   = UndoBlock[OnTab].UndoCount[Undo2Count[OnTab]] 
						  RedoBlock[OnTab].StartPos[Redo2Count[OnTab]]    = UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]
						  RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]      = UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]
						  RedoBlock[OnTab].Length[Redo2Count[OnTab]]      = UndoBlock[OnTab].Length[Undo2Count[OnTab]]
						  RedoBlock[OnTab].LineNo[Redo2Count[OnTab]]      = UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]
						  RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]] = UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]

'''print "Undo count = ",Undo2Count[OnTab],"    Press ",Undo2[OnTab].Press[Undo2Count[OnTab]],"  CUT cLine ",cLine

						  RetCount = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
						  RetCount = abs(OldLines - RetCount)

                    'Add any sub routine that was cut back into the list of sub routines
						  int LastLineCut = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]])
						  int FirstLineCut = (LastLineCut-abs(RetCount))+1
                    LastLineCut ++

						  Loading = 0 
                    sRange.Low = ((cLine-1) * LineSpace) - LineSpace
                    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                    setscrollpos(w1,ScrollBar,Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+1)

                    'Correct line numbers and set >
                    int a1 = 0
						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  for a1 = 1 to 30
							   setcontroltext(w1,a1+1000,str$(FirstVisLine+(a1)))
							   SETCONTROLCOLOR w1,a1+1000,RGB(0,0,0),BackColour
								if LastLineCut = FirstVisLine+a1
									setcontroltext(w1,1000 + a1,"> " + getcontroltext(w1,1000 + a1))
									SETCONTROLCOLOR w1,1000 + a1,Red,BackColour
								endif
						  next a1

						  RetCount = 0
						  RetCount = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
						  if LinesBeforeUndo < RetCount 'and NoMove = 0
							  RetCount = RetCount - LinesBeforeUndo
							  MoveBlocks(cLine,RetCount,1,5) 'Code added
							  goto U4
						  endif
						  if LinesBeforeUndo > RetCount 'and NoMove = 0
							  RetCount = (LinesBeforeUndo - RetCount)  '+ 1
							  MoveBlocks(cLine,RetCount,0,6) 'Code deleted
						  endif
                    label U4

                    int NoMove = 0
                    for a1 = FirstLineCut to LastLineCut
							   CONTROLCMD(w1,RichEdit,@RTGETLINE,a1-1,line$,512)
							   Offset = SendMessage(rHandle,EM_LINEINDEX,a1-1,0)

							   ''print line$,"      ",a1
							   GetWordsOnLine(rHandle,a1-1,line$,Offset)

							   if ucase$(#w[1].aWord) = "SUB"
								   INT position = CONTROLCMD(w1,ListView2,@LVFINDITEM,#w[2].aWord)
                           if position = -1
                              NoMove = 1
										int NoDelSub = 1
										int NewInsertPos = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
										CONTROLCMD w1,ListView2,@LVINSERTITEM,NewInsertPos,#w[2].aWord
										position = CONTROLCMD(w1,ListView2,@LVFINDITEM,#w[2].aWord)
										CONTROLCMD w1,ListView2,@LVSETTEXT,position,1,LTRIM$(STR$(a1))
										CONTROLCMD w1,ListView2,@LVSETTEXT,position,2,LTRIM$(STR$(a1))
										SendMessage(GetDlgItem(w1.hwnd,Combo2),CB_RESETCONTENT,0,0)
										int lvcount22 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
										if lvcount22 > 0 
											StoreSubs()
											PopulateSubRoutines()
										endif
                           endif
				           endif

							  if ucase$(#w[1].aWord) = "ENDSUB" 
								  CONTROLCMD w1,ListView2,@LVSETTEXT,position,2,LTRIM$(STR$(a1))
							  endif

							  if ucase$(#w[1].aWord) = "OPENWINDOW"
								  position = CONTROLCMD(w1,ListView4,@LVFINDITEM,#w[2].aWord)
                          if position = -1
                             NoMove = 1
									  int NoDelWin = 1
									  NewInsertPos = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
									  CONTROLCMD w1,ListView4,@LVINSERTITEM,NewInsertPos,#w[2].aWord
									  position = CONTROLCMD(w1,ListView4,@LVFINDITEM,#w[2].aWord)
									  CONTROLCMD w1,ListView4,@LVSETTEXT,position,1,LTRIM$(STR$(a1))
									  CONTROLCMD w1,ListView4,@LVSETTEXT,position,2,LTRIM$(STR$(a1))
									  SendMessage(GetDlgItem(w1.hwnd,Combo4),CB_RESETCONTENT,0,0)
									  lvcount22 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
									  if lvcount22 > 0 
										  PopulateWindows()
									  endif
                          endif
				           endif

							  if ucase$(#w[1].aWord) = "WAITUNTIL" 
								  CONTROLCMD w1,ListView4,@LVSETTEXT,position,2,LTRIM$(STR$(a1))
							  endif

                    next a1

						  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
						  Undo2Count[OnTab]--  
						  RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)

					case 5 'Paste Undo
						  Loading = 1 
                    RetCount = 0
                    OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
						  SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]],UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]+1)
						  CONTROLCMD w1,RichEdit,@RTDELETESEL

						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  if FirstVisLine <> Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
							  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                       setscrollpos(w1,ScrollBar,Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+1)
							  for a = 1 to 30
									setcontroltext(w1,a+1000,str$(Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+a))
									SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
									if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										StoreLine = cLine
									endif
							  next a
						  endif

						  QuietMode(1)
						  FirstVisLine = Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
						  ColourNow(w1,1,rHandle)
						  QuietMode(0)

						  Redo2Count[OnTab]++
						  Redo2[OnTab].Press[Redo2Count[OnTab]]           = Undo2[OnTab].Press[Undo2Count[OnTab]]
                    Redo2[OnTab].FirstVis[Redo2Count[OnTab]]        = Undo2[OnTab].FirstVis[Undo2Count[OnTab]]
						  RedoBlock[OnTab].UndoCount[Redo2Count[OnTab]]   = UndoBlock[OnTab].UndoCount[Undo2Count[OnTab]] 
						  RedoBlock[OnTab].StartPos[Redo2Count[OnTab]]    = UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]
						  RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]      = UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]
						  RedoBlock[OnTab].Length[Redo2Count[OnTab]]      = UndoBlock[OnTab].Length[Undo2Count[OnTab]]
						  RedoBlock[OnTab].LineNo[Redo2Count[OnTab]]      = UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]
						  RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]] = UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]

						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  for a1 = 1 to 30
							   setcontroltext(w1,a1+1000,str$(FirstVisLine+(a1)))
							   SETCONTROLCOLOR w1,a1+1000,RGB(0,0,0),BackColour
						  next a1

                    'Was there a sub routine in the pasted text, if so delete it from sub routine's list
                    GetWordsInBlockText(UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]])
                    for a1 = 1 to WordCount
                        if ucase$(#w[a1].aWord) = "SUB"
                           position = CONTROLCMD(w1,ListView2,@LVFINDITEM,#w[a1+1].aWord)
								   CONTROLCMD(w1,ListView2,@LVDELETEITEM,position)
								   deletestring(w1,Combo2,position)
                           breakfor
                        endif
                    next a1

                    for a1 = 1 to WordCount
                        if ucase$(#w[a1].aWord) = "OPENWINDOW"
                           position = CONTROLCMD(w1,ListView4,@LVFINDITEM,#w[a1+1].aWord)
								   CONTROLCMD(w1,ListView4,@LVDELETEITEM,position)
								   deletestring(w1,Combo4,position)
                           breakfor
                        endif
                    next a1

						  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
						  SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]],UndoBlock[OnTab].StartPos[Undo2Count[OnTab]])
						  setfocus w1,RichEdit

						  Undo2Count[OnTab]--  
						  if Undo2Count[OnTab] < 0 then Undo2Count[OnTab] = 0
						  Loading = 0
						  RetCount = 0
						  RetCount = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
						  if LinesBeforeUndo < RetCount
							  RetCount = RetCount - LinesBeforeUndo
							  MoveBlocks(cLine,RetCount,1,7) 'Code added
							  goto U5
						  endif
						  if LinesBeforeUndo > RetCount
							  RetCount = (LinesBeforeUndo - RetCount)  '+ 1
							  MoveBlocks(cLine,RetCount,0,8) 'Code deleted
						  endif
                    label U5
						  RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)

					case 6 'Tab Undo
						  Loading = 1
                    QuietMode(1)
                    OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
						  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]]-1,Undo2[OnTab].pos[Undo2Count[OnTab]]+1)
						  CONTROLCMD w1,RichEdit,@RTREPLACESEL,Undo2[OnTab].Was[Undo2Count[OnTab]]
                    QuietMode(0)

						  CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line$,512)
                    Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)

						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  if FirstVisLine <> Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
							  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
							  for a = 1 to 30
									setcontroltext(w1,a+1000,str$(Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+a))
									SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
									if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										StoreLine = cLine
									endif
							  next a
						  endif

                    QuietMode(1)
                    #cp.ClipText = line$
						  ColourLineP(rHandle,cLine-1,Offset)
                    QuietMode(0)

						  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                    setscrollpos(w1,ScrollBar,Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+1)
						  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]]-1,Undo2[OnTab].pos[Undo2Count[OnTab]]-1) 
						  Loading = 0

				   case 7 'Replace Undo (Find & Replace)
						  Loading = 1
						  int eendpos = len(Undo2[OnTab].Typed[Undo2Count[OnTab]]) 
						  eendpos = (eendpos + Undo2[OnTab].Offset[Undo2Count[OnTab]])

                    QuietMode(1)
						  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].Offset[Undo2Count[OnTab]],eendpos)
						  CONTROLCMD w1,RichEdit,@RTREPLACESEL,""
						  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].Offset[Undo2Count[OnTab]],Undo2[OnTab].Offset[Undo2Count[OnTab]])
						  CONTROLCMD w1,RichEdit,@RTREPLACESEL,Undo2[OnTab].Was[Undo2Count[OnTab]]
						  setscrollpos(w1,ScrollBar,Undo2[OnTab].LineNo[Undo2Count[OnTab]]-2)
						  FirstVisLine = Undo2[OnTab].LineNo[Undo2Count[OnTab]]-2 
                    int RedLine = CONTROLCMD w1,RichEdit,@RTLINEFROMCHAR,Undo2[OnTab].Offset[Undo2Count[OnTab]]+ 1

						  for a = 1 to 30
							   setcontroltext(w1,a+1000,str$((FirstVisLine+2) + (a+1)))
							   SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
                        if RedLine = (FirstVisLine+2) + (a+1)
							      setcontroltext(w1,a+1000,"> " +str$((FirstVisLine+2) + (a+1)))
							      SETCONTROLCOLOR w1,a+1000,Red,BackColour
                        endif
						  next a

						  sRange.Low = Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                    setscrollpos(w1,ScrollBar,Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+1)
						  cLine = GETSCROLLPOS(w1,ScrollBar)
						  StoreLine = cLine

						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
						  ColourNow(w1,0,rHandle)
                    QuietMode(0)

						  sRange.Low = Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                    setscrollpos(w1,ScrollBar,Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+1)

						  SendMessage(rHandle,EM_SETSEL,eendpos,eendpos)
						  setfocus w1,RichEdit

               case 8 'Backspace delete line
						  if Undo2[OnTab].DeleteLine[Undo2Count[OnTab]] = 1 'Delete line
							  RetCount = 0
							  OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
							  CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line$,512)
							  Offset = Undo2[OnTab].Offset[Undo2Count[OnTab]]
							  SendMessage(rHandle,EM_SETSEL,Offset,Offset) 
							  CONTROLCMD w1,RichEdit,@RTREPLACESEL,chr$(13) + chr$(10)

							  if FirstVisLine <> Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
								  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
								  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
								  for a = 1 to 30
									   setcontroltext(w1,a+1000,str$(Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+a))
									   SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
									   if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										   cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										   StoreLine = cLine
									   endif
								  next a
							  endif

							  QuietMode(1)
							  FirstVisLine = Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
							  ColourNow(w1,1,rHandle)
							  QuietMode(0)

							  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                       setscrollpos(w1,ScrollBar,Undo2[OnTab].FirstVis[Undo2Count[OnTab]]+1)
                       Offset = Undo2[OnTab].Offset[Undo2Count[OnTab]]
                       SendMessage(rHandle,EM_SETSEL,Offset,Offset)

							  goto RedoIncrement
						  endif 

               case 9 'Delete Empty line
						  if asc(Undo2[OnTab].Typed[Undo2Count[OnTab]]) = 10
							  RetCount = 0
							  OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
							  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]],Undo2[OnTab].pos[Undo2Count[OnTab]])
							  CONTROLCMD w1,RichEdit,@RTREPLACESEL,chr$(13) + chr$(10)

							  if FirstVisLine <> Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
								  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
								  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
								  for a = 1 to 30
									   setcontroltext(w1,a+1000,str$(FirstVisLine+a))
									   SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
									   if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										   cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										   StoreLine = cLine
									   endif
								  next a
							  endif

							  QuietMode(1)
							  FirstVisLine = Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
							  ColourNow(w1,1,rHandle)
							  QuietMode(0)

							  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
							  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]],Undo2[OnTab].pos[Undo2Count[OnTab]])
						  endif

               case 10 'Keyword Undo
                    Loading = 1
						  Redo2Count[OnTab]++
						  Redo2[OnTab].Press[Redo2Count[OnTab]]  = Undo2[OnTab].Press[Undo2Count[OnTab]]
						  Redo2[OnTab].Typed[Redo2Count[OnTab]]  = Undo2[OnTab].Typed[Undo2Count[OnTab]]
						  Redo2[OnTab].Pos[Redo2Count[OnTab]]    = Undo2[OnTab].Pos[Undo2Count[OnTab]]
						  Redo2[OnTab].LineNo[Redo2Count[OnTab]] = Undo2[OnTab].LineNo[Undo2Count[OnTab]]
						  Redo2[OnTab].Offset[Redo2Count[OnTab]] = Undo2[OnTab].Offset[Undo2Count[OnTab]]
						  Redo2[OnTab].Was[Redo2Count[OnTab]]    = Undo2[OnTab].Was[Undo2Count[OnTab]]
						  Redo2[OnTab].Colour[Redo2Count[OnTab]] = Undo2[OnTab].Colour[Undo2Count[OnTab]]
						  Redo2[OnTab].Length[Redo2Count[OnTab]] = Undo2[OnTab].Length[Undo2Count[OnTab]]
						  Redo2[OnTab].PosBK[Redo2Count[OnTab]]  = Undo2[OnTab].PosBK[Undo2Count[OnTab]]
						  Redo2[OnTab].PosAK[Redo2Count[OnTab]]  = Undo2[OnTab].PosAK[Undo2Count[OnTab]]
						  Redo2[OnTab].NewLine[Redo2Count[OnTab]]  = Undo2[OnTab].NewLine[Undo2Count[OnTab]]
                    Redo2[OnTab].FirstVis[Redo2Count[OnTab]] = Undo2[OnTab].FirstVis[Undo2Count[OnTab]]
						  Redo2[OnTab].DeleteLine[Redo2Count[OnTab]] = Undo2[OnTab].DeleteLine[Undo2Count[OnTab]]

                    conDrawOff(w1,RichEdit)
                    QuietMode(1)

						  CONTROLCMD(w1,RichEdit,@RTGETLINE,Undo2[OnTab].LineNo[Undo2Count[OnTab]],line$,512)
						  Offset = SendMessage(rHandle,EM_LINEINDEX,Undo2[OnTab].LineNo[Undo2Count[OnTab]],0)
						  SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset + (instr(line$,chr$(13))-1))
						  CONTROLCMD w1,RichEdit,@RTREPLACESEL,""
						  SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset)

                    if instr(Undo2[OnTab].Was[Undo2Count[OnTab]],chr$(13))
                       Undo2[OnTab].Was[Undo2Count[OnTab]] = mid$(Undo2[OnTab].Was[Undo2Count[OnTab]],1,instr(Undo2[OnTab].Was[Undo2Count[OnTab]],chr$(13))-1)
                    endif

						  CONTROLCMD w1,RichEdit,@RTREPLACESEL,Undo2[OnTab].Was[Undo2Count[OnTab]]
						  CONTROLCMD(w1,RichEdit,@RTGETLINE,Undo2[OnTab].LineNo[Undo2Count[OnTab]],#cp.ClipText,512)
						  ColourLineP(rHandle,Undo2[OnTab].LineNo[Undo2Count[OnTab]],Offset)
						  SENDMESSAGE(rHandle,EM_SETSEL,Undo2[OnTab].PosBK[Undo2Count[OnTab]],Undo2[OnTab].PosBK[Undo2Count[OnTab]])

                    QuietMode(0)
                    conDrawOn(w1,RichEdit)

						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                    if FirstVisLine <> Undo2[OnTab].FirstVis[Undo2Count[OnTab]] 
							  for a = 1 to 30
								  setcontroltext(w1,a+1000,str$(FirstVisLine+a))
								  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
								  if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
									  cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
									  StoreLine = cLine
								  endif
							  next a
                    endif

						  Undo2Count[OnTab]-- 
						  if Undo2Count[OnTab] < 0 then Undo2Count[OnTab] = 0
						  Loading = 0
						  RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)

		 endselect
    endif

	 if Undo2[OnTab].Press[Undo2Count[OnTab]] <> 0
		 label RedoIncrement
		 Redo2Count[OnTab]++
		 Redo2[OnTab].Press[Redo2Count[OnTab]]  = Undo2[OnTab].Press[Undo2Count[OnTab]]
		 Redo2[OnTab].Typed[Redo2Count[OnTab]]  = Undo2[OnTab].Typed[Undo2Count[OnTab]]
		 Redo2[OnTab].Pos[Redo2Count[OnTab]]    = Undo2[OnTab].Pos[Undo2Count[OnTab]]
		 Redo2[OnTab].LineNo[Redo2Count[OnTab]] = Undo2[OnTab].LineNo[Undo2Count[OnTab]]
		 Redo2[OnTab].Offset[Redo2Count[OnTab]] = Undo2[OnTab].Offset[Undo2Count[OnTab]]
		 Redo2[OnTab].Was[Redo2Count[OnTab]]    = Undo2[OnTab].Was[Undo2Count[OnTab]]
		 Redo2[OnTab].Colour[Redo2Count[OnTab]] = Undo2[OnTab].Colour[Undo2Count[OnTab]]
		 Redo2[OnTab].Length[Redo2Count[OnTab]] = Undo2[OnTab].Length[Undo2Count[OnTab]]
       Redo2[OnTab].NewLine[Redo2Count[OnTab]] = Undo2[OnTab].NewLine[Undo2Count[OnTab]]
		 Redo2[OnTab].FirstVis[Redo2Count[OnTab]] = Undo2[OnTab].FirstVis[Undo2Count[OnTab]]
		 Redo2[OnTab].DeleteLine[Redo2Count[OnTab]] = Undo2[OnTab].DeleteLine[Undo2Count[OnTab]]

		 RetCount = 0
		 RetCount = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)

		 if LinesBeforeUndo < RetCount
			 RetCount = RetCount - LinesBeforeUndo
			 MoveBlocks(cLine,RetCount,1,9) 'Code added
			 goto DecrementUndo
		 endif
		 if LinesBeforeUndo > RetCount
			 RetCount = (LinesBeforeUndo - RetCount)  '+ 1
			 MoveBlocks(cLine,RetCount,0,10) 'Code deleted
		 endif

       label DecrementUndo

       'Do before count goes to zero otherwise we end up back at line 1 (zero)
		 if Undo2Count[OnTab] = 1
			 sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
			 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
			 setscrollpos(w1,ScrollBar,Undo2[OnTab].FirstVis[Undo2Count[OnTab]])
		 endif

		 Undo2Count[OnTab]-- 
		 if Undo2Count[OnTab] < 0 then Undo2Count[OnTab] = 0	
       if asc(Undo2[OnTab].Typed[Undo2Count[OnTab]+1]) = 22 or asc(Undo2[OnTab].Typed[Undo2Count[OnTab]+1]) = 24
          goto DoUndoAgain
       endif
	 endif
	 Loading = 0

return
endsub

sub DoRedo(hwnd:int,uMsg:int,wParam:int,lParam:pointer)
    label DoRedoAgain
    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
    showwindow w1,@SWHIDE,ListView
    int LinesBeforeRedo = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
    if Redo2Count[OnTab] = 0 then return
	 if Redo2[OnTab].Typed[Redo2Count[OnTab]] = chr$(13) + chr$(10)
       RetCount = 0
       OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
		 SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]],Redo2[OnTab].pos[Redo2Count[OnTab]]+2)
		 CONTROLCMD w1,RichEdit,@RTREPLACESEL,Redo2[OnTab].Typed[Redo2Count[OnTab]]

	    if FirstVisLine <> Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
		    sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
		    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
		    for a = 1 to 30
				  setcontroltext(w1,a+1000,str$(FirstVisLine+a))
				  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
				  if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
					  cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
					  StoreLine = cLine
				  endif
		    next a
	    endif

	    QuietMode(1)
       FirstVisLine = Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
	    ColourNow(w1,1,rHandle)
	    QuietMode(0)

	    if FirstVisLine <> Redo2[OnTab].FirstVis[Redo2Count[OnTab]]
			 sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
			 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
			 setscrollpos(w1,ScrollBar,Redo2[OnTab].FirstVis[Redo2Count[OnTab]]+1)
       endif
	    SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]],Redo2[OnTab].pos[Redo2Count[OnTab]])

	 else
       'Ignore system message
		 if asc(Redo2[OnTab].Typed[Redo2Count[OnTab]]) = 22 or asc(Redo2[OnTab].Typed[Redo2Count[OnTab]]) = 24
			 goto UndoIncrement
		 endif

    endif

	 select Redo2[OnTab].Press[Redo2Count[OnTab]] 
			  case 1 'Char Redo
                Loading = 1
                RetCount = 0
                OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
                RetCount = OldLines

                QuietMode(1)
					 SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]],Redo2[OnTab].pos[Redo2Count[OnTab]])
					 CONTROLCMD w1,RichEdit,@RTREPLACESEL,Redo2[OnTab].Typed[Redo2Count[OnTab]]
                QuietMode(0) 

                if asc(Redo2[OnTab].Typed[Redo2Count[OnTab]]) <> 13 
						 CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line$,512)
						 Offset = Redo2[OnTab].Offset[Redo2Count[OnTab]]

					    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
					    if FirstVisLine <> Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
						    sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
						    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
						    for a = 1 to 30
								 setcontroltext(w1,a+1000,str$(Redo2[OnTab].FirstVis[Redo2Count[OnTab]]+a))
								 SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
								 if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
									 cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
									 StoreLine = cLine
								 endif
						    next a
					    endif

                   QuietMode(1)
                   #cp.ClipText = line$
						 'ColourLineP(rHandle,cLine-1,Offset)
                   'Offset = SendMessage(rHandle,EM_LINEINDEX,cLine,0)
						 'ColourLineP(rHandle,cLine,Offset)
							  FirstVisLine = Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
							  ColourNow(w1,1,rHandle)

                   QuietMode(0)

						 sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
						 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
						 SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]]+1,Redo2[OnTab].pos[Redo2Count[OnTab]]+1) 
                   Loading = 0
                endif

			  case  2 'Backspace Redo Single character
			  case& 3 'Delete Redo Single character
                 Loading = 1 
                 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)

                 if Redo2[OnTab].Press[Redo2Count[OnTab]] = 2
                    SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]]-1,Redo2[OnTab].pos[Redo2Count[OnTab]])
                 else
					     SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]],Redo2[OnTab].pos[Redo2Count[OnTab]]+1)
                 endif

                 QuietMode(1)
					  CONTROLCMD w1,RichEdit,@RTDELETESEL
                 QuietMode(0)

					  CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line$,512)
					  Offset = Redo2[OnTab].Offset[Redo2Count[OnTab]]

					  if FirstVisLine <> Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
						  sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
					  endif

					  int b2
					  QuietMode(1) 
					  for b2 = Redo2[OnTab].FirstVis[Redo2Count[OnTab]]  to Redo2[OnTab].FirstVis[Redo2Count[OnTab]]  + 35
						   CONTROLCMD(w1,RichEdit,@RTGETLINE,b2,#cp.ClipText,512)
						   if len(ltrim$(#cp.ClipText)) < 3 then goto CheckNextLineR
						   Offset = SendMessage(rHandle,EM_LINEINDEX,b2,0)
						   ColourLineP(rHandle,b2-1,Offset)
					  label CheckNextLineR
					  next b2
					  QuietMode(0)

					  if FirstVisLine <> Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) 
						  for a = 1 to 30
							   setcontroltext(w1,a+1000,str$(FirstVisLine+a))
							   SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
							   if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
								   cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
								   StoreLine = cLine
							   endif
						  next a
					  endif

					  sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
					  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
					  SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]],Redo2[OnTab].pos[Redo2Count[OnTab]])
                 Loading = 0

			  case 4 'Cut Redo
					 Loading = 1
                RetCount = 0
                OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)

                QuietMode(1)
					 SendMessage(rHandle,EM_SETSEL,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]],RedoBlock[OnTab].EndPos[Redo2Count[OnTab]])
					 CONTROLCMD w1,RichEdit,@RTDELETESEL
				    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
				    ColourNow(w1,1,rHandle)
                QuietMode(0)

					 Undo2Count[OnTab]++
					 Undo2[OnTab].Press[Undo2Count[OnTab]]           = Redo2[OnTab].Press[Redo2Count[OnTab]]
                Undo2[OnTab].FirstVis[Undo2Count[OnTab]]        = Redo2[OnTab].FirstVis[Redo2Count[OnTab]]
					 UndoBlock[OnTab].UndoCount[Undo2Count[OnTab]]   = RedoBlock[OnTab].UndoCount[Redo2Count[OnTab]] 
					 UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]    = RedoBlock[OnTab].StartPos[Redo2Count[OnTab]]
					 UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]      = RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]
					 UndoBlock[OnTab].Length[Undo2Count[OnTab]]      = RedoBlock[OnTab].Length[Redo2Count[OnTab]]
					 UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]      = RedoBlock[OnTab].LineNo[Redo2Count[OnTab]]
					 UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]] = RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]]
					 SendMessage(rHandle,EM_SETSEL,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]],RedoBlock[OnTab].StartPos[Redo2Count[OnTab]])
					 setfocus w1,RichEdit

                'Line number can vary depending on speed of key press
					 int a1
					 int SubDeleteLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]])
					 int NewDeletePos = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
					 for a1 = 0 to NewDeletePos - 1
						  CONTROLCMD w1,ListView2,@LVGETTEXT,a1,1,text
						  if val(text) = SubDeleteLine - 1
							  CONTROLCMD(w1,ListView2,@LVDELETEITEM,a1)
							  deletestring(w1,Combo2,a1)
							  breakfor
						  endif
						  if val(text) = SubDeleteLine
							  CONTROLCMD(w1,ListView2,@LVDELETEITEM,a1)
							  deletestring(w1,Combo2,a1)
							  breakfor 
						  endif
						  if val(text) = SubDeleteLine + 1 'Usually this one
							  CONTROLCMD(w1,ListView2,@LVDELETEITEM,a1)
							  deletestring(w1,Combo2,a1)
							  breakfor
						  endif
					 next a1

					 for a1 = 0 to NewDeletePos - 1
						  CONTROLCMD w1,ListView4,@LVGETTEXT,a1,1,text
						  if val(text) = SubDeleteLine - 1
							  CONTROLCMD(w1,ListView4,@LVDELETEITEM,a1)
							  deletestring(w1,Combo4,a1)
							  breakfor
						  endif
						  if val(text) = SubDeleteLine
							  CONTROLCMD(w1,ListView4,@LVDELETEITEM,a1)
							  deletestring(w1,Combo4,a1)
							  breakfor 
						  endif
						  if val(text) = SubDeleteLine + 1 'Usually this one
							  CONTROLCMD(w1,ListView4,@LVDELETEITEM,a1)
							  deletestring(w1,Combo4,a1)
							  breakfor
						  endif
					 next a1

                RetCount = 0
                RetCount = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)

					 if LinesBeforeRedo < RetCount
						 RetCount = RetCount - LinesBeforeRedo
						 MoveBlocks(cLine,RetCount,1,13) 'Code added
						 goto R1
					 endif
					 if LinesBeforeRedo > RetCount
						 RetCount = (LinesBeforeRedo - RetCount)
						 MoveBlocks(cLine,RetCount,0,14) 'Code deleted
					 endif

                Label R1 

					 sRange.Low = (cLine-2) * LineSpace
					 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
					 SETSCROLLPOS w1,ScrollBar,cLine

					 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
					 SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset)
					 setfocus w1,RichEdit

                FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
				    if FirstVisLine <> Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
					    sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
					    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
					    for a = 1 to 30
							  setcontroltext(w1,a+1000,str$(FirstVisLine+a))
							  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
							  if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
								  cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
								  StoreLine = cLine
							  endif
					    next a
				    endif

				    QuietMode(1)
				    FirstVisLine = Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
				    ColourNow(w1,1,rHandle)
				    QuietMode(0)

				    sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
				    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
					 SendMessage(rHandle,EM_SETSEL,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]],RedoBlock[OnTab].StartPos[Redo2Count[OnTab]])
                setfocus w1,RichEdit

					 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
					 for a = 1 to 30
						  setcontroltext(w1,a+1000,str$(FirstVisLine+a))
						  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
						  if (FirstVisLine+a) = cLine
							  setcontroltext(w1,a+1000,"> " + getcontroltext(w1,a+1000))
							  SETCONTROLCOLOR w1,a+1000,Red,BackColour
						  endif
					 next a

					 Redo2Count[OnTab] --  
					 if Redo2Count[OnTab] < 0 then Redo2Count[OnTab] = 0
					 Loading = 0 
                starttimer w1,TimerSpeed1,MainTimer 
					 RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)

			  case 5 'Paste Redo
				    Loading = 1 
				    RetCount = 0

                QuietMode(1) 
				    OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
				    SendMessage(rHandle,EM_SETSEL,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]],RedoBlock[OnTab].StartPos[Redo2Count[OnTab]])
				    CONTROLCMD w1,RichEdit,@RTREPLACESEL,RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]]
				    SendMessage(rHandle,EM_SETSEL,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]],RedoBlock[OnTab].StartPos[Redo2Count[OnTab]])
                QuietMode(0)

				    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)

				    if FirstVisLine <> Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
					    sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
					    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
					    for a = 1 to 30
							  setcontroltext(w1,a+1000,str$(FirstVisLine+a))
							  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
							  if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
								  cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
								  StoreLine = cLine
							  endif
					    next a
				    endif

					 sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
					 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)

                FirstVisLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]])

                QuietMode(1)
				    ColourNow(w1,1,rHandle)
                QuietMode(0)

				    SendMessage(rHandle,EM_SETSEL,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]+1,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]+1)
				    setfocus w1,RichEdit

				    Undo2Count[OnTab]++
				    Undo2[OnTab].Press[Undo2Count[OnTab]]           = Redo2[OnTab].Press[Redo2Count[OnTab]]
                Undo2[OnTab].FirstVis[Undo2Count[OnTab]]        = Redo2[OnTab].FirstVis[Redo2Count[OnTab]]
				    UndoBlock[OnTab].UndoCount[Undo2Count[OnTab]]   = RedoBlock[OnTab].UndoCount[Redo2Count[OnTab]] 
				    UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]    = RedoBlock[OnTab].StartPos[Redo2Count[OnTab]]
				    UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]      = RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]
				    UndoBlock[OnTab].Length[Undo2Count[OnTab]]      = RedoBlock[OnTab].Length[Redo2Count[OnTab]]
				    UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]      = RedoBlock[OnTab].LineNo[Redo2Count[OnTab]]
				    UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]] = RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]]

				    Redo2Count[OnTab] --  
				    if Redo2Count[OnTab] < 0 then Redo2Count[OnTab] = 0

                RetCount = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
					 if LinesBeforeRedo < RetCount
						 RetCount = RetCount - LinesBeforeRedo
						 MoveBlocks(cLine,RetCount,1,15) 'Code added
						 goto R2
					 endif
					 if LinesBeforeRedo > RetCount
						 RetCount = (LinesBeforeRedo - RetCount)  '+ 1
						 MoveBlocks(cLine,RetCount,0,16) 'Code deleted
					 endif
                label R2 
				    'Add any sub routine that was cut back into the list of sub routines
				    int LastLineCut = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]])
				    int FirstLineCut = (LastLineCut-abs(RetCount))+1
				    LastLineCut ++

                'Add sub routine to list of sub routines
                for c1 = FirstLineCut to LastLineCut
						  CONTROLCMD(w1,RichEdit,@RTGETLINE,c1-1,line$,512)
						  Offset = SendMessage(rHandle,EM_LINEINDEX,c1-1,0)

						  GetWordsOnLine(rHandle,c1-1,line$,Offset)

						  if ucase$(#w[1].aWord) = "SUB"
							  INT position = CONTROLCMD(w1,ListView2,@LVFINDITEM,#w[2].aWord)
							  if position = -1
								  int NoDelSub = 1
								  int NewInsertPos = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
								  CONTROLCMD w1,ListView2,@LVINSERTITEM,NewInsertPos,#w[2].aWord
								  position = CONTROLCMD(w1,ListView2,@LVFINDITEM,#w[2].aWord)
								  CONTROLCMD w1,ListView2,@LVSETTEXT,position,1,LTRIM$(STR$(c1))
								  CONTROLCMD w1,ListView2,@LVSETTEXT,position,2,LTRIM$(STR$(c1))
								  SendMessage(GetDlgItem(w1.hwnd,Combo2),CB_RESETCONTENT,0,0)
								  int lvcount22 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
								  if lvcount22 > 0 
									  StoreSubs()
									  PopulateSubRoutines()
								  endif
							  endif
				        endif

						  if ucase$(#w[1].aWord) = "ENDSUB"
							  CONTROLCMD w1,ListView2,@LVSETTEXT,position,2,LTRIM$(STR$(c1))
						  endif

						  if ucase$(#w[1].aWord) = "OPENWINDOW"
							  position = CONTROLCMD(w1,ListView4,@LVFINDITEM,#w[2].aWord)
							  if position = -1
								  int NoDelWin = 1
								  NewInsertPos = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
								  CONTROLCMD w1,ListView4,@LVINSERTITEM,NewInsertPos,#w[2].aWord
								  position = CONTROLCMD(w1,ListView4,@LVFINDITEM,#w[2].aWord)
								  CONTROLCMD w1,ListView4,@LVSETTEXT,position,1,LTRIM$(STR$(c1))
								  CONTROLCMD w1,ListView4,@LVSETTEXT,position,2,LTRIM$(STR$(c1))
								  SendMessage(GetDlgItem(w1.hwnd,Combo4),CB_RESETCONTENT,0,0)
								  lvcount22 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
								  if lvcount22 > 0 
									  PopulateWindows()
								  endif
							  endif
				        endif

						  if ucase$(#w[1].aWord) = "WAITUNTIL"
							  CONTROLCMD w1,ListView4,@LVSETTEXT,position,2,LTRIM$(STR$(c1))
						  endif

                Next c1

				    starttimer w1,TimerSpeed1,MainTimer
				    Loading = 0
                setscrollpos(w1,ScrollBar,LastLineCut-1)
					 sRange.Low = (LastLineCut-1) * LineSpace
					 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)

				    'Correct line numbers and set >
				    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
				    for a1 = 1 to 30
						  setcontroltext(w1,a1+1000,str$(FirstVisLine+(a1)))
						  SETCONTROLCOLOR w1,a1+1000,RGB(0,0,0),BackColour
						  if LastLineCut = FirstVisLine+a1
							  setcontroltext(w1,1000 + a1,"> " + getcontroltext(w1,1000 + a1))
							  SETCONTROLCOLOR w1,1000 + a1,Red,BackColour
						  endif
				    next a1
				    RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)

			  case 6 'Tab Redo
                RetCount = 0
                OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
                RetCount = OldLines
					 SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]]-1,Redo2[OnTab].pos[Redo2Count[OnTab]])
					 CONTROLCMD w1,RichEdit,@RTREPLACESEL,Redo2[OnTab].Typed[Redo2Count[OnTab]]
                if asc(Redo2[OnTab].Typed[Redo2Count[OnTab]]) <> 13 
						 CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line$,512)
						 Offset = Redo2[OnTab].Offset[Redo2Count[OnTab]]

					    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
					    if FirstVisLine <> Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
						    sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
						    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
						    for a = 1 to 30
								 setcontroltext(w1,a+1000,str$(Redo2[OnTab].FirstVis[Redo2Count[OnTab]]+a))
								 SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
								 if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
									 cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
									 StoreLine = cLine
								 endif
						    next a
					    endif

                   QuietMode(1)
                   #cp.ClipText = line$
						 ColourLineP(rHandle,cLine-1,Offset)
                   QuietMode(0)

						 sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
						 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
						 SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]],Redo2[OnTab].pos[Redo2Count[OnTab]]) 

                endif

			  case 7 'Replace Redo (Find & Replace)
				    Loading = 1
				    int eendpos = len(Redo2[OnTab].Typed[Redo2Count[OnTab]]) 
				    eendpos = (eendpos + Redo2[OnTab].Offset[Redo2Count[OnTab]])

                QuietMode(1)
				    SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].Offset[Redo2Count[OnTab]],eendpos)
				    CONTROLCMD w1,RichEdit,@RTREPLACESEL,""
				    SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].Offset[Redo2Count[OnTab]],Redo2[OnTab].Offset[Redo2Count[OnTab]])
				    CONTROLCMD w1,RichEdit,@RTREPLACESEL,Redo2[OnTab].Typed[Redo2Count[OnTab]]
				    setscrollpos(w1,ScrollBar,Redo2[OnTab].LineNo[Redo2Count[OnTab]]-2)
				    FirstVisLine = Redo2[OnTab].LineNo[Redo2Count[OnTab]]-2 
				    int RedLine = CONTROLCMD w1,RichEdit,@RTLINEFROMCHAR,Redo2[OnTab].Offset[Redo2Count[OnTab]]+ 1

				    for a = 1 to 30
						  setcontroltext(w1,a+1000,str$((FirstVisLine) + (a+1)))
						  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
						  if RedLine = (FirstVisLine+2) + (a+1)
							  setcontroltext(w1,a+1000,"> " +str$((FirstVisLine) + (a+1)))
							  SETCONTROLCOLOR w1,a+1000,Red,BackColour
						  endif
				    next a

				    sRange.Low = Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace
				    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
				    setscrollpos(w1,ScrollBar,Redo2[OnTab].FirstVis[Redo2Count[OnTab]]+1)
				    cLine = GETSCROLLPOS(w1,ScrollBar)
				    StoreLine = cLine

				    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
				    ColourNow(w1,0,rHandle)
				    QuietMode(0)

				    sRange.Low = Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace
				    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
				    setscrollpos(w1,ScrollBar,Redo2[OnTab].FirstVis[Redo2Count[OnTab]]+1)

				    SendMessage(rHandle,EM_SETSEL,eendpos,eendpos)
				    setfocus w1,RichEdit

				case 8 'Backspace delete line
						  if Redo2[OnTab].DeleteLine[Redo2Count[OnTab]] = 1 'Delete line
							  RetCount = 0
							  OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
							  CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line$,512)
							  Offset = Redo2[OnTab].Offset[Redo2Count[OnTab]]
							  SendMessage(rHandle,EM_SETSEL,Offset-1,Offset)              
							  CONTROLCMD w1,RichEdit,@RTDELETESEL

							  if FirstVisLine <> Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
								  sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
								  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
								  for a = 1 to 30
									   setcontroltext(w1,a+1000,str$(FirstVisLine+a))
									   SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
									   if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										   cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										   StoreLine = cLine
									   endif
								  next a
							  endif

							  QuietMode(1)
							  FirstVisLine = Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
							  ColourNow(w1,1,rHandle)
							  QuietMode(0)

							  sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
                       Offset = Redo2[OnTab].Offset[Redo2Count[OnTab]]
                       SendMessage(rHandle,EM_SETSEL,Offset,Offset)
							  goto UndoIncrement
						  endif
 
               case 9 'Delete line
						  if asc(Redo2[OnTab].Typed[Redo2Count[OnTab]]) = 10
							  RetCount = 0
							  OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
							  SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]]-2,Redo2[OnTab].pos[Redo2Count[OnTab]])
							  CONTROLCMD w1,RichEdit,@RTDELETESEL

							  if FirstVisLine <> Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
								  sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
								  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
								  for a = 1 to 30
									   setcontroltext(w1,a+1000,str$(FirstVisLine+a))
									   SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
									   if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										   cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
										   StoreLine = cLine
									   endif
								  next a
							  endif

							  QuietMode(1)
							  FirstVisLine = Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
							  ColourNow(w1,1,rHandle)
							  QuietMode(0)

							  sRange.Low = (Redo2[OnTab].FirstVis[Redo2Count[OnTab]] * LineSpace)
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)
							  SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]],Redo2[OnTab].pos[Redo2Count[OnTab]])
						  endif

				case 10 'Keyword Redo
                 Loading = 1
					  Undo2Count[OnTab]++
					  Undo2[OnTab].Press[Undo2Count[OnTab]]  = Redo2[OnTab].Press[Redo2Count[OnTab]]
					  Undo2[OnTab].Typed[Undo2Count[OnTab]]  = Redo2[OnTab].Typed[Redo2Count[OnTab]]
					  Undo2[OnTab].Pos[Undo2Count[OnTab]]    = Redo2[OnTab].Pos[Redo2Count[OnTab]]
					  Undo2[OnTab].LineNo[Undo2Count[OnTab]] = Redo2[OnTab].LineNo[Redo2Count[OnTab]]
					  Undo2[OnTab].Offset[Undo2Count[OnTab]] = Redo2[OnTab].Offset[Redo2Count[OnTab]]
					  Undo2[OnTab].Was[Undo2Count[OnTab]]    = Redo2[OnTab].Was[Redo2Count[OnTab]]
					  Undo2[OnTab].Colour[Undo2Count[OnTab]] = Redo2[OnTab].Colour[Redo2Count[OnTab]]
					  Undo2[OnTab].Length[Undo2Count[OnTab]] = Redo2[OnTab].Length[Redo2Count[OnTab]]
					  Undo2[OnTab].PosBK[Undo2Count[OnTab]]  = Redo2[OnTab].PosBK[Redo2Count[OnTab]]
					  Undo2[OnTab].PosAK[Undo2Count[OnTab]]  = Redo2[OnTab].PosAK[Redo2Count[OnTab]]
                 Undo2[OnTab].NewLine[Undo2Count[OnTab]] = Redo2[OnTab].NewLine[Redo2Count[OnTab]]
                 Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = Redo2[OnTab].FirstVis[Redo2Count[OnTab]]
					  Undo2[OnTab].DeleteLine[Undo2Count[OnTab]] = Redo2[OnTab].DeleteLine[Redo2Count[OnTab]]

                 conDrawOff(w1,RichEdit)
                 QuietMode(1)

					  CONTROLCMD(w1,RichEdit,@RTGETLINE,Redo2[OnTab].LineNo[Redo2Count[OnTab]],line$,512)
					  Offset = SendMessage(rHandle,EM_LINEINDEX,Redo2[OnTab].LineNo[Redo2Count[OnTab]],0)
					  SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset + (instr(line$,chr$(13))-1))
					  CONTROLCMD w1,RichEdit,@RTREPLACESEL,""
					  SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset)

					  if instr(Redo2[OnTab].Was[Redo2Count[OnTab]],chr$(13))
						  Redo2[OnTab].Was[Redo2Count[OnTab]] = mid$(Redo2[OnTab].Was[Redo2Count[OnTab]],1,instr(Redo2[OnTab].Was[Redo2Count[OnTab]],chr$(13))-1)
					  endif

					  CONTROLCMD w1,RichEdit,@RTREPLACESEL,Redo2[OnTab].Typed[Redo2Count[OnTab]]
					  CONTROLCMD(w1,RichEdit,@RTGETLINE,Redo2[OnTab].LineNo[Redo2Count[OnTab]],#cp.ClipText,512)
					  ColourLineP(rHandle,Redo2[OnTab].LineNo[Redo2Count[OnTab]],Offset)
							  'FirstVisLine = Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
							  'ColourNow(w1,1,rHandle)


					  SENDMESSAGE(rHandle,EM_SETSEL,Redo2[OnTab].PosAK[Redo2Count[OnTab]],Redo2[OnTab].PosAK[Redo2Count[OnTab]])
                 setfocus w1,RichEdit

                 QuietMode(0)
                 conDrawOn(w1,RichEdit)
  
					  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
					  if FirstVisLine <> Redo2[OnTab].FirstVis[Redo2Count[OnTab]] 
						  for a = 1 to LinesPerPage
							  setcontroltext(w1,a+1000,str$(FirstVisLine+a))
							  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
							  if FirstVisLine+a = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
								  cLine = CONTROLCMD(w1,RichEdit,@RTLINEFROMCHAR,EditPos)
								  StoreLine = cLine
							  endif
						  next a
					  endif

					  Redo2Count[OnTab]--  
					  if Redo2Count[OnTab] <= 0 then Redo2Count[OnTab] = 0
                 setfocus w1,RichEdit
					  Loading = 0
					  RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
				        
    endselect

	 if Redo2[OnTab].Press[Redo2Count[OnTab]] > 0
		 label UndoIncrement
		 Undo2Count[OnTab]++
		 Undo2[OnTab].Press[Undo2Count[OnTab]]  = Redo2[OnTab].Press[Redo2Count[OnTab]]
		 Undo2[OnTab].Typed[Undo2Count[OnTab]]  = Redo2[OnTab].Typed[Redo2Count[OnTab]]
		 Undo2[OnTab].Pos[Undo2Count[OnTab]]    = Redo2[OnTab].Pos[Redo2Count[OnTab]]
		 Undo2[OnTab].LineNo[Undo2Count[OnTab]] = Redo2[OnTab].LineNo[Redo2Count[OnTab]]
		 Undo2[OnTab].Offset[Undo2Count[OnTab]] = Redo2[OnTab].Offset[Redo2Count[OnTab]]
		 Undo2[OnTab].Was[Undo2Count[OnTab]]    = Redo2[OnTab].Was[Redo2Count[OnTab]]
		 Undo2[OnTab].Colour[Undo2Count[OnTab]] = Redo2[OnTab].Colour[Redo2Count[OnTab]]
		 Undo2[OnTab].Length[Undo2Count[OnTab]] = Redo2[OnTab].Length[Redo2Count[OnTab]]
       Undo2[OnTab].NewLine[Undo2Count[OnTab]] = Redo2[OnTab].NewLine[Redo2Count[OnTab]]
		 Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = Redo2[OnTab].FirstVis[Redo2Count[OnTab]]
		 Undo2[OnTab].DeleteLine[Undo2Count[OnTab]] = Redo2[OnTab].DeleteLine[Redo2Count[OnTab]]
		 Redo2Count[OnTab] -- 
''print "DEFAULT Redo Press ",Redo2[OnTab].Press[Redo2Count[OnTab]]
		 if Redo2Count[OnTab] < 0 then Redo2Count[OnTab] = 0

		 RetCount = 0
		 RetCount = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
		 if LinesBeforeRedo < RetCount
			 RetCount = RetCount - LinesBeforeRedo
			 MoveBlocks(cLine,RetCount,1,17) 'Code added
			 goto Rend
		 endif
		 if LinesBeforeRedo > RetCount
			 RetCount = (LinesBeforeRedo - RetCount)  '+ 1
			 MoveBlocks(cLine,RetCount,0,18) 'Code deleted
		 endif

       label Rend
       if asc(Redo2[OnTab].Typed[Redo2Count[OnTab]+1]) = 22 or asc(Redo2[OnTab].Typed[Redo2Count[OnTab]+1]) = 24
          goto DoRedoAgain
       endif

       starttimer w1,TimerSpeed1,MainTimer
       Loading = 0
	 endif
endsub

sub ColourTextScroll()
Scrolling = 1
	 FirstVisLine = val(getcontroltext w1,EDIT_1)-1

	 for a = 1 to 30
		  setcontroltext(w1,a+1000,str$(FirstVisLine+(a)))
        SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour 
	 next a

    QuietMode(1)

    NoNotify = 1
    showcursor(FALSE)
	 OnLine = FirstVisLine
    CommentBlockStart = 0
    CommentBlockEnd = 0
	 for a = FirstVisLine -1 to FirstVisLine + LinesPerPage
		  CONTROLCMD(w1,RichEdit,@RTGETLINE,a-1,#cp.ClipText,512)
		  if len(ltrim$(#cp.ClipText)) < 3 then goto CheckNextLine
		  Offset = SendMessage(rHandle,EM_LINEINDEX,a-1,0)
		  ColourLineP(rHandle,a-1,Offset)
	 label CheckNextLine
	 next a

    'BlockCommentCheck()

    QuietMode(0)

    showcursor(TRUE)
    NoNotify = 0

    if FirstVisLine = 0
	    'setcontroltext(w1,4,"1")
    else
	    'setcontroltext(w1,4,ltrim$(str$(FirstVisLine)))
    endif

Scrolling = 0
return
endsub

sub DeleteBlock()
	 if OnBlock = 1
		 setcontroltext(w1,TextBlock1,"")
		 enablecontrol w1,ShowBlock1,0
		 FocusMain()  
	 endif 
	 if OnBlock = 2
		 setcontroltext(w1,TextBlock2,"")
		 enablecontrol w1,ShowBlock2,0
		 FocusMain()  
	 endif 
	 if OnBlock = 3
		 setcontroltext(w1,TextBlock3,"")
		 enablecontrol w1,ShowBlock3,0
		 FocusMain()  
	 endif 
	 if OnBlock = 4
		 setcontroltext(w1,TextBlock4,"")
		 enablecontrol w1,ShowBlock4,0
		 FocusMain()  
	 endif 
endsub

Sub conLVSetCheckState(win:Window,cid:Int,index:Int,ticked:Int)
   Def litem:LVITEM
   litem.mask=LVIF_STATE
   If ticked Then ticked = 0x2000 Else ticked = 0x1000
   litem.state=ticked
   litem.stateMask=LVIS_STATEIMAGEMASK
   SendMessage(win,LVM_SETITEMSTATE,index,litem,cid)
   Return
EndSub
Sub conLVGetCheckState(win:Window,cid:Int,index:Int),Int
Def n:Int
   'State image 1 is the unchecked box, and state image 2 is the checked box.
   'Setting the state image To zero removes the check box altogether.
   n=(SendMessage(win,LVM_GETITEMSTATE,index,LVIS_STATEIMAGEMASK,cid))/4096
   Return (n=2)
EndSub

sub Cut()
    StarTabs()
    int LinesBeforeCut = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)  
	  if len(CutLine)
		  SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
		  Undo2Count[OnTab]++
		  Undo2[OnTab].Press[Undo2Count[OnTab]] = 4
		  Undo2[OnTab].Length[Undo2Count[OnTab]] = len(ClipText)
        Undo2[OnTab].FirstVis[Undo2Count[OnTab]] = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
		  UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]] = ClipText
		  UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] = cr.cpMin
		  UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] = cr.cpMax
		  UndoBlock[OnTab].Length[Undo2Count[OnTab]] = len(ClipText)
		  UndoBlock[OnTab].LineNo[Undo2Count[OnTab]] = cLine-1
	  endif

     RetCount = 0
     OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
	  CopyStringToClipboard(CutLine)
     ClipText2 = CutLine
	  SendMessage(rHandle,EM_SETSEL,cr.cpMin,cr.cpMax)
	  CONTROLCMD w1,RichEdit,@RTDELETESEL

     RetCount = 0
     RetCount = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
     RetCount = LinesBeforeCut - RetCount
     MoveBlocks(cLine,RetCount,0,11180) 'Code deleted

	  ColourText() 

	  SendMessage(rHandle,EM_SETSEL,cr.cpMin,cr.cpMin)
	  sRange.Low = (Undo2[OnTab].FirstVis[Undo2Count[OnTab]] * LineSpace)
	  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,RichEdit)

	  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
	  int RedLine = cLine

	  for a = 1 to 30
			setcontroltext(w1,a+1000,str$((FirstVisLine) + a))
			SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
			if RedLine = FirstVisLine + a
				setcontroltext(w1,a+1000,"> " +str$((FirstVisLine) + a))
				SETCONTROLCOLOR w1,a+1000,Red,BackColour
			endif
	  next a
return
endsub

sub Paste()
    Loading = 1
    DoPaste()

    QuietMode(1)
    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
    ColourNow(w1,1,rHandle)
    QuietMode(0)

    SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]+1,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]+1)
    setfocus w1,RichEdit
    Loading = 0
    int NewRange = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
    SETSCROLLRANGE w1,ScrollBar,0,NewRange
return
endsub

SUB DoGetSubZ(INT LineNoIn,STRING LineToWords,opt int MaxWordsIn)
    'if !instr(ucase$(LineToWords),"SUB") and !instr(ucase$(LineToWords),"OPENWINDOW") and !instr(ucase$(LineToWords),"$INCLUDE") and !instr(ucase$(LineToWords),"CREATEDIALOG") and !instr(ucase$(LineToWords),"CONTROL") and !instr(ucase$(LineToWords),"CASE") then return
    LineToWords = rtrim$(ltrim$(LineToWords))
    LineLenZ = LEN(LineToWords)
    CheckWordZ1 = 1
    WordIn = ""
    WordCount = 0
    #w[1].aWord = ""
    #w[2].aWord = ""
    int Comments = 0

    FOR bz = 1 TO LineLenZ

        ThisPos = bz 
        Letter = LineToWords[bz-1]

        if Letter = chr$(34) and ucase$(#w[1].aWord) <> "$INCLUDE"
           do 
              bz++
              Letter = LineToWords[bz-1]
           until Letter = chr$(34) or bz = LineLenZ
        endif

        if Letter = chr$(34) and ucase$(#w[1].aWord) = "$INCLUDE"
           bz++
           Letter = LineToWords[bz-1]
        endif

        DelZ = INSTR(CheckDelimiter,Letter) 'CheckDelimiter
        if Letter = "_" then goto AddAnyway
        if ucase$(#w[1].aWord) = "$INCLUDE" and Letter = "." then goto AddAnyway
        if Letter = "'"
           Comments = 1
        endif      

        SELECT DelZ

               CASE 0 'Add character to our word
                    label AddAnyway
                    if CheckWordZ1
                       if ucase$(Letter) <> "S" and ucase$(Letter) <> "O" and ucase$(Letter) <> "$"  and ucase$(Letter) <> "C" and WordCount = 0 then return
                       CheckWordZ1 = 0
                    endif
                    WordIn = WordIn + Letter

               DEFAULT 'Delimiter found - so we have our word
                     IF LEN(WordIn)> 0 and WordIn <> " "
                        StartPos = (ThisPos - LEN(WordIn))-1
                        EndPos   = ThisPos-1
                        WordCount ++
                        #w[WordCount].aWord = WordIn 
                        if ucase$(#w[1].aWord) <> "SUB" and ucase$(#w[1].aWord) <> "OPENWINDOW" and ucase$(#w[1].aWord) <> "CREATEDIALOG" and ucase$(#w[1].aWord) <> "CONTROL" and ucase$(#w[1].aWord) <> "$INCLUDE" then return 
                        if WordCount = MaxWordsIn and ucase$(#w[1].aWord) = "SUB"
								   if instr(LineToWords,"'")
									   if StartPos > instr(LineToWords,"'") then return
								   endif
                           'Add to subroutines
									CONTROLCMD w1,ListView2,@LVINSERTITEM,0,#w[2].aWord
									PositionZ = CONTROLCMD(w1,ListView2,@LVFINDITEM,#w[2].aWord)
									CONTROLCMD w1,ListView2,@LVSETTEXT,PositionZ,1,LTRIM$(STR$(LineNoIn))
									CONTROLCMD w1,ListView2,@LVSETTEXT,PositionZ,2,LTRIM$(STR$(LineNoIn))
                           breakfor
                        endif

                        if WordCount = MaxWordsIn 
                           if ucase$(#w[1].aWord) = "OPENWINDOW" or ucase$(#w[1].aWord) = "CREATEDIALOG"
										'Add to windows
										CONTROLCMD w1,ListView4,@LVINSERTITEM,0,#w[2].aWord
										int lvcountIn = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
										int c1
										string text
										for c1 = 0 to lvcountIn - 1
											 CONTROLCMD w1,ListView4,@LVGETTEXT,c1,1,text
											 if rtrim$(ltrim$(text)) = "" 
												 CONTROLCMD w1,ListView4,@LVSETTEXT,c1,1,LTRIM$(STR$(LineNoIn))
												 breakfor
											 endif
										next c1
										breakfor
                           endif
                        endif

                        if WordCount = MaxWordsIn and ucase$(#w[1].aWord) = "$INCLUDE"
								   if instr(LineToWords,"'")
									   if StartPos > instr(LineToWords,"'") then return
								   endif
                           'Add to include files
                           ADDSTRING w1,Combo88,#w[2].aWord
                           breakfor
                        endif
                     ENDIF
                     if Comments = 1 
                        Breakfor
                     endif
                     label NextWord
                     WordIn = ""
         ENDSELECT
   NEXT bz

   'Add to controls
   if ucase$(#w[1].aWord) = "CONTROL" and #w[WordCount].aWord <> ""
		CONTROLCMD w1,ListView10,@LVINSERTITEM,0,#w[WordCount].aWord
		PositionZ = CONTROLCMD(w1,ListView10,@LVFINDITEM,#w[WordCount].aWord)
		CONTROLCMD w1,ListView10,@LVSETTEXT,PositionZ,1,LTRIM$(STR$(LineNoIn))
		CONTROLCMD w1,ListView10,@LVSETTEXT,PositionZ,2,ucase$(#w[2].aWord)
		CONTROLCMD w1,ListView10,@LVSETTEXT,PositionZ,3,ucase$(#w[3].aWord)
   endif

return
endsub

SUB DoGetEndSubZ(INT LineNoIn,STRING LineToWords,opt int MaxWordsIn)
    if !instr(ucase$(LineToWords),"SUB") then return
    LineToWords = rtrim$(ltrim$(LineToWords))
    LineLenZ = LEN(LineToWords)
    CheckWordZ1 = 1
    WordIn = ""
    WordCount = 0
    EndSubFound = 0

    FOR bz = 1 TO LineLenZ

        ThisPos = bz 
        Letter = LineToWords[bz-1]
        DelZ = INSTR(CheckLetter2,Letter)

        SELECT DelZ

               CASE 0 'Add character to our word
                    if CheckWordZ1
                       if ucase$(Letter) <> "S" and ucase$(Letter) <> "E" and WordCount = 0 then return
                       CheckWordZ1 = 0
                    endif
                    WordIn = WordIn + Letter

               DEFAULT 'Delimiter found - so we have our word
                     IF LEN(WordIn)> 1 'Key words are at least 2 characrers long
                        StartPos = (ThisPos - LEN(WordIn))-1
                        EndPos   = ThisPos-1
                        WordCount ++
                        #w[WordCount].aWord = WordIn 
                        if ucase$(#w[1].aWord) <> "SUB" and ucase$(#w[1].aWord) <> "ENDSUB" then return 
                        if ucase$(#w[1].aWord) = "SUB"
                           EndSubFound = 2
                           breakfor 
                        endif
                        if ucase$(#w[1].aWord) = "ENDSUB"
                           EndSubFound = 1 
                           breakfor
                        endif 
                     ENDIF
                     WordIn = ""
                     if WordCount = MaxWordsIn
                        breakfor
                     endif
         ENDSELECT
   NEXT bz

return 0
endsub

SUB DoGetEndWinZ(INT LineNoIn,STRING LineToWords,opt int MaxWordsIn)
    LineToWords = rtrim$(ltrim$(LineToWords))
    LineLenZ = LEN(LineToWords)
    CheckWordZ1 = 1
    WordIn = ""
    WordCount = 0
    EndWinFound = 0

    FOR bz = 1 TO LineLenZ

        ThisPos = bz 
        Letter = LineToWords[bz-1]
        DelZ = INSTR(CheckLetter2,Letter)

        SELECT DelZ

               CASE 0 'Add character to our word
                    if CheckWordZ1
                       if ucase$(Letter) <> "W" and ucase$(Letter) <> "E" and ucase$(Letter) <> "C" and WordCount = 0 then return
                       CheckWordZ1 = 0
                    endif
                    WordIn = WordIn + Letter

               DEFAULT 'Delimiter found - so we have our word
                     IF LEN(WordIn)> 1 'Key words are at least 2 characrers long
                        StartPos = (ThisPos - LEN(WordIn))-1
                        EndPos   = ThisPos-1
                        WordCount ++
                        #w[WordCount].aWord = WordIn 
                        if ucase$(#w[1].aWord) <> "WAITUNTIL" then return 
                        if ucase$(#w[1].aWord) = "WAITUNTIL"
                           EndWinFound = 1 
                           breakfor
                        endif 
                        if ucase$(#w[1].aWord) = "ENDSUB"
                           EndWinFound = 1 
                           breakfor
                        endif 
                     ENDIF
                     WordIn = ""
                     if WordCount = MaxWordsIn
                        breakfor
                     endif
         ENDSELECT
   NEXT bz

return
endsub

SUB DoGetEndHandlerZ(STRING LineToWords,opt int MaxWordsIn)
    if !instr(ucase$(LineToWords),"OPENWINDOW") and !instr(ucase$(LineToWords),"CREATEDIALOG") then return
    if !instr(LineToWords,"&") then return
    LineToWords = rtrim$(ltrim$(LineToWords))
    LineLenZ = LEN(LineToWords)
    CheckWordZ1 = 1
    WordIn = ""
    WordCount = 0
    EndWinFound = 0

    FOR bz = instr(LineToWords,"&") + 1 TO LineLenZ

        ThisPos = bz 
        Letter = LineToWords[bz-1]
        DelZ = INSTR(CheckLetter2,Letter)

        SELECT DelZ

               CASE 0 'Add character to our word
                    WordIn = WordIn + Letter

               DEFAULT 'Delimiter found - so we have our word
                     IF LEN(WordIn)> 1 'Key words are at least 2 characrers long
                        StartPos = (ThisPos - LEN(WordIn))-1
                        EndPos   = ThisPos-1
                        WordCount ++
                        #w[1].aWord = WordIn 
                     ENDIF
                     WordIn = ""
                     if WordCount = MaxWordsIn
                        breakfor
                     endif
         ENDSELECT
   NEXT bz

return
endsub

sub HideMain()
return
    DisableMenuItem(w1,201)
    DisableMenuItem(w1,202)
    DisableMenuItem(w1,203)
    DisableMenuItem(w1,204)
    DisableMenuItem(w1,205)
    DisableMenuItem(w1,206)
    DisableMenuItem(w1,402)

    showwindow w1,@SWHIDE,ReloadButton
    showwindow w1,@SWHIDE,FindFirst
    showwindow w1,@SWHIDE,FindAll
    showwindow w1,@SWHIDE,FindLast
    showwindow w1,@SWHIDE,EDIT_1111
    showwindow w1,@SWHIDE,Combo18
    showwindow w1,@SWHIDE,NavDeleteAllButton
    showwindow w1,@SWHIDE,RememberMe
    showwindow w1,@SWHIDE,RememberStatic
    showwindow w1,@SWHIDE,HandyControls
    showwindow w1,@SWHIDE,ConstantsButton
    showwindow w1,@SWHIDE,SubSearchButton
    showwindow w1,@SWHIDE,CoorCheck
    showwindow w1,@SWHIDE,LineNumberStatic
    showwindow w1,@SWHIDE,LineNumberEdit
    showwindow w1,@SWHIDE,WordStatic
    showwindow w1,@SWHIDE,WordNumberEdit
    showwindow w1,@SWHIDE,PosStatic
    showwindow w1,@SWHIDE,PosEdit
    showwindow w1,@SWHIDE,CharPosStatic
    showwindow w1,@SWHIDE,CharPosEdit
    showwindow w1,@SWHIDE,CloseButton
    showwindow w1,@SWHIDE,NewButton
    showwindow w1,@SWHIDE,SaveButton
    showwindow w1,@SWHIDE,OpenButton
    showwindow w1,@SWHIDE,SaveAsButton
    showwindow w1,@SWHIDE,BackupButton
    showwindow w1,@SWHIDE,CogButton
    showwindow w1,@SWHIDE,BinButton
    showwindow w1,@SWHIDE,ColourButton
    showwindow w1,@SWHIDE,AutoButton
    showwindow w1,@SWHIDE,BUTTON_4
    showwindow w1,@SWHIDE,BUTTON_44
    showwindow w1,@SWHIDE,SubJump
    showwindow w1,@SWHIDE,EndSubb
    showwindow w1,@SWHIDE,CopySubButton
    showwindow w1,@SWHIDE,CopySubBlockButton
    showwindow w1,@SWHIDE,DeleteSubButton
    showwindow w1,@SWHIDE,ShowSubButton
    showwindow w1,@SWHIDE,ClearSubs
    showwindow w1,@SWHIDE,WinJump
    showwindow w1,@SWHIDE,EndWin
    showwindow w1,@SWHIDE,WinHandler
    showwindow w1,@SWHIDE,CopyWinButton
    showwindow w1,@SWHIDE,CopyWinBlockButton
    showwindow w1,@SWHIDE,DeleteWinButton
    showwindow w1,@SWHIDE,ShowWindowButton
    showwindow w1,@SWHIDE,ClearWins
    showwindow w1,@SWHIDE,EDIT_11
    showwindow w1,@SWHIDE,EDIT_111
    showwindow w1,@SWHIDE,LineStatic
    showwindow w1,@SWHIDE,WinStatic
    showwindow w1,@SWHIDE,BookStatic
    showwindow w1,@SWHIDE,SubStatic
    showwindow w1,@SWHIDE,Combo2
    showwindow w1,@SWHIDE,Combo4
    showwindow w1,@SWHIDE,Combo6
    showwindow w1,@SWHIDE,STATIC_4
    showwindow w1,@SWHIDE,BlockJumpButton
    showwindow w1,@SWHIDE,Combo1
    showwindow w1,@SWHIDE,IncludeStatic
    showwindow w1,@SWHIDE,Combo88
    showwindow w1,@SWHIDE,BookJump
    showwindow w1,@SWHIDE,BookAdd
    showwindow w1,@SWHIDE,BookDel
    showwindow w1,@SWHIDE,BookDelAll
    showwindow w1,@SWHIDE,ShowBookmarksButton
    showwindow w1,@SWHIDE,NavBackButton
    showwindow w1,@SWHIDE,NavForwardButton
    showwindow w1,@SWHIDE,NavButton
    showwindow w1,@SWHIDE,NavBackGrey
    showwindow w1,@SWHIDE,NavForwardGrey
    showwindow w1,@SWHIDE,NavDeleteButton
    showwindow w1,@SWHIDE,Check1
    showwindow w1,@SWHIDE,KeyFind
    showwindow w1,@SWHIDE,KeyDelete
    showwindow w1,@SWHIDE,CodeWordStatic
    showwindow w1,@SWHIDE,CodeWordEdit1
    showwindow w1,@SWHIDE,CodeWordEdit2
    showwindow w1,@SWHIDE,CodeWordSearch
    showwindow w1,@SWHIDE,CodeWordDelete
    showwindow w1,@SWHIDE,CodePhrase
    showwindow w1,@SWHIDE,CodeWordAnd
    showwindow w1,@SWHIDE,CodeWordOr
    showwindow w1,@SWHIDE,CodePhraseWords
    showwindow w1,@SWHIDE,CodePhraseSearch
    showwindow w1,@SWHIDE,PhraseDeleteButton
    showwindow w1,@SWHIDE,Combo12
    showwindow w1,@SWHIDE,KeyFind
    showwindow w1,@SWHIDE,KeyDelete
    showwindow w1,@SWHIDE,KeyWordStatic
    showwindow w1,@SWHIDE,EDIT_2
    showwindow w1,@SWHIDE,CodePhraseStatic
    showwindow w1,@SWHIDE,CodePhraseEdit
    showwindow w1,@SWHIDE,TopButton
    showwindow w1,@SWHIDE,BottomButton
    showwindow w1,@SWHIDE,Debug1
    showwindow w1,@SWHIDE,Debug2
    showwindow w1,@SWHIDE,Debug3
    showwindow w1,@SWHIDE,DebugCheck

    for a = 1 to 30
	     showwindow w1,@SWHIDE,a + 1000
    next a
return
endsub

sub ShowMain()
return
    EnableMenuItemX(w1,201)
    'EnableMenuItemX(w1,202)

    EnableMenuItem(w1,202,1)

    EnableMenuItemX(w1,203)
    EnableMenuItemX(w1,204)
    EnableMenuItemX(w1,205)
    EnableMenuItemX(w1,206)

    showwindow w1,@SWSHOW,ReloadButton
    showwindow w1,@SWSHOW,FindFirst
    showwindow w1,@SWSHOW,FindAll
    showwindow w1,@SWSHOW,FindLast
    showwindow w1,@SWSHOW,EDIT_1111
    showwindow w1,@SWSHOW,Combo18
    showwindow w1,@SWSHOW,NavDeleteAllButton
    showwindow w1,@SWSHOW,RememberMe
    showwindow w1,@SWSHOW,RememberStatic
    showwindow w1,@SWSHOW,HandyControls
    showwindow w1,@SWSHOW,SubSearchButton
    showwindow w1,@SWSHOW,CoorCheck
    if CoOn
       showwindow w1,@SWSHOW,PosStatic
       showwindow w1,@SWSHOW,PosEdit
       showwindow w1,@SWSHOW,CharPosStatic
       showwindow w1,@SWSHOW,CharPosEdit
    endif
    showwindow w1,@SWSHOW,ConstantsButton
    showwindow w1,@SWSHOW,CloseButton
    showwindow w1,@SWSHOW,NewButton
    showwindow w1,@SWSHOW,SaveButton
    showwindow w1,@SWSHOW,OpenButton
    showwindow w1,@SWSHOW,SaveAsButton
    showwindow w1,@SWSHOW,BackupButton
    showwindow w1,@SWSHOW,CogButton
    showwindow w1,@SWSHOW,BinButton
    showwindow w1,@SWSHOW,ColourButton
    showwindow w1,@SWSHOW,AutoButton
    showwindow w1,@SWSHOW,BUTTON_4
    showwindow w1,@SWSHOW,BUTTON_44
    showwindow w1,@SWSHOW,SubJump
    showwindow w1,@SWSHOW,EndSubb
    showwindow w1,@SWSHOW,CopySubButton
    showwindow w1,@SWSHOW,CopySubBlockButton
    showwindow w1,@SWSHOW,DeleteSubButton
    showwindow w1,@SWSHOW,ShowSubButton
    showwindow w1,@SWSHOW,ClearSubs
    showwindow w1,@SWSHOW,WinJump
    showwindow w1,@SWSHOW,EndWin
    showwindow w1,@SWSHOW,WinHandler
    showwindow w1,@SWSHOW,CopyWinButton
    showwindow w1,@SWSHOW,CopyWinBlockButton
    showwindow w1,@SWSHOW,DeleteWinButton
    showwindow w1,@SWSHOW,ShowWindowButton
    showwindow w1,@SWSHOW,ClearWins
    showwindow w1,@SWSHOW,EDIT_11
    showwindow w1,@SWSHOW,EDIT_111
    showwindow w1,@SWSHOW,LineStatic
    showwindow w1,@SWSHOW,WinStatic
    showwindow w1,@SWSHOW,BookStatic
    showwindow w1,@SWSHOW,SubStatic
    showwindow w1,@SWSHOW,Combo2
    showwindow w1,@SWSHOW,Combo4
    showwindow w1,@SWSHOW,Combo6
    showwindow w1,@SWSHOW,2005 'Combo88
    showwindow w1,@SWSHOW,STATIC_4
    showwindow w1,@SWSHOW,BlockJumpButton
    showwindow w1,@SWSHOW,Combo1
    showwindow w1,@SWSHOW,IncludeStatic
    showwindow w1,@SWSHOW,Combo88
    showwindow w1,@SWSHOW,BookJump
    showwindow w1,@SWSHOW,BookAdd
    showwindow w1,@SWSHOW,BookDel
    showwindow w1,@SWSHOW,BookDelAll
    showwindow w1,@SWSHOW,ShowBookmarksButton

    showwindow w1,@SWSHOW,NavButton
    showwindow w1,@SWSHOW,NavDeleteButton

    if NavMax = 0
		 showwindow w1,@SWSHOW,NavBackGrey
		 showwindow w1,@SWSHOW,NavForwardGrey
	 endif

	 if NavMax > 1
		 showwindow w1,@SWSHOW,NavBackButton
		 showwindow w1,@SWSHOW,NavForwardButton
		 showwindow w1,@SWHIDE,NavBackGrey
		 showwindow w1,@SWHIDE,NavForwardGrey
	 endif
	 if NavMax = 1 
		 showwindow w1,@SWSHOW,NavBackButton
		 showwindow w1,@SWHIDE,NavBackGrey
		 showwindow w1,@SWSHOW,NavForwardGrey
		 return 0
	 endif

    showwindow w1,@SWSHOW,Check1
    showwindow w1,@SWSHOW,KeyFind
    showwindow w1,@SWSHOW,KeyDelete
    if CodePhraseV = 1
       showwindow w1,@SWHIDE,CodeWordAnd
       showwindow w1,@SWHIDE,CodeWordOr
    else
       showwindow w1,@SWSHOW,CodeWordAnd
       showwindow w1,@SWSHOW,CodeWordOr
    endif
    showwindow w1,@SWSHOW,CodePhrase
    showwindow w1,@SWSHOW,CodePhraseWords
    showwindow w1,@SWSHOW,CodePhraseSearch
    showwindow w1,@SWSHOW,PhraseDeleteButton
    showwindow w1,@SWSHOW,Combo12
    showwindow w1,@SWSHOW,KeyFind
    showwindow w1,@SWSHOW,KeyDelete
    showwindow w1,@SWSHOW,KeyWordStatic
    showwindow w1,@SWSHOW,EDIT_2
    showwindow w1,@SWSHOW,CodePhraseStatic
    showwindow w1,@SWSHOW,CodePhraseEdit
    showwindow w1,@SWSHOW,TopButton
    showwindow w1,@SWSHOW,BottomButton
	 if DebugOn = 1
		 showwindow w1,@SWSHOW,Debug1
		 showwindow w1,@SWSHOW,Debug2
		 showwindow w1,@SWSHOW,Debug3
	 endif 
	 if DebugOn = 0
		 showwindow w1,@SWHIDE,Debug1
		 showwindow w1,@SWHIDE,Debug2
		 showwindow w1,@SWHIDE,Debug3
	 endif 
    showwindow w1,@SWSHOW,DebugCheck

    for a = 1 to 30
	     showwindow w1,@SWSHOW,a + 1000
    next a

return
endsub

SUB DisableMenuItem(win as WINDOW,id as INT)
	UINT hTopMenu
	MENUITEMINFO info
   hTopMenu = GetMenu(win.hwnd)
   IF hTopMenu <> NULL /*window has a menu*/
      RtlZeroMemory(info,LEN(MENUITEMINFO))
      info.cbSize = LEN(MENUITEMINFO)
      info.fMask = MIIM_STATE
      info.fState = MFS_DISABLED
      SetMenuItemInfo(hTopMenu,id,FALSE,info)
   ENDIF
return
endsub

SUB EnableMenuItemX(win as WINDOW,id as INT)
	UINT hTopMenu
	MENUITEMINFO info
   hTopMenu = GetMenu(win.hwnd)
   IF hTopMenu <> NULL /*window has a menu*/
      RtlZeroMemory(info,LEN(MENUITEMINFO))
      info.cbSize = LEN(MENUITEMINFO)
      info.fMask = MIIM_STATE
      info.fState = MFS_ENABLED
      SetMenuItemInfo(hTopMenu,id,FALSE,info)
   ENDIF
return
endsub

sub Debug()
	 CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line2$,512)
	 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
	 MonitorBrackets(rHandle,cLine-1,Line2$,Offset)
    string BracketW1,BracketW2
    BracketW1 = " ( Brackets"
    BracketW2 = " ) Brackets"
    if OpenRound  = 1 then BracketW1 = " ( Bracket" 
    if CloseRound = 1 then BracketW2 = " ) Bracket"
	 setcontroltext(w1,Debug2," " + ltrim$(str$(OpenRound)) + BracketW1 + chr$(9) + ltrim$(str$(CloseRound)) + BracketW2) 
    if OpenRound <> CloseRound
       SETCONTROLCOLOR w1,Debug2,Red,WindowBackColour
    else
       SETCONTROLCOLOR w1,Debug2,RGB(0,0,0),WindowBackColour
    endif
    BracketW1 = " [ Brackets"
    BracketW2 = " ] Brackets"
    if OpenSquare  = 1 then BracketW1 = " [ Bracket" 
    if CloseSquare = 1 then BracketW2 = " ] Bracket"
	 setcontroltext(w1,Debug3," " + ltrim$(str$(OpenSquare)) + BracketW1 + chr$(9) + ltrim$(str$(CloseSquare)) + BracketW2) 
    if OpenSquare <> CloseSquare
       SETCONTROLCOLOR w1,Debug3,Red,WindowBackColour
    else
       SETCONTROLCOLOR w1,Debug3,RGB(0,0,0),WindowBackColour
    endif
return
endsub

sub SaveAndCloseIt()
	 if DelConfirm = 1
		 if len(ProgPath) > 0
			 if openfile(file1,ProgPath,"W") = 0
				 Modified = 0
				 for a = 0 to CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT) - 1
					  CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512)
					  if instr(line$,chr$(13)) 'Line has CHR$(13) + CHR$(10) 
						  write file1,mid$(line$,1,instr(line$,chr$(13))-1)
						  goto NextLine
					  endif
					  if instr(line$,chr$(10)) 'Line has CHR$(13)
						  write file1,mid$(line$,1,instr(line$,chr$(10))-1)
						  goto NextLine
					  endif
					  if !instr(line$,chr$(13)) and !instr(line$,chr$(10)) 'Line does not have CHR$(13) or CHR$(10)
						  write file1,line$
					  endif 
				 label NextLine
				 next a
			 endif
			 closefile file1
		 endif
	 endif
return
endsub

sub BlockCommentCheck()
return
CommentBlockStart = 0

		 for a = FirstVisLine -2 to FirstVisLine + LinesPerPage
           CONTROLCMD(w1,RichEdit,@RTGETLINE,a,#cp.ClipText,512)

           if instr(#cp.ClipText,"/*")
              CommentBlockStart = 1
           endif

			  'if len(ltrim$(#cp.Cliptext)) < 3 then goto CheckNextLine
			  Offset = SendMessage(rHandle,EM_LINEINDEX,a,0)

			  SENDMESSAGE(rHandle,EM_SETSEL,Offset,len(line$) + Offset)
			  cf.dwMask = CFM_COLOR
			  cf.crTextColor = Green
			  cf.cbSize = SIZEOF(cf)
			  SENDMESSAGE(rHandle,EM_SETCHARFORMAT,SCF_SELECTION,&cf)

           if instr(#cp.ClipText,"*/")
              CommentBlockStart = 0
              breakfor 
           endif

		 'label CheckNextLine
		 next a
/*
		 for a = CommentBlockStart-1 to CommentBlockEnd
			  CONTROLCMD(w1,1,@RTGETLINE,a,line$,512)
			  if !len(ltrim$(line$)) then goto CheckNextLineG
			  Offset = SendMessage(rHandle,EM_LINEINDEX,a,0)
			  SENDMESSAGE(rHandle,EM_SETSEL,Offset,len(line$) + Offset)
			  cf.dwMask = CFM_COLOR
			  cf.crTextColor = Green
			  cf.cbSize = SIZEOF(cf)
			  SENDMESSAGE(rHandle,EM_SETCHARFORMAT,SCF_SELECTION,&cf)
		 label CheckNextLineG
		 next a
*/
return
endsub

sub WindowSubs()

	 if getstate(w1,RememberMe) = 1
		 DoAddNavigationPage(1)
	 endif

    OPENWINDOW w11,0,0,430,470,@MINBOX|@MAXBOX|@TOPMOST|@CAPTION,0,"Search local subroutines",&SubSearchHandler
    Setwindowcolor w11,BackColour

    CONTROL w11,@EDIT,"",10,10,400,25,@CTEDITAUTOH||ES_SUNKEN,EDIT_1
            CONTROLCMD w1,EDIT_1,@EDSETLIMITTEXT,255
            SETFONT w11,"Arial",12,400,0,EDIT_1

    CONTROL w11,@CHECKBOX,"Begins with",10,45,100,25,@CTEDITLEFT,BeginsWith
            SETCONTROLCOLOR w11,BeginsWith,RGB(0,0,0),BackColour
            SETFONT w11,"Arial",11,400,0,BeginsWith
            setstate w11,BeginsWith,1

    CONTROL w11,@CHECKBOX,"In subroutine name",120,45,180,25,@CTEDITLEFT,InSubName
            SETCONTROLCOLOR w11,InSubName,RGB(0,0,0),BackColour
            SETFONT w11,"Arial",11,400,0,InSubName

   CONTROL w11,@CHECKBOX,"Close window on selection",10,410,300,25,@CTEDITLEFT,SearchCheck
           SETCONTROLCOLOR w11,SearchCheck,RGB(0,0,0),BackColour
           SETFONT w11,"Arial",12,400,0,SearchCheck
           if SearchCheckV = 1 then setstate w11,SearchCheck,1

    CONTROL w11,@BUTTON,"Close",350,410,60,25,@CTEDITCENTER,CloseButton 
            SETFONT w11,"Arial",12,400,0,CloseButton

    CONTROL w11,@LISTVIEW,"",10,80,400,320,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			   SENDMESSAGE w11,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			   CONTROLCMD w11,ListViewResult,@LVINSERTCOLUMN,0,"Subroutine name"
			   CONTROLCMD w11,ListViewResult,@LVSETCOLWIDTH,0,400
            SendMessage w11,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
            SendMessage w11,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
            SETFONT w11,"Arial",12,400,0,ListViewResult

    setfocus w11,EDIT_1
    WAITUNTIL IsWindowClosed(w11)

return 
endsub

SUB SubSearchHandler(),INT
    string text2,text4
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w11

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w11

           CASE @IDCONTROL
                SELECT @CONTROLID
							  case ListViewResult
									 if @NOTIFYCODE=@NMCLICK 
										 label ClickListViewResult
										 lvpos=*<NMLISTVIEW>@LPARAM.iItem
										 CONTROLCMD(w11,ListViewResult,@LVGETTEXT,lvpos,0,text4)
                               int Match = 0
										 int lvcountIn = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
										 for a = 0 to lvcountIn - 1
											  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text)
											  if text4 = text
												  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text2)
                                      Match = 1
												  breakfor
											  endif
										 next a
                               if Match = 1
										    setcontroltext(w1,EDIT_1,text2)
                                  if SearchCheckV = 1
                                     closewindow w11
                                     return 0
                                  endif
                               endif
									 endif

							  case CloseButton
									 if @NOTIFYCODE = 0
                               closewindow w11
                            endif

							  case BeginsWith
									 if @NOTIFYCODE = 0
                               if getstate(w11,BeginsWith) = 1 then setstate(w11,InSubName,0)
                               if getstate(w11,BeginsWith) = 0 then setstate(w11,InSubName,1)
                               CONTROLCMD(w11,ListViewResult,@LVDELETEALL)
                               setcontroltext(w11,EDIT_1,getcontroltext(w11,EDIT_1))
                               setfocus w11,EDIT_1
                               AppendEdit(w11,EDIT_1,"",0)
                            endif

							  case InSubName
									 if @NOTIFYCODE = 0
                               if getstate(w11,InSubName) = 1 then setstate(w11,BeginsWith,0)
                               if getstate(w11,InSubName) = 0 then setstate(w11,BeginsWith,1)
                               CONTROLCMD(w11,ListViewResult,@LVDELETEALL)
                               setcontroltext(w11,EDIT_1,getcontroltext(w11,EDIT_1))
                               setfocus w11,EDIT_1
                               AppendEdit(w11,EDIT_1,"",0) 
                            endif

							  case SearchCheck
									 if @NOTIFYCODE = 0
                               SearchCheckV = 1 - SearchCheckV 
                               setfocus w11,EDIT_1 
                            endif

                       case EDIT_1
                            if @NOTIFYCODE = @ENCHANGE
                               CONTROLCMD(w11,ListViewResult,@LVDELETEALL)
										 lvcountIn = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
										 for a = 0 to lvcountIn - 1
											  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text)
                                   if getstate(w11,InSubName)
												  if instr(ucase$(text),ucase$(getcontroltext(w11,EDIT_1)))
													  CONTROLCMD w11,ListViewResult,@LVINSERTITEM,a,text
												  endif
                                   endif
                                   if getstate(w11,BeginsWith)
                                      int InLine = len(getcontroltext(w11,EDIT_1))
												  if ucase$(mid$(text,1,InLine)) = ucase$(getcontroltext(w11,EDIT_1))
													  CONTROLCMD w11,ListViewResult,@LVINSERTITEM,a,text
												  endif
                                   endif
										 next a
                            endif 
                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

sub WindowCase(opt string ControlNameIn)

    'Add where you currently are to navigation list
    if getstate(w1,RememberMe) = 1
       DoAddNavigationPage(1) 'With no confirmation screen
    endif

    OPENWINDOW w16,0,0,746,500,@TOPMOST|@CAPTION,0,"Search controls",&CaseSearchHandler
    Setwindowcolor w16,BackColour
    hIcon = LOADIMAGE(getstartpath + "\\Res\\search.ico",@IMGICON)
    SETICON w16,hIcon
    SETICON w1,0
 
    CONTROL w16,@STATIC,"Control name",10,10,100,25,@CTEDITLEFT|0x200,ControlName
            SETCONTROLCOLOR w16,ControlName,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",12,400,0,ControlName

    CONTROL w16,@EDIT,"",10,40,300,25,@CTEDITAUTOH||ES_SUNKEN,EDIT_1
            CONTROLCMD w16,EDIT_1,@EDSETLIMITTEXT,255
            SETFONT w16,"Arial",12,400,0,EDIT_1

    CONTROL w16,@CHECKBOX,"Begins with",12,75,100,25,@CTEDITLEFT,BeginsWith
            SETCONTROLCOLOR w16,BeginsWith,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",12,400,0,BeginsWith
            setstate w16,BeginsWith,1

    CONTROL w16,@CHECKBOX,"In control name",130,75,130,25,@CTEDITLEFT,InSubName
            SETCONTROLCOLOR w16,InSubName,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",12,400,0,InSubName

    CONTROL w16,@CHECKBOX,"Go to control",10,105,110,25,@CTEDITLEFT,GoControl
            SETCONTROLCOLOR w16,GoControl,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",12,400,0,GoControl
            setstate(w16,GoControl,1)

    CONTROL w16,@CHECKBOX,"Go to case",130,105,100,25,@CTEDITLEFT,GoCase
            SETCONTROLCOLOR w16,GoCase,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",12,400,0,GoCase

    CONTROL w16,@STATIC,"",0,127,746,20,@CTEDITCENTER,SearchStatic
            SETCONTROLCOLOR w16,SearchStatic,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",12,400,0,SearchStatic

    CONTROL w16,@CHECKBOX,"Exclude statics",270,75,150,25,@CTEDITLEFT,ExcludeStatics
            SETCONTROLCOLOR w16,ExcludeStatics,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",12,400,0,ExcludeStatics
            setstate(w16,ExcludeStatics,1)

   CONTROL w16,@CHECKBOX,"Close window on selection",270,105,300,25,@CTEDITLEFT,SearchCheck
           SETCONTROLCOLOR w16,SearchCheck,RGB(0,0,0),BackColour
           SETFONT w16,"Arial",12,400,0,SearchCheck
           setstate w16,SearchCheck,0

    CONTROL w16,@LISTVIEW,"",10,150,720,280,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL||LVS_SORTASCENDING,ListViewResult
			   SENDMESSAGE w16,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			   CONTROLCMD w16,ListViewResult,@LVINSERTCOLUMN,0,"Control name"
			   CONTROLCMD w16,ListViewResult,@LVSETCOLWIDTH,0,250
			   CONTROLCMD w16,ListViewResult,@LVINSERTCOLUMN,1,"Window"
			   CONTROLCMD w16,ListViewResult,@LVSETCOLWIDTH,1,200
			   CONTROLCMD w16,ListViewResult,@LVINSERTCOLUMN,2,"Line"
			   CONTROLCMD w16,ListViewResult,@LVSETCOLWIDTH,2,100
			   CONTROLCMD w16,ListViewResult,@LVINSERTCOLUMN,3,"Type"
			   CONTROLCMD w16,ListViewResult,@LVSETCOLWIDTH,3,170
            SendMessage w16,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
            SendMessage w16,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
            SETFONT w16,"Arial",12,400,0,ListViewResult

    CONTROL w16,@STATIC,"Filter by window && type",512,12,170,16,@CTEDITLEFT|0x200,FilterBy
            SETCONTROLCOLOR w16,FilterBy,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",12,400,0,FilterBy

    'Control types
    CONTROL w16,@STATIC,"Types",435,70,70,25,@CTEDITRIGHT|0x200,TypeStatic
            SETCONTROLCOLOR w16,TypeStatic,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",11,400,0,TypeStatic

    CONTROL w16,@COMBOBOX,"",510,70,222,505,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo6
				addstring w16,Combo6,"ALL"
				addstring w16,Combo6,"BUTTON"
				addstring w16,Combo6,"CHECKBOX"
				addstring w16,Combo6,"RADIOBUTTON"
				addstring w16,Combo6,"EDIT"
				addstring w16,Combo6,"LISTBOX"
				addstring w16,Combo6,"COMBOBOX"
				addstring w16,Combo6,"STATIC"
				addstring w16,Combo6,"SCROLLBAR"
				addstring w16,Combo6,"GROUPBOX"
				addstring w16,Combo6,"RICHEDIT"
				addstring w16,Combo6,"LISTVIEW"
				addstring w16,Combo6,"STATUS"
				addstring w16,Combo6,"SYSBUTTON"
				addstring w16,Combo6,"RGNBUTTON"
				addstring w16,Combo6,"TREEVIEW"
            SETFONT w16,"Arial",12,400,0,Combo6
            setselected(w16,Combo6,0)

    'Windows
    CONTROL w16,@STATIC,"Windows",435,40,70,25,@CTEDITRIGHT|0x200,WindowStatic
            SETCONTROLCOLOR w16,WindowStatic,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",11,400,0,WindowStatic

    CONTROL w16,@COMBOBOX,"",510,40,222,505,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo4
		      SETFONT w16,"Arial",12,400,0,Combo4

	 	      addstring w16,Combo4,"ALL"
			   for a = 0 to getstringcount(w1,Combo4) - 1
				    string WinString = getstring(w1,Combo4,a)
	 	          addstring w16,Combo4,WinString
            label NextWinName
			   next a
            setselected(w16,Combo4,0)
            FilterList = getstring(w16,Combo4,getselected(w16,Combo4))

    'Total
    CONTROL w16,@STATIC,"",510,105,210,25,@CTEDITLEFT|0x200,TotalStatic
            SETCONTROLCOLOR w16,TotalStatic,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",12,400,0,TotalStatic

    CONTROL w16,@BUTTON,"Hide this screen for now",10,440,200,25,@CTEDITCENTER,KeepHandy 
            SETFONT w16,"Arial",12,400,0,KeepHandy

    CONTROL w16,@CHECKBOX,"Save the control location when I go to it in my places",220,440,400,25,@CTEDITLEFT,AddNavCheck
            SETCONTROLCOLOR w16,AddNavCheck,RGB(0,0,0),BackColour
            SETFONT w16,"Arial",12,400,0,AddNavCheck

    CONTROL w16,@BUTTON,"Close",650,440,80,25,@CTEDITCENTER,CloseButton 
            SETFONT w16,"Arial",12,400,0,CloseButton

    setfocus w16,EDIT_1

    if ControlNameIn <> ""
       setselected(w16,Combo4,0) 
       setselected(w16,Combo6,0) 
    endif
    setcontroltext(w16,EDIT_1,ControlNameIn)

    WAITUNTIL IsWindowClosed(w16)

return 
endsub

SUB CaseSearchHandler(),INT
    string text2,text4
	 SELECT @MESSAGE
           CASE @IDCREATE
                'Centre window and move down a little
                'so you can see in the rich edit what the search case screen has found easier. 
                CENTERWINDOW w16
					 int wl,wt,ww,wh
					 GETSIZE w16,wl,wt,ww,wh
					 SETSIZE w16,wl,wt+100,ww,wh

           CASE @IDCLOSEWINDOW
                if hIcon then deleteimage hIcon,@IMGICON
                CLOSEWINDOW w16

           CASE @IDCONTROL
                SELECT @CONTROLID
                       case KeepHandy
                            if @NOTIFYCODE = 0
                               showwindow w16,@SWHIDE
                            endif 

							  case  Combo4
							  case& Combo6
									 if @NOTIFYCODE = @CBNSELCHANGE
                               if getstate(w16,ExcludeStatics) = 1
                                  CaseSelection(1)
                               else
                                  CaseSelection()
                               endif
										 if getstring(w16,Combo4,(getselected(w16,Combo4))) = "ALL"
											 setcontroltext(w16,WindowStatic,"Windows")
										 else
											 setcontroltext(w16,WindowStatic,"Window")
										 endif
										 if getstring(w16,Combo6,(getselected(w16,Combo6))) = "ALL"
											 setcontroltext(w16,TypeStatic,"Types")
										 else
											 setcontroltext(w16,TypeStatic,"Type")
										 endif
                               setfocus w16,EDIT_1  
                               AppendEdit(w16,EDIT_1,"",0)  
                            endif

							  case EDIT_1
									 if @NOTIFYCODE = @ENCHANGE
                               if getstate(w16,ExcludeStatics) = 1
                                  CaseSelection(1)
                               else
                                  CaseSelection()
                               endif
                            endif

							  case ExcludeStatics
									 if @NOTIFYCODE = 0
                               if getstate(w16,ExcludeStatics) = 1
                                  CaseSelection(1)
                               else
                                  CaseSelection()
                               endif
                               setfocus w16,EDIT_1  
                               AppendEdit(w16,EDIT_1,"",0) 
                            endif

							  case ListViewResult
									 if @NOTIFYCODE=@NMCLICK and getstate(w16,GoControl) = 1
										 lvpos=*<NMLISTVIEW>@LPARAM.iItem
										 label ClickListGoControl
										 CONTROLCMD(w16,ListViewResult,@LVGETTEXT,lvpos,2,text4) 'The line number where control was created

                               'Control line number is in human form (one based) so no ajdustment needed
                               'EDIT_1 on change scrolls the rich edit control to a specific line  
										 setcontroltext(w1,EDIT_1,text4)
                               setfocus w16
                               if getstate(w16,AddNavCheck) = 1
                                  DoAddNavigationPage(1)
                               endif
										 if getstate(w16,SearchCheck)
                                  if iswindowclosed(w16) = 0
											    closewindow w16
                                  endif
											 return 0
										 endif
									 endif

									 if @NOTIFYCODE = @NMCLICK and getstate(w16,GoCase) = 1
                               'Get the control name we want to search for
										 lvpos=*<NMLISTVIEW>@LPARAM.iItem

										 label ClickListGoCase
                               FromLine = -1
                               int CaseFound = 0
                               int HandlerFound = 0

										 CONTROLCMD(w16,ListViewResult,@LVGETTEXT,lvpos,0,text)  'Control name
										 CONTROLCMD(w16,ListViewResult,@LVGETTEXT,lvpos,1,text2) 'Window it belongs to
										 string ControlNameSaved  = ucase$(text) 'This is the control name
										 string ControlNameSavedN = text 'This is the control name
										 int lvcountIn = CONTROLCMD(w1,ListView4,@LVGETCOUNT)

                               'Find handler name of the window
										 for a = 0 to lvcountIn - 1
                                   string text3
											  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text)  'Window name
											  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text3) 'Handler name
											  int LookAt = val(text3) -1
											  CONTROLCMD(w1,RichEdit,@RTGETLINE,LookAt,#cp.ClipText,512)
                                   if len(#cp.ClipText) < 3 then goto NextHandler
											  GetCaseStatement(#cp.Cliptext)
											  string TheHandler = #w[WordCount].aWord 'We have found the handler
											  if ucase$(text2) = ucase$(text) 
                                      HandlerFound = 1 
                                      breakfor
                                   endif
                               label NextHandler
										 next a

                               if HandlerFound = 0 then return 0 'Handler not found                              

                               'Find the first line of the handler subroutine
										 lvcountIn = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
										 for a = 0 to lvcountIn - 1
											  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text)  'Subroutine name
											  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text3) 'Subroutine start line
											  if ucase$(text) = ucase$(TheHandler) 'We have the subroutine start line number we want 
												  FromLine = val(text3) - 1
												  breakfor
											  endif 
										 next a

                               if FromLine = -1 then return 0 'First line of subroutine not found

										 int CodeEnd = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
										 for a = FromLine to CodeEnd
											  CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512) 
											  DoGetEndSubZ(a+1,Line$,1)
											  if EndSubFound = 1
												  breakfor
											  endif
										 next a
										 if EndSubFound = 1
											 EndSubFound = 0
											 int EndSubLine  = a
                               else
                                  return 0 'Last line of subroutine not found
										 endif

                               'Search subroutine for the specific CASE statement
										 SETCONTROLCOLOR w16,SearchStatic,RGB(0,0,0),BackColour
										 setcontroltext(w16,SearchStatic,"")
										 for a = FromLine to EndsubLine
											  CONTROLCMD(w1,RichEdit,@RTGETLINE,a,#cp.ClipText,512)
                                   if len(#cp.ClipText) < 3 then goto NextFromLine
                                   if !instr(ucase$(#cp.ClipText),"CASE") then goto NextFromLine
											  GetCaseStatement(#cp.Cliptext,1)
											  if ucase$(#w[1].aWord) = "CASE" and ucase$(#w[2].aWord) = ControlNameSaved
                                      CaseFound = 1 
                                      breakfor
											  endif
                               label NextFromLine 
										 next a
										 if CaseFound
										    setcontroltext(w16,SearchStatic,"")
										 else
										    SETCONTROLCOLOR w16,SearchStatic,Red,BackColour
										    setcontroltext(w16,SearchStatic,"No case statement for " + ControlNameSavedN)
										 endif
                               
                               'All is well, scroll to the CASE statement line
                               if CaseFound = 1
                                  'Add 1 to the line number for us humans (Rich edit control are zero based) 
											 a++ 
                                  'EDIT_1 on change scrolls the rich edit control to a specific line
											 setcontroltext(w1,EDIT_1,ltrim$(str$(a))) 
                                  setfocus w16
											 if getstate(w16,AddNavCheck) = 1
												 DoAddNavigationPage(1)
											 endif
                               endif

                            endif

							  case CloseButton
									 if @NOTIFYCODE = 0
                               closewindow w16
                            endif

							  case GoCase
									 if @NOTIFYCODE = 0
                               if getstate(w16,GoCase) = 0 
                                  setstate(w16,GoControl,1)
                                  setfocus w16
                                  return 0
                               endif
                               if getstate(w16,GoCase) = 1 then setstate(w16,GoControl,0)
										 if getselected(w16,Combo4) = -1
											 setselected(w16,Combo4,0)
										 endif
										 setfocus w16,EDIT_1
										 AppendEdit(w16,EDIT_1,"",0)
										 int lvcountInR = CONTROLCMD(w16,ListViewResult,@LVGETCOUNT)
										 if lvcountInR = 1
											 lvpos = 0
											 goto ClickListGoCase 
										 endif
                            endif

							  case GoControl
									 if @NOTIFYCODE = 0
                               if getstate(w16,GoControl) = 0 
                                  setstate(w16,GoCase,1)
                                  setfocus w16
                                  return 0
                               endif
                               if getstate(w16,GoControl) = 1 then setstate(w16,GoCase,0)
                                  if getselected(w16,Combo4) = -1
                                     setselected(w16,Combo4,0)
                                  endif
                                  setfocus w16,EDIT_1
                                  AppendEdit(w16,EDIT_1,"",0)
                                  lvcountInR = CONTROLCMD(w16,ListViewResult,@LVGETCOUNT)
                                  if lvcountInR = 1
                                     lvpos = 0
                                     goto ClickListGoControl 
                                  endif
                            endif

							  case BeginsWith
									 if @NOTIFYCODE = 0
                               if getstate(w16,BeginsWith) = 1 then setstate(w16,InSubName,0)
                               if getstate(w16,BeginsWith) = 0 then setstate(w16,InSubName,1)
                                  if getselected(w16,Combo4) = -1
                                     setselected(w16,Combo4,0)
                                  endif
                               CONTROLCMD(w16,ListViewResult,@LVDELETEALL)
                               setcontroltext(w16,EDIT_1,getcontroltext(w16,EDIT_1))
                               setfocus w16,EDIT_1
                               AppendEdit(w16,EDIT_1,"",0)
                            endif

							  case InSubName
									 if @NOTIFYCODE = 0
                               if getstate(w16,InSubName) = 1 then setstate(w16,BeginsWith,0)
                               if getstate(w16,InSubName) = 0 then setstate(w16,BeginsWith,1)
                                  if getselected(w16,Combo4) = -1
                                     setselected(w16,Combo4,0)
                                  endif
                               CONTROLCMD(w16,ListViewResult,@LVDELETEALL)
                               setcontroltext(w16,EDIT_1,getcontroltext(w16,EDIT_1))
                               setfocus w16,EDIT_1
                               AppendEdit(w16,EDIT_1,"",0) 
                            endif

							  case AddNavCheck
									 if @NOTIFYCODE = 0
                               setfocus w16 
                            endif

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

sub DisplayTab(int Switch)

    AddToNavStore()
    AddToBookStore()

    int FindScreen  = 0
    int ReOpenCases = 0
     
    if iswindowclosed(w16) = 0
       closewindow w16
       ReOpenCases = 1
    endif

    if iswindowclosed(w6) = 0 
       Closewindow w6
       FindScreen = 1
    endif
                   
	 Scrolling = 1 
    SubDisplayed[OnTab] = getselected(w1,Combo2)
    WinDisplayed[OnTab] = getselected(w1,Combo4)

	 showwindow w1,@SWHIDE,NavBackButton
	 showwindow w1,@SWHIDE,NavForwardButton
	 showwindow w1,@SWSHOW,NavBackGrey
	 showwindow w1,@SWSHOW,NavForwardGrey

    int StoreNav1Count = NavStoreCount[1]
    int StoreNav2Count = NavStoreCount[2]

	 LoadTab(Switch)

    int bx = 0
    int ResetCount = 0
    SendMessage(GetDlgItem(w1.hwnd,Combo18),CB_RESETCONTENT,0,0)
 
    select OnTab
           case 1
                if StoreNav1Count < NavStoreCount[1] 
                   NavStoreCount[1] = NavMax
                endif 
					 for bx = 1 to NavStoreCount[1]
                    if NavStore1[bx] <> ""
                       ResetCount ++
                       insertstring(w1,Combo18,ResetCount-1,NavStore1[bx])
                    endif  
					 next bx
                NavStoreCount[1] = ResetCount
                NavPos = ResetCount
                NavMax = ResetCount

           case 2
                if StoreNav2Count < NavStoreCount[2] 
                   NavStoreCount[2] = NavMax
                endif 
					 for bx = 1 to NavStoreCount[2]
                    if NavStore2[bx] <> ""
                       ResetCount ++
                       insertstring(w1,Combo18,ResetCount-1,NavStore2[bx])
                    endif  
					 next bx
                NavStoreCount[2] = ResetCount
                NavPos = ResetCount
                NavMax = ResetCount

           case 3
					 for a = 1 to NavStoreCount[1]
                    if NavStore3[a] <> ""
                       ResetCount ++
                       addstring(w1,Combo18,NavStore3[a])
                    endif  
					 next a
                NavStoreCount[3] = ResetCount
                NavPos = ResetCount
                NavMax = ResetCount

           case 4
					 for a = 1 to NavStoreCount[1]
                    if NavStore4[a] <> ""
                       ResetCount ++
                       addstring(w1,Combo18,NavStore4[a])
                    endif  
					 next a
                NavStoreCount[4] = ResetCount
                NavPos = ResetCount
                NavMax = ResetCount

           case 5
					 for a = 1 to NavStoreCount[1]
                    if NavStore5[a] <> ""
                       ResetCount ++
                       addstring(w1,Combo18,NavStore5[a])
                    endif  
					 next a
                NavStoreCount[5] = ResetCount
                NavPos = ResetCount
                NavMax = ResetCount

           case 6
					 for a = 1 to NavStoreCount[1]
                    if NavStore6[a] <> ""
                       ResetCount ++
                       addstring(w1,Combo18,NavStore6[a])
                    endif  
					 next a
                NavStoreCount[6] = ResetCount
                NavPos = ResetCount
                NavMax = ResetCount

   endselect 
   label SkipAddingNav

   ResetCount = 0
   CONTROLCMD(w1,ListView6,@LVDELETEALL)
   SendMessage(GetDlgItem(w1.hwnd,Combo6),CB_RESETCONTENT,0,0)
    
   select OnTab
          case 1
				   for a = 1 to BookStoreCount[1]
                   if BookStore1[a] <> ""
                      ResetCount ++
                      insertstring(w1,Combo6,ResetCount-1,BookStore1[a])
                      AddToBookmarksList(BookStore1[a],ResetCount) 
                   endif  
					next a
               BookStoreCount[1] = ResetCount

          case 2
					for a = 1 to BookStoreCount[2]
                   if BookStore2[a] <> ""
                      ResetCount ++
                      insertstring(w1,Combo6,ResetCount-1,BookStore2[a])
                      AddToBookmarksList(BookStore2[a],ResetCount)
                   endif  
					next a
               BookStoreCount[2] = ResetCount

          case 3
					for a = 1 to BookStoreCount[3]
                   if BookStore3[a] <> ""
                      ResetCount ++
                      insertstring(w1,Combo6,ResetCount-1,BookStore3[a])
                      AddToBookmarksList(BookStore3[a],ResetCount)
                   endif  
					next a
               BookStoreCount[3] = ResetCount

          case 4
					for a = 1 to BookStoreCount[4]
                   if BookStore4[a] <> ""
                      ResetCount ++
                      insertstring(w1,Combo6,ResetCount-1,BookStore4[a])
                      AddToBookmarksList(BookStore4[a],ResetCount)
                   endif  
					next a
               BookStoreCount[4] = ResetCount

          case 5
					for a = 1 to BookStoreCount[5]
                   if BookStore5[a] <> ""
                      ResetCount ++
                      insertstring(w1,Combo6,ResetCount-1,BookStore5[a])
                      AddToBookmarksList(BookStore5[a],ResetCount)
                   endif  
					next a
               BookStoreCount[5] = ResetCount

          case 6
					for a = 1 to BookStoreCount[6]
                   if BookStore6[a] <> ""
                      ResetCount ++
                      insertstring(w1,Combo6,ResetCount-1,BookStore6[a])
                      AddToBookmarksList(BookStore6[a],ResetCount)
                   endif  
					next a
               BookStoreCount[6] = ResetCount

   endselect 

   if getstringcount(w1,Combo18) > 0
      showwindow w1,@SWSHOW,NavBackButton
      showwindow w1,@SWHIDE,NavBackGrey
   endif
   if getstringcount(w1,Combo18) > 1
      showwindow w1,@SWSHOW,NavForwardButton
      showwindow w1,@SWHIDE,NavForwardGrey
   endif

	DoRebuild()

   if SubDisplayed[OnTab] > -1
      setselected(w1,Combo2,SubDisplayed[OnTab])
   endif
   if WinDisplayed[OnTab] > -1
      setselected(w1,Combo4,WinDisplayed[OnTab])
   endif
	Scrolling = 0
	Loading = 0
   SendMessage(rHandle,EM_SETTABSTOPS,1,&Tabss)

   if getstringcount(w1,Combo18) > 0
      showwindow w1,@SWSHOW,NavBackButton
      showwindow w1,@SWHIDE,NavBackGrey
   endif

   if getstringcount(w1,Combo18) > 1
      showwindow w1,@SWSHOW,NavForwardButton
      showwindow w1,@SWHIDE,NavForwardGrey
   endif

   if ReOpenCases = 1
      WindowCase()
   endif

   if FindScreen = 1
      WindowSearchPhrase()
   endif

   showwindow w1,@SWHIDE,ListView

return
endsub

sub InitialLoadDisplay()
	 ppos = GETCARETPOSITION w1,AcrossX,DownY
	 AcrossX --
	 AcrossX = AcrossX / 8
	 AcrossX ++
	 EditPos = CONTROLCMD(w1,RichEdit,@RTCHARFROMLINE,cLine-1)
	 EditPos = (EditPos + AcrossX) - 1
    setcontroltext(w1,LineNumberEdit,ltrim$(str$(cLine))) 
	 setcontroltext(w1,PosEdit,ltrim$(str$(EditPos)))
	 CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line$,512)
	 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
	 WordNumber = GetAllWordsOnLine(rHandle,cLine-1,line$,Offset)
	 setcontroltext(w1,WordNumberEdit,ltrim$(str$(WordNumber)))
    CharPos = (EditPos - Offset) + 1
	 setcontroltext(w1,CharPosEdit,ltrim$(str$(CharPos)))
	 InitialLoad = 0
	 Loading = 0
	 OldLines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
	 starttimer w1,TimerSpeed1,MainTimer
    setfocus w1,RichEdit	
return
endsub

sub StarTabs()
	 Mod = 1
    select OnTab
           case 1 
					 if instr(getcaption(w1),getcontroltext(w1,FileTab1))
						 if !instr(getcontroltext(w1,FileTab1),"*")
							 setcontroltext(w1,FileTab1,getcontroltext(w1,FileTab1) + "*")
							 setcaption(w1,getcaption(w1) + "*")
						 endif
					 endif
           case 2
					 if instr(getcaption(w1),getcontroltext(w1,FileTab2))
						 if !instr(getcontroltext(w1,FileTab2),"*")
							 setcontroltext(w1,FileTab2,getcontroltext(w1,FileTab2) + "*")
							 setcaption(w1,getcaption(w1) + "*")
						 endif
					 endif
           case 3
					 if instr(getcaption(w1),getcontroltext(w1,FileTab3))
						 if !instr(getcontroltext(w1,FileTab3),"*")
						 	 setcontroltext(w1,FileTab3,getcontroltext(w1,FileTab3) + "*")
							 setcaption(w1,getcaption(w1) + "*")
						 endif
					 endif
	        case 4
					 if instr(getcaption(w1),getcontroltext(w1,FileTab4))
						 if !instr(getcontroltext(w1,FileTab4),"*")
							 setcontroltext(w1,FileTab4,getcontroltext(w1,FileTab4) + "*")
							 setcaption(w1,getcaption(w1) + "*")
						 endif
					 endif
           case 5
					 if instr(getcaption(w1),getcontroltext(w1,FileTab5))
						 if !instr(getcontroltext(w1,FileTab5),"*")
							 setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab5) + "*")
							 setcaption(w1,getcaption(w1) + "*")
						 endif
					 endif

           case 6
					 if instr(getcaption(w1),getcontroltext(w1,FileTab6))
						 if !instr(getcontroltext(w1,FileTab6),"*")
							 setcontroltext(w1,FileTab6,getcontroltext(w1,FileTab6) + "*")
							 setcaption(w1,getcaption(w1) + "*")
						 endif
					 endif
    endselect
Return
endsub

sub ReSizeTabs()

	 StoreLastTabWidth = 0
    if getcontroltext(w1,FileTab1) <> ""
		 CalcTabSize(getcontroltext(w1,FileTab1))
		 if CONTROLEXISTS(w1,RichEdit)
			 SETSIZE w1,0,642,Total,25,FileTab1
			 StoreLastTabWidth = Total
		 endif
    else
		 showwindow w1,@SWHIDE,FileTab1
    endif
    if getcontroltext(w1,FileTab2) <> ""
		 CalcTabSize(getcontroltext(w1,FileTab2))
		 if CONTROLEXISTS(w1,RichEdit)
			 SETSIZE w1,StoreLastTabWidth,642,Total,25,FileTab2
			 StoreLastTabWidth = StoreLastTabWidth + Total
		 endif 
    else
		 showwindow w1,@SWHIDE,FileTab2
    endif
    if getcontroltext(w1,FileTab3) <> ""
		 CalcTabSize(getcontroltext(w1,FileTab3))
		 if CONTROLEXISTS(w1,RichEdit)
			 SETSIZE w1,StoreLastTabWidth,642,Total,25,FileTab3
			 StoreLastTabWidth = StoreLastTabWidth + Total
		 endif
    else
		 showwindow w1,@SWHIDE,FileTab3 
    endif
    if getcontroltext(w1,FileTab4) <> ""
		 CalcTabSize(getcontroltext(w1,FileTab4))
		 if CONTROLEXISTS(w1,RichEdit)
			 SETSIZE w1,StoreLastTabWidth,642,Total,25,FileTab4
			 StoreLastTabWidth = StoreLastTabWidth + Total
		 endif 
    else
		 showwindow w1,@SWHIDE,FileTab4
    endif
    if getcontroltext(w1,FileTab5) <> ""
		 CalcTabSize(getcontroltext(w1,FileTab5))
		 if CONTROLEXISTS(w1,RichEdit)
			 SETSIZE w1,StoreLastTabWidth,642,Total,25,FileTab5
			 StoreLastTabWidth = StoreLastTabWidth + Total
		 endif 
    else
		 showwindow w1,@SWHIDE,FileTab5
    endif
    if getcontroltext(w1,FileTab6) <> ""
		 CalcTabSize(getcontroltext(w1,FileTab6))
		 if CONTROLEXISTS(w1,RichEdit)
			 SETSIZE w1,StoreLastTabWidth,642,Total,25,FileTab6
			 StoreLastTabWidth = StoreLastTabWidth + Total
		 endif 
    else
		 showwindow w1,@SWHIDE,FileTab6
    endif
return
endsub

sub CalcTabSize(string TabIn)

Total = 0
int DelC = 0
for a = 1 to len(TabIn)
    Letter = mid$(TabIn,a,1)
    DelC = instr(LcaseS,Letter)
    if DelC
       Total = Total + LcaseV[DelC]
       goto NextLtr
    endif

    Letter = mid$(TabIn,a,1)
    DelC = instr(UcaseS,Letter)
    if DelC
       Total = Total + UcaseV[DelC]
       goto NextLtr
    endif

    Letter = mid$(TabIn,a,1)
    DelC = instr(Others,Letter)
    if DelC
       Total = Total + OthersV[DelC]
       goto NextLtr
    endif

    Total += 11    

label NextLtr
next a

Total += 20

return
endsub

'========================================================================
'                                                                       ' 
' Routine to update the current edit position for the Find edit control '
'                                                                       '
'========================================================================

sub GetSelPosEdit()
    CONTROLCMD w1,CodePhraseEdit,@EDGETSELECTION,ePos,ePos
    ePos ++
return
endsub

sub GetSelPosEditFind()
    CONTROLCMD w6,CodePhraseEdit,@EDGETSELECTION,ePos,ePos
print ePos
    ePos ++
return
endsub

'=======================================================================
'                                                                      ' 
' Routine to update the current edit position in the Rich edit control '
'                                                                      '
'=======================================================================
sub GetSelPos()
    if Scrolling then return

    'Used to get the edit position on screen
    CONTROLCMD w1,CodePhraseEdit,@EDGETSELECTION,EditPos,EditPos

    'Used to change the key word selection list view control location on screen 
	 ppos = GETCARETPOSITION w1,AcrossX,DownY
	 int lvX = AcrossX
	 int lvY = DownY
	 if kw = 0
		 setsize w1,lvX+58,lvY+98,300,38,ListView
	 endif

    'Make adjustment to reflect actual edit position NOT visual position on screen
	 int varStart2,varEnd2
	 CONTROLCMD w1,RichEdit,@RTGETSELECTION,varStart2,varEnd2
	 if varStart2 <> Offset
		 AdjustPos = EditPos - varStart2
	 else
		 AdjustPos = 0
	 endif
	 EditPos = EditPos - AdjustPos

    'Reset the edit position if position is at the start of a line
	 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
	 if cLine <> StoreLine and varStart2 = Offset
		 EditPos = Offset
       PrevEditPos = EditPos
       setcontroltext(w1,PosEdit,ltrim$(str$(EditPos))) 
       goto Continue
	 endif

    'Has edit position changed?
	 if PrevEditPos <> EditPos and EditPos <> Offset
		 PrevEditPos = EditPos
       'Rich edit pos (Zero based index)
       if Offset > 0 and EditPos = 0 'EditPos must equal offset value
          EditPos = Offset
          PrevEditPos = EditPos
       endif
       if Offset = 0 and varStart2 = 0 'EditPos must be zero
          EditPos = 0
          PrevEditPos = 0
       endif
		 setcontroltext(w1,PosEdit,ltrim$(str$(EditPos))) 
		 CONTROLCMD(w1,RichEdit,@RTGETLINE,cLine-1,line$,512)
		 Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)

       label Continue
		 WordNumber = GetAllWordsOnLine(rHandle,cLine-1,line$,Offset)
	 
       'Human position on line (One based index)
		 CharPos = (EditPos - Offset) + 1 
		 if CharPos < -1 then CharPos = 1
	    if PrevCharPos <> CharPos
		    PrevCharPos = CharPos 
		    setcontroltext(w1,CharPosEdit,ltrim$(str$(CharPos)))
	    endif

       'Human word number (One based index)
	    if PrevWordNumber <> WordNumber  
		    PrevWordNumber = WordNumber
		    setcontroltext(w1,WordNumberEdit,ltrim$(str$(WordNumber)))
	    endif
	 endif

return
endsub

SUB GetLines(OPT INT Switch),INT
    INT xx = 0
    ClipText = ""
    OPENFILE(myFile,ProgPath,"R")
    LoadFileToString(ProgPath,ClipText,TBuff,&fSize)
    closefile myfile
    if fSize > 500000
       CONTROLCMD w1,RichEdit,@RTSETLIMITTEXT,fSize + 500000
    endif
RETURN xx
ENDSUB

sub JustColourScreen()
	 Loading = 1
	 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
	 QuietMode(1)
	 ColourNow(w1,0,rHandle)
	 QuietMode(0)
	 Loading = 0
return
endsub

sub Load_Defaults()

'##############################
'                             '
' Variables you can customise '
'                             ' 
'##############################

IF OPENFILE(MyFile2,GETSTARTPATH + "\\Res\\"+ "xeditor4Defaults.ini","R") = 0

   'Use the Editor settings option (File, Editor settings), do not edit manually! 

   'Location    - YourFolder\Xeditor\Bin\Res folder
   'File        - xeditor4Defaults.ini (User preferences)
   'Backup file - xeditor4DefaultsBackup.ini

   INT xx = 0
   DO 
         xx ++
         READ MyFile2,dIn
              SELECT xx
							CASE 1
								  Spelling         		 = VAL(dIn)
							CASE 2  
								  FontSize         		 = VAL(dIn)
							CASE 3
								  FontName         		 = dIn
							CASE 4  
								  Ucase            		 = VAL(dIn)
							CASE 5
								  ScreenColour 	   	 = VAL(dIn)
							CASE 6
								  WindowBackColour 		 = VAL(dIn)
							CASE 7
								  AutoJumpTo       		 = VAL(dIn)
							CASE 8
								  ConfirmMessage   		 = VAL(dIn)
							CASE 9
								  MaxTabs          		 = VAL(dIn)
							CASE 10
								  Spelling         		 = VAL(dIn) 
							CASE 11
								  AutoSaveOnExit   		 = VAL(dIn)
							CASE 12
								  AutoSaveOnClose  		 = VAL(dIn)
							CASE 13
								  WheelScrollLines 		 = VAL(dIn)
							CASE 14
								  ToolTips         		 = VAL(dIn)
							CASE 15
								  TimerSpeed1      		 = VAL(dIn)
							CASE 16
								  ReIndexSpeed     		 = VAL(dIn)
							CASE 17
								  UndoKey          		 = VAL(dIn)
							CASE 18
								  RedoKey          		 = VAL(dIn)
							CASE 19
								  UndoAllKey       		 = VAL(dIn)
							CASE 20
								  RedoAllKey       		 = VAL(dIn)
							CASE 21
								  TabSpacing       		 = VAL(dIn)
							CASE 22
								  Tabss            		 = VAL(dIn)
							CASE 23
								  AutoCompleteKeyWords 	 = VAL(dIn)
							CASE 24
								  RoundBrackets    		 = VAL(dIn)
							CASE 25
								  SquareBrackets   		 = VAL(dIn)
							CASE 26
								  LocalSubColour   		 = VAL(dIn)
							CASE 27
								  LocalWinColour		  	 = VAL(dIn)
							CASE 28
								  DebugOn          		 = VAL(dIn)
							CASE 29
								  CoOn             		 = VAL(dIn)
							CASE 30
								  SearchCheckV     		 = VAL(dIn)
							CASE 31
								  ColourNumbers    		 = VAL(dIn)
							CASE 32
								  KeyWordColourAt		    = VAL(dIn)
							CASE 33
								  KeyWordColourVariables = VAL(dIn)
							CASE 34
								  KeyWordColourDollar 	 = VAL(dIn)
							CASE 35
								  KeyWordColourAtoZ   	 = VAL(dIn)
							CASE 36
								  KeyWordColourOther  	 = VAL(dIn)
                     case 37
                          FindFirstV             = val(dIn)  
                     case 38
                          FindAllV               = val(dIn)
                     case 39
                          FindLastV              = val(dIn)
                     case 40
                          AndV                   = val(dIn)
                     case 41
                          OrV                    = val(dIn)
                     case 42
                          RememberV              = val(dIn)
                     case 43
                          DupPlacesV             = val(dIn)
              ENDSELECT
   UNTIL EOF(MyFile2)
ELSE
   Defaults() 				'Editor default settings
   SetKeyWordColours()	'Key word default colours
ENDIF
CLOSEFILE MyFile2

'#####################################
'                                    '
' End of Variables you can customise '
'                                    ' 
'#####################################

RETURN
ENDSUB

'=====================================================
'                                                    ' 
' Load the main window - not much to see here really '
'                                                    '
'=====================================================

SUB LoadWindow()

SetupTiming()	'Not requiered.

OPENWINDOW w1,0,0,1350,725,@MINBOX|@MAXBOX|@SIZE|@CAPTION,0,"",&main
	SETWINDOWCOLOR w1,WindowBackColour
   SETCAPTION w1,"Opening, please wait while files load..." + ProgramTitle

	BEGINMENU w1
		  MENUTITLE "&File"
		  MENUITEM "New file",0,209
		  SEPARATOR
		  MENUITEM "Open file",0,210
		  SEPARATOR
		  MENUITEM "Close file",0,211
		  SEPARATOR
		  MENUITEM "Save file",0,212
		  MENUITEM "Save file as",0,213
		  SEPARATOR
		  MENUITEM "Backup file",0,214
		  MENUITEM "Reindex file",0,215
		  MENUITEM "Editor Settings",0,216
        separator
        MENUITEM "Recent files...",0,300
		  SEPARATOR
		  MENUITEM "Exit",0,220
		  MENUTITLE "&Edit"
		  MENUITEM "Cut		Ctrl + X",0,201
		  MENUITEM "Copy		Ctrl + C",0,202
		  MENUITEM "Paste		Ctrl + V",0,203
		  MENUITEM "Select All	Ctrl + A",0,206
		  MENUITEM "Find		Ctrl + F",0,204
		  MENUITEM "Replace	Ctrl + R",0,205
		  MENUTITLE "&Help"
		  MENUITEM "User guide",0,240
	ENDMENU
	 
	ADDACCELERATOR w1,@FCONTROL|@FVIRTKEY,ASC("X"),201 'Cut
	ADDACCELERATOR w1,@FCONTROL|@FVIRTKEY,ASC("C"),202 'Copy
	ADDACCELERATOR w1,@FCONTROL|@FVIRTKEY,ASC("V"),203 'Paste
	ADDACCELERATOR w1,@FCONTROL|@FVIRTKEY,ASC("A"),206 'Select All
	ADDACCELERATOR w1,@FCONTROL|@FVIRTKEY,ASC("F"),204 'Find
	ADDACCELERATOR w1,@FCONTROL|@FVIRTKEY,ASC("R"),203 'Replace

   'The rich edit control
   CONTROL w1,@RICHEDIT,"",119,100,EndButtons-109,rcDepth,0x50B010C4,RichEdit 
			  SETFONT w1,FontName,FontSize,400,0,RichEdit
			  MODIFYEXSTYLE(w1,0,@EXCLIENTEDGE|WS_BORDER,RichEdit)
			  REDRAWFRAME(w1,RichEdit)
			  mask = CONTROLCMD(w1,RichEdit,@RTGETEVENTMASK)
			  CONTROLCMD w1, RichEdit, @RTSETEVENTMASK, mask | @ENMKEYEVENTS | @ENMSCROLL | @ENMCHANGE | ENM_MOUSEEVENTS
			  SENDMESSAGE w1,EM_SETBKGNDCOLOR,0,ScreenColour,RichEdit
			  SENDMESSAGE w1,EM_SHOWSCROLLBAR,SB_VERT,FALSE,RichEdit
			  CONTROLCMD w1,RichEdit,@RTSETLIMITTEXT,TBuff
			  SubclassRichEdit(w1,RichEdit)

			  'Line numbers
			  Downs = 102
			  FOR a = 1 TO LinesPerPage
				   CONTROL w1,@STATIC,"",32,Downs,80,LineSpace,@CTEDITRIGHT|0x200,a+1000
				   SETFONT w1, FontName,FontSize,400,0,a+1000
				   SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
				   Downs = Downs + LineSpace
			  NEXT a

   CONTROL w1,@LISTVIEW,"",0,0,270,58,@BORDER|@LVSSHOWSELALWAYS|@LVSSORTASCENDING|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListView2
		     SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView2
		     CONTROLCMD w1,ListView2,@LVINSERTCOLUMN,0,"Subroutine"
		     CONTROLCMD w1,ListView2,@LVSETCOLWIDTH,0,150
		     CONTROLCMD w1,ListView2,@LVINSERTCOLUMN,1,"Begins"
		     CONTROLCMD w1,ListView2,@LVSETCOLWIDTH,1,50
		     CONTROLCMD w1,ListView2,@LVINSERTCOLUMN,2,"Ends"
		     SHOWWINDOW w1,@SWHIDE,ListView2

   CONTROL w1,@SCROLLBAR,"",EndButtons+10,100,15,rcDepth,0x50000001,ScrollBar

   CONTROL w1,@RICHEDIT,"",119,100,EndButtons-109,rcDepth,0x50B010C4,TextBlock1
			  SETFONT w1,FontName,FontSize,400,0,TextBlock1
			  MODIFYEXSTYLE(w1,0,@EXCLIENTEDGE|WS_BORDER,TextBlock1)
			  REDRAWFRAME(w1,TextBlock1)
			  CONTROLCMD w1,TextBlock1,@RTSETEVENTMASK, mask | @ENMKEYEVENTS | @ENMSCROLL | @ENMCHANGE | ENM_MOUSEEVENTS
			  SETCONTROLTEXT w1,TextBlock1,""
			  SENDMESSAGE w1,EM_SETBKGNDCOLOR,0,ScreenColour,TextBlock1
			  CONTROLCMD w1,TextBlock1,@RTSETLIMITTEXT,MainTimer
			  SHOWWINDOW w1,@SWHIDE,TextBlock1  

   CONTROL w1,@RICHEDIT,"",119,100,EndButtons-109,rcDepth,0x50B010C4,TextBlock2 
			  SETFONT w1,FontName,FontSize,400,0,TextBlock2
			  MODIFYEXSTYLE(w1,0,@EXCLIENTEDGE|WS_BORDER,TextBlock2)
			  REDRAWFRAME(w1,TextBlock2)
			  CONTROLCMD w1,TextBlock2,@RTSETEVENTMASK, mask | @ENMKEYEVENTS | @ENMSCROLL | @ENMCHANGE | ENM_MOUSEEVENTS
			  SETCONTROLTEXT w1,TextBlock2,""
			  SENDMESSAGE w1,EM_SETBKGNDCOLOR,0,ScreenColour,TextBlock2
			  CONTROLCMD w1,TextBlock2,@RTSETLIMITTEXT,MainTimer
			  SHOWWINDOW w1,@SWHIDE,TextBlock2

   CONTROL w1,@RICHEDIT,"",119,100,EndButtons-109,rcDepth,0x50B010C4,TextBlock3 
			  SETFONT w1,FontName,FontSize,400,0,TextBlock3
			  MODIFYEXSTYLE(w1,0,@EXCLIENTEDGE|WS_BORDER,TextBlock3)
			  REDRAWFRAME(w1,TextBlock3)
			  CONTROLCMD w1,TextBlock3,@RTSETEVENTMASK, mask | @ENMKEYEVENTS | @ENMSCROLL | @ENMCHANGE | ENM_MOUSEEVENTS
			  SETCONTROLTEXT w1,TextBlock3,""
			  SENDMESSAGE w1,EM_SETBKGNDCOLOR,0,ScreenColour,TextBlock3
			  CONTROLCMD w1,TextBlock3,@RTSETLIMITTEXT,MainTimer
			  SHOWWINDOW w1,@SWHIDE,TextBlock3

   CONTROL w1,@RICHEDIT,"",119,100,EndButtons-109,rcDepth,0x50B010C4,TextBlock4 
			  SETFONT w1,FontName,FontSize,400,0,TextBlock4
			  MODIFYEXSTYLE(w1,0,@EXCLIENTEDGE|WS_BORDER,TextBlock4)
			  REDRAWFRAME(w1,TextBlock4)
			  CONTROLCMD w1,TextBlock4,@RTSETEVENTMASK, mask | @ENMKEYEVENTS | @ENMSCROLL | @ENMCHANGE | ENM_MOUSEEVENTS
			  SETCONTROLTEXT w1,TextBlock4,""
			  SENDMESSAGE w1,EM_SETBKGNDCOLOR,0,ScreenColour,TextBlock4
			  CONTROLCMD w1,TextBlock4,@RTSETLIMITTEXT,MainTimer
			  SHOWWINDOW w1,@SWHIDE,TextBlock4

   'Listview to store installed font names and sizes
   CONTROL w1,@LISTVIEW,"",0,0,455,380,@BORDER|@LVSSHOWSELALWAYS|@LVSSORTASCENDING|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewFonts
		     SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewFonts
		     CONTROLCMD w1,ListViewFonts,@LVINSERTCOLUMN,0,"Font"
		     CONTROLCMD w1,ListViewFonts,@LVSETCOLWIDTH,0,255
			  CONTROLCMD w1,ListViewFonts,@LVINSERTCOLUMN,1,"Size"
			  CONTROLCMD w1,ListViewFonts,@LVSETCOLWIDTH,1,100
			  CONTROLCMD w1,ListViewFonts,@LVINSERTCOLUMN,2,"Height"
			  CONTROLCMD w1,ListViewFonts,@LVSETCOLWIDTH,2,100
			  SETFONT w1,"Arial",11,400,0,ListViewFonts
			  SHOWWINDOW w1,@SWHIDE,ListViewFonts

			  LoadFonts(w1,ListViewFonts,1)
			  PositionZ = CONTROLCMD(w1,ListViewFonts,@LVFINDITEM,FontName)
			  IF PositionZ > -1
				  STRING textH
				  CONTROLCMD(w1,ListViewFonts,@LVGETTEXT,PositionZ,1,text)
				  CONTROLCMD(w1,ListViewFonts,@LVGETTEXT,PositionZ,2,textH)
			  ENDIF
			  TheFontSize = VAL(text)

			  'Handle to the rich edit control
			  rHandle = GETCONTROLHANDLE(w1,RichEdit)
			  Loading = 1

   'Coordinates
   CONTROL w1,@CHECKBOX,"Coordinates",70,617,100,25,@CTEDITLEFT,CoorCheck
           SETCONTROLCOLOR w1,CoorCheck,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,CoorCheck

   CONTROL w1,@EDIT,"",1043,73,60,22,@CTEDITRO|ES_SUNKEN,LineNumberEdit
           SETFONT w1,"Arial",11,400,0,LineNumberEdit
           SHOWWINDOW w1,@SWHIDE,LineNumberEdit

   CONTROL w1,@EDIT,"",1148,73,40,22,@CTEDITRO|ES_SUNKEN,WordNumberEdit
           SETFONT w1,"Arial",11,400,0,WordNumberEdit
           SHOWWINDOW w1,@SWHIDE,WordNumberEdit

   CONTROL w1,@STATIC,"Pos",1088,53,30,16,@CTEDITRIGHT|0x200,PosStatic
           SETCONTROLCOLOR w1,PosStatic,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,PosStatic

   CONTROL w1,@EDIT,"",1127,50,73,22,@CTEDITRO|ES_SUNKEN,PosEdit
           SETFONT w1,"Arial",11,400,0,PosEdit

   CONTROL w1,@STATIC,"Chr",1210,53,25,16,@CTEDITRIGHT|0x200,CharPosStatic
           SETCONTROLCOLOR w1,CharPosStatic,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,CharPosStatic

   CONTROL w1,@EDIT,"",1240,50,50,22,@CTEDITRO|ES_SUNKEN,CharPosEdit
           SETFONT w1,"Arial",11,400,0,CharPosEdit

			  IF CoOn = 1
				  SHOWWINDOW w1,@SWSHOW,PosStatic
				  SHOWWINDOW w1,@SWSHOW,PosEdit
				  SHOWWINDOW w1,@SWSHOW,CharPosStatic
				  SHOWWINDOW w1,@SWSHOW,CharPosEdit
              SETSTATE w1,CoorCheck,1
           else
				  SHOWWINDOW w1,@SWHIDE,PosStatic
				  SHOWWINDOW w1,@SWHIDE,PosEdit
				  SHOWWINDOW w1,@SWHIDE,CharPosStatic
				  SHOWWINDOW w1,@SWHIDE,CharPosEdit
			  ENDIF 

   'Debug
   CONTROL w1,@CHECKBOX,"Debug",1150,47,70,25,@CTEDITLEFT,DebugCheck
           SETCONTROLCOLOR w1,DebugCheck,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,DebugCheck
           IF DebugOn = 1
              SETSTATE w1,DebugCheck,1
           ENDIF
           showwindow w1,@SWHIDE,DebugCheck

   CONTROL w1,@STATIC,"",1040,97,280,25,@CTEDITLEFT|0x200,Debug2 
           SETCONTROLCOLOR w1,Debug2,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",12,400,0,Debug2 

   CONTROL w1,@STATIC,"",1040,122,280,25,@CTEDITLEFT|0x200,Debug3
           SETCONTROLCOLOR w1,Debug3,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",12,400,0,Debug3

			  IF DebugOn = 1
				  SHOWWINDOW w1,@SWSHOW,Debug1
				  SHOWWINDOW w1,@SWSHOW,Debug2
				  SHOWWINDOW w1,@SWSHOW,Debug3
			  ENDIF 
			  IF DebugOn = 0
				  SHOWWINDOW w1,@SWHIDE,Debug1
				  SHOWWINDOW w1,@SWHIDE,Debug2
				  SHOWWINDOW w1,@SWHIDE,Debug3
			  ENDIF

   'Code buttons
   CONTROL w1,@BUTTON,"Main program",70,590,100,25,@CTEDITRIGHT,ShowCode
           SETCONTROLCOLOR w1,ShowCode,RGB(255,255,255),BlueButton
           SETFONT w1,"Arial",10,400,0,ShowCode 

   CONTROL w1,@BUTTON,"1",180,590,25,25,@CTEDITRIGHT,ShowBlock1
           SETCONTROLCOLOR w1,ShowBlock1,RGB(255,255,255),BackColour
           SETFONT w1,"Arial",10,400,0,ShowBlock1
           ENABLECONTROL w1,ShowBlock1,0 

   CONTROL w1,@BUTTON,"2",210,590,25,25,@CTEDITRIGHT,ShowBlock2
           SETCONTROLCOLOR w1,ShowBlock2,RGB(255,255,255),BackColour
           SETFONT w1,"Arial",10,400,0,ShowBlock2
           ENABLECONTROL w1,ShowBlock2,0 

   CONTROL w1,@BUTTON,"3",240,590,25,25,@CTEDITRIGHT,ShowBlock3
           SETCONTROLCOLOR w1,ShowBlock3,RGB(255,255,255),BackColour
           SETFONT w1,"Arial",10,400,0,ShowBlock3
           ENABLECONTROL w1,ShowBlock3,0 

   CONTROL w1,@BUTTON,"4",270,590,25,25,@CTEDITRIGHT,ShowBlock4
           SETCONTROLCOLOR w1,ShowBlock4,RGB(255,255,255),BackColour
           SETFONT w1,"Arial",10,400,0,ShowBlock4
           ENABLECONTROL w1,ShowBlock4,0 

   CONTROL w1,@BUTTON,"",300,590,25,25,@CTLBTNBITMAP,CopyBlockButton
           SETCONTROLTEXT w1,CopyBlockButton,GETSTARTPATH() + "\\Res\\copy2.bmp"

   CONTROL w1,@BUTTON,"",330,590,25,25,@CTLBTNBITMAP,DeleteBlockButton
           SETCONTROLTEXT w1,DeleteBlockButton,GETSTARTPATH() + "\\Res\\remove2.bmp"

   'File buttons
   CONTROL w1,@BUTTON,"",1,110,30,30,@CTLBTNBITMAP,NewButton
           SETCONTROLTEXT w1,NewButton,GETSTARTPATH() + "\\Res\\new.bmp"

   CONTROL w1,@BUTTON,"",1,150,30,30,@CTLBTNBITMAP,OpenButton
           SETCONTROLTEXT w1,OpenButton,GETSTARTPATH() + "\\Res\\Open.bmp"

   CONTROL w1,@BUTTON,"",1,190,30,30,@CTLBTNBITMAP,SaveButton
           SETCONTROLTEXT w1,SaveButton,GETSTARTPATH() + "\\Res\\Save.bmp"

   CONTROL w1,@BUTTON,"",1,230,30,30,@CTLBTNBITMAP,SaveAsButton
           SETCONTROLTEXT w1,SaveAsButton,GETSTARTPATH() + "\\Res\\SaveAs.bmp"

   CONTROL w1,@BUTTON,"",1,270,30,30,@CTLBTNBITMAP,BackupButton
           SETCONTROLTEXT w1,BackupButton,GETSTARTPATH() + "\\Res\\Backup.bmp"

   CONTROL w1,@BUTTON,"",1,310,30,30,@CTLBTNBITMAP,CogButton
           SETCONTROLTEXT w1,CogButton,GETSTARTPATH() + "\\Res\\Cog.bmp"

   CONTROL w1,@BUTTON,"",1,350,30,30,@CTLBTNBITMAP,AutoButton
           IF AutoCompleteKeyWords = 1
              SETCONTROLTEXT w1,AutoButton,GETSTARTPATH() + "\\Res\\SpellingOn.bmp"
           ELSE
              SETCONTROLTEXT w1,AutoButton,GETSTARTPATH() + "\\Res\\SpellingOff.bmp"
           ENDIF

   CONTROL w1,@BUTTON,"",1,390,30,30,@CTLBTNBITMAP,ColourButton
           SETCONTROLTEXT w1,ColourButton,GETSTARTPATH() + "\\Res\\Colour.bmp"

   CONTROL w1,@BUTTON,"",1,430,30,30,@CTLBTNBITMAP,BinButton
           SETCONTROLTEXT w1,BinButton,GETSTARTPATH() + "\\Res\\Bin.bmp"

   CONTROL w1,@BUTTON,"",1,470,30,30,@CTLBTNBITMAP,ConstantsButton
           SETCONTROLTEXT w1,ConstantsButton,GETSTARTPATH() + "\\Res\\constantssearch.bmp"

   CONTROL w1,@BUTTON,"",1,510,30,30,@CTLBTNBITMAP,ReLoadButton
           SETCONTROLTEXT w1,ReLoadButton,GETSTARTPATH() + "\\Res\\Recycle.bmp"

   CONTROL w1,@BUTTON,"",1,588,30,30,@CTLBTNBITMAP,CloseButton
           SETCONTROLTEXT w1,CloseButton,GETSTARTPATH() + "\\Res\\delete2.bmp"

   'File tabs
   CONTROL w1,@BUTTON,"",0,647,0,0,@CTEDITLEFT,FileTab1
           SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",12,400,0,FileTab1

   CONTROL w1,@BUTTON,"",216,647,0,0,@CTEDITLEFT,FileTab2
           SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",12,400,0,FileTab2
           SHOWWINDOW w1,@SWHIDE,FileTab2

   CONTROL w1,@BUTTON,"",432,647,0,0,@CTEDITLEFT,FileTab3
           SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",12,400,0,FileTab3
           SHOWWINDOW w1,@SWHIDE,FileTab3

   CONTROL w1,@BUTTON,"",648,647,0,0,@CTEDITLEFT,FileTab4
           SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",12,400,0,FileTab4
           SHOWWINDOW w1,@SWHIDE,FileTab4

   CONTROL w1,@BUTTON,"",864,647,0,0,@CTEDITLEFT,FileTab5
           SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",12,400,0,FileTab5
           SHOWWINDOW w1,@SWHIDE,FileTab5

   CONTROL w1,@BUTTON,"",1080,647,0,0,@CTEDITLEFT,FileTab6
           SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",12,400,0,FileTab6
           SHOWWINDOW w1,@SWHIDE,FileTab6

   'Line entry
   CONTROL w1,@STATIC," Go to line",35,0,100,20,@CTEDITLEFT|0x200,LineStatic 
           SETCONTROLCOLOR w1,LineStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",11,400,0,LineStatic

   CONTROL w1,@BUTTON,"",5,17,25,25,@CTLBTNBITMAP,BUTTON_4
           SETCONTROLTEXT w1,BUTTON_4,GETSTARTPATH() + "\\Res\\jump.bmp"
           SHOWWINDOW w1,@SWHIDE,BUTTON_4

   CONTROL w1,@EDIT,"",35,19,84,22,@CTEDITNUMBER|@CTEDITAUTOH|ES_SUNKEN,EDIT_1 'Control jump to line number
           CONTROLCMD w1,EDIT_1,@EDSETLIMITTEXT,255
           SETFONT w1,"Courier New",11,400,0,EDIT_1
           SHOWWINDOW w1,@SWHIDE,EDIT_1

   CONTROL w1,@EDIT,"",35,19,84,22,@CTEDITNUMBER|@CTEDITAUTOH|ES_SUNKEN,EDIT_10 'Control jump to line number
           CONTROLCMD w1,EDIT_10,@EDSETLIMITTEXT,255
           SETFONT w1,"Courier New",11,400,0,EDIT_10
           SHOWWINDOW w1,@SWHIDE,EDIT_10

   CONTROL w1,@EDIT,"",35,19,85,22,@CTEDITNUMBER|@CTEDITAUTOH||ES_SUNKEN,EDIT_11 'User jump to line number
           CONTROLCMD w1,EDIT_11,@EDSETLIMITTEXT,255
           SETFONT w1,"Courier New",11,400,0,EDIT_11

   CONTROL w1,@BUTTON,"",5,45,25,25,@CTLBTNBITMAP,BUTTON_44
           SETCONTROLTEXT w1,BUTTON_44,GETSTARTPATH() + "\\Res\\jump.bmp"
           SHOWWINDOW w1,@SWHIDE,BUTTON_44

   CONTROL w1,@BUTTON,"",5,71,25,25,@CTLBTNBITMAP,BUTTON_444
           SETCONTROLTEXT w1,BUTTON_444,GETSTARTPATH() + "\\Res\\jump.bmp"
           SHOWWINDOW w1,@SWHIDE,BUTTON_444

   CONTROL w1,@EDIT,"",35,45,85,22,@CTEDITNUMBER|@CTEDITAUTOH||ES_SUNKEN,EDIT_111 'User jump to line number
           CONTROLCMD w1,EDIT_111,@EDSETLIMITTEXT,255
           SETFONT w1,"Courier New",11,400,0,EDIT_111

   CONTROL w1,@EDIT,"",35,71,85,22,@CTEDITNUMBER|@CTEDITAUTOH||ES_SUNKEN,EDIT_1111 'User jump to line number
           CONTROLCMD w1,EDIT_1111,@EDSETLIMITTEXT,255
           SETFONT w1,"Courier New",11,400,0,EDIT_1111

   'Subroutines
	CONTROL w1,@STATIC," Subroutines",184,2,150,20,@CTEDITLEFT,SubStatic 
			  SETCONTROLCOLOR w1,SubStatic,RGB(0,0,0),WindowBackColour
			  SETFONT w1,"Arial",11,400,0,SubStatic

	CONTROL w1,@COMBOBOX,"",186,19,190,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo2
			  SETFONT w1,"Arial",11,400,0,Combo2

   CONTROL w1,@BUTTON,"",155,17,25,25,@CTLBTNBITMAP,SubJump
           SETCONTROLTEXT w1,SubJump,GETSTARTPATH() + "\\Res\\jump.bmp"

   CONTROL w1,@BUTTON,"",155,47,25,25,@CTLBTNBITMAP,EndSubb
           SETCONTROLTEXT w1,EndSubb,GETSTARTPATH() + "\\Res\\jumpEnd.bmp"

   CONTROL w1,@BUTTON,"",155,75,25,25,@CTLBTNBITMAP,ClearSubs
           SETCONTROLTEXT w1,ClearSubs,GETSTARTPATH() + "\\Res\\delete.bmp"

   CONTROL w1,@BUTTON,"",185,47,25,25,@CTLBTNBITMAP,SubSearchButton 
			  SETCONTROLTEXT w1,SubSearchButton,GETSTARTPATH() + "\\Res\\find.bmp"

   CONTROL w1,@BUTTON,"",215,47,25,25,@CTLBTNBITMAP,CopySubButton 
           SETCONTROLTEXT w1,CopySubButton,GETSTARTPATH() + "\\Res\\copy2.bmp"

   CONTROL w1,@BUTTON,"",245,47,25,25,@CTLBTNBITMAP,CopySubBlockButton 
           SETCONTROLTEXT w1,CopySubBlockButton,GETSTARTPATH() + "\\Res\\block2.bmp"

   'CONTROL w1,@BUTTON,"",245,47,25,25,@CTLBTNBITMAP,MoveSubButton 
           'SETCONTROLTEXT w1,MoveSubButton,GETSTARTPATH() + "\\Res\\Move2.bmp"

   CONTROL w1,@BUTTON,"",285,47,25,25,@CTLBTNBITMAP,DeleteSubButton
           SETCONTROLTEXT w1,DeleteSubButton,GETSTARTPATH() + "\\Res\\remove2.bmp"

   CONTROL w1,@BUTTON,"",328,47,25,25,@CTLBTNBITMAP,ShowSubButton
           SETCONTROLTEXT w1,ShowSubButton,GETSTARTPATH() + "\\Res\\show.bmp"

   'Windows
	CONTROL w1,@LISTVIEW,"",340,0,420,58,@BORDER|@LVSSHOWSELALWAYS|@LVSSORTASCENDING|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListView4
			  SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView4
           CONTROLCMD w1,ListView4,@LVINSERTCOLUMN,0,"Window"
			  CONTROLCMD w1,ListView4,@LVSETCOLWIDTH,0,150
			  CONTROLCMD w1,ListView4,@LVINSERTCOLUMN,1,"Begins"
			  CONTROLCMD w1,ListView4,@LVSETCOLWIDTH,1,50
			  CONTROLCMD w1,ListView4,@LVINSERTCOLUMN,2,"Ends"
			  CONTROLCMD w1,ListView4,@LVSETCOLWIDTH,2,50
			  CONTROLCMD w1,ListView4,@LVINSERTCOLUMN,3,"Handler name"
			  CONTROLCMD w1,ListView4,@LVSETCOLWIDTH,3,150
           SHOWWINDOW w1,@SWHIDE,ListView4

   CONTROL w1,@STATIC," Windows && Dialogs",425,0,167,20,@CTEDITLEFT|0x200,WinStatic 
           SETCONTROLCOLOR w1,WinStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",11,400,0,WinStatic

   CONTROL w1,@COMBOBOX,"",425,19,207,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo4
           SETFONT w1,"Arial",11,400,0,Combo4

   CONTROL w1,@BUTTON,"",395,17,25,25,@CTLBTNBITMAP,WinJump
           SETCONTROLTEXT w1,WinJump,GETSTARTPATH() + "\\Res\\jump.bmp"

   CONTROL w1,@BUTTON,"",395,47,25,25,@CTLBTNBITMAP,EndWin
           SETCONTROLTEXT w1,EndWin,GETSTARTPATH() + "\\Res\\jumpEnd.bmp"

   CONTROL w1,@BUTTON,"",395,75,25,25,@CTLBTNBITMAP,ClearWins
           SETCONTROLTEXT w1,ClearWins,GETSTARTPATH() + "\\Res\\delete.bmp"

   CONTROL w1,@BUTTON,"",425,47,25,25,@CTLBTNBITMAP|0x200,WinHandler
           SETCONTROLTEXT w1,WinHandler,GETSTARTPATH() + "\\Res\\handle.bmp"

   CONTROL w1,@BUTTON,"",455,47,25,25,@CTLBTNBITMAP,CopyWinButton 
           SETCONTROLTEXT w1,CopyWinButton,GETSTARTPATH() + "\\Res\\copy2.bmp"

   CONTROL w1,@BUTTON,"",485,47,25,25,@CTLBTNBITMAP,CopyWinBlockButton 
           SETCONTROLTEXT w1,CopyWinBlockButton,GETSTARTPATH() + "\\Res\\block2.bmp"

   'CONTROL w1,@BUTTON,"",515,47,25,25,@CTLBTNBITMAP,MoveWinButton 
           'SETCONTROLTEXT w1,MoveWinButton,GETSTARTPATH() + "\\Res\\move2.bmp"

   CONTROL w1,@BUTTON,"",550,47,25,25,@CTLBTNBITMAP,DeleteWinButton
           SETCONTROLTEXT w1,DeleteWinButton,GETSTARTPATH() + "\\Res\\remove2.bmp"

   CONTROL w1,@BUTTON,"",583,47,25,25,@CTLBTNBITMAP,ShowWindowButton
           SETCONTROLTEXT w1,ShowWindowButton,GETSTARTPATH() + "\\Res\\show.bmp"

   'Bookmarks
   CONTROL w1,@STATIC," Bookmarks",920,0,167,20,@CTEDITLEFT|0x200,BookStatic 
           SETCONTROLCOLOR w1,BookStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",11,400,0,BookStatic

	CONTROL w1,@LISTVIEW,"",910,590,250,80,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListView6
			  SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView6
			  CONTROLCMD w1,ListView6,@LVINSERTCOLUMN,0,"Line"
			  CONTROLCMD w1,ListView6,@LVSETCOLWIDTH,0,150
			  CONTROLCMD w1,ListView6,@LVINSERTCOLUMN,1,"Description"
			  CONTROLCMD w1,ListView6,@LVSETCOLWIDTH,1,100
           SHOWWINDOW w1,@SWHIDE,ListView6

   CONTROL w1,@COMBOBOX,"",920,19,160,500,@CTCOMBODROPDOWN|@VSCROLL|SS_NOTIFY|@TABSTOP,Combo6
           SETFONT w1,"Arial",10,400,0,Combo6

   CONTROL w1,@BUTTON,"",890,17,25,25,@CTLBTNBITMAP,BookJump
           SETCONTROLTEXT w1,BookJump,GETSTARTPATH() + "\\Res\\jump.bmp"

   CONTROL w1,@BUTTON,"",920,47,25,25,@CTLBTNBITMAP,BookAdd
           SETCONTROLTEXT w1,BookAdd,GETSTARTPATH() + "\\Res\\add.bmp"

   CONTROL w1,@BUTTON,"",950,47,25,25,@CTLBTNBITMAP,BookDel
           SETCONTROLTEXT w1,BookDel,GETSTARTPATH() + "\\Res\\minus.bmp"

   CONTROL w1,@BUTTON,"",1000,47,25,25,@CTLBTNBITMAP,BookDelAll
           SETCONTROLTEXT w1,BookDelAll,GETSTARTPATH() + "\\Res\\delete.bmp"

   'Controls
   CONTROL w1,@BUTTON,"Search controls",455,75,152,25,@CTEDITLEFT,HandyControls
           SETCONTROLCOLOR w1,HandyControls,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,HandyControls

	CONTROL w1,@LISTVIEW,"",675,20,200,52,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL|LVS_NOCOLUMNHEADER|LVS_SORTASCENDING,ListView10
			  SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView10
			  CONTROLCMD w1,ListView10,@LVINSERTCOLUMN,0,"Name"
			  CONTROLCMD w1,ListView10,@LVSETCOLWIDTH,0,100
			  CONTROLCMD w1,ListView10,@LVINSERTCOLUMN,1,"Line"
			  CONTROLCMD w1,ListView10,@LVSETCOLWIDTH,1,50
			  CONTROLCMD w1,ListView10,@LVINSERTCOLUMN,2,"Window"
			  CONTROLCMD w1,ListView10,@LVSETCOLWIDTH,2,50
			  CONTROLCMD w1,ListView10,@LVINSERTCOLUMN,3,"Type"
			  CONTROLCMD w1,ListView10,@LVSETCOLWIDTH,3,0
           SETFONT w1,"Arial",11,400,0,ListView10
           showwindow w1,@SWHIDE,ListView10 

   'Block code
   CONTROL w1,@STATIC,"Add ready made code",697,0,150,20,@CTEDITLEFT|0x200,STATIC_4 
           SETCONTROLCOLOR w1,STATIC_4,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",11,400,0,STATIC_4

   CONTROL w1,@BUTTON,"",650,18,25,25,@CTLBTNBITMAP,BlockJumpButton
           SETCONTROLTEXT w1,BlockJumpButton,GETSTARTPATH() + "\\Res\\jump.bmp"

   CONTROL w1,@COMBOBOX,"",680,18,200,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo1
           printDir(getstartpath + "\\Res\\")
           SETFONT w1,"Arial",12,400,0,Combo1

   'Top / botton buttons
   CONTROL w1,@BUTTON,"",1307,80,15,15,@CTLBTNBITMAP,TopButton 
           SETCONTROLTEXT w1,TopButton,GETSTARTPATH() + "\\Res\\top.bmp"

   CONTROL w1,@BUTTON,"",1307,rcDepth+105,15,15,@CTLBTNBITMAP,BottomButton 
           SETCONTROLTEXT w1,BottomButton,GETSTARTPATH() + "\\Res\\bottom.bmp"

   'Exit button
   CONTROL w1,@BUTTON,"Exit",1240,620,80,25,@CTEDITLEFT,ExitButton
           SETCONTROLCOLOR w1,ExitButton,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,ExitButton

   'Include files
   CONTROL w1,@STATIC,"Include files",1090,0,80,20,@CTEDITLEFT|0x200,IncludeStatic 
           SETCONTROLCOLOR w1,IncludeStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",11,400,0,IncludeStatic

           CONTROL w1,@COMBOBOX,"",1090,19,160,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo88
                   SETFONT w1,"Arial",12,400,0,Combo88

   'Navigation
	CONTROL w1,@COMBOBOX,"",780,75,80,200,@CTCOMBODROPDOWN|@VSCROLL|SS_NOTIFY|@TABSTOP,Combo18
			  SETFONT w1,"Arial",11,400,0,Combo18

	CONTROL w1,@BUTTON,"",650,75,26,25,@CTLBTNBITMAP,NavBackGrey 
			  SETCONTROLTEXT w1,NavBackGrey,GETSTARTPATH() + "\\Res\\navbackgrey.bmp"

	CONTROL w1,@BUTTON,"",650,75,26,25,@CTLBTNBITMAP,NavBackButton 
			  SETCONTROLTEXT w1,NavBackButton,GETSTARTPATH() + "\\Res\\navback.bmp"
           SHOWWINDOW w1,@SWHIDE,NavBackButton

	CONTROL w1,@BUTTON,"",680,75,25,25,@CTLBTNBITMAP,NavForwardGrey 
			  SETCONTROLTEXT w1,NavForwardGrey,GETSTARTPATH() + "\\Res\\navforwardgrey.bmp"

	CONTROL w1,@BUTTON,"",680,75,25,25,@CTLBTNBITMAP,NavForwardButton 
			  SETCONTROLTEXT w1,NavForwardButton,GETSTARTPATH() + "\\Res\\navforward.bmp"
           SHOWWINDOW w1,@SWHIDE,NavForwardButton

	CONTROL w1,@BUTTON,"",710,75,25,25,@CTLBTNBITMAP,NavButton 
			  SETCONTROLTEXT w1,NavButton,GETSTARTPATH() + "\\Res\\add.bmp"

   CONTROL w1,@BUTTON,"",740,75,25,25,@CTLBTNBITMAP,NavDeleteButton
			  SETCONTROLTEXT w1,NavDeleteButton,GETSTARTPATH() + "\\Res\\minus.bmp"

   CONTROL w1,@BUTTON,"",870,75,25,25,@CTLBTNBITMAP,NavDeleteAllButton
			  SETCONTROLTEXT w1,NavDeleteAllButton,GETSTARTPATH() + "\\Res\\Delete.bmp"

   'Remember location
   CONTROL w1,@STATIC,"Places I've been to",652,50,150,20,@CTEDITLEFT|0x200,RememberStatic 
           SETCONTROLCOLOR w1,RememberStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",11,400,0,RememberStatic

   CONTROL w1,@CHECKBOX,"Remember places",925,75,140,25,@CTEDITLEFT,RememberMe
           SETCONTROLCOLOR w1,RememberMe,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,RememberMe
           setstate w1,RememberMe,RememberV

   CONTROL w1,@CHECKBOX,"Allow duplicate places",1092,75,170,25,@CTEDITLEFT,DupPlaces
           SETCONTROLCOLOR w1,DupPlaces,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,DupPlaces
           setstate w1,DupPlaces,DupPlacesV

   'Auto jump
   CONTROL w1,@CHECKBOX,"Auto jump to selections",190,75,180,25,@CTEDITLEFT,Check1
           SETCONTROLCOLOR w1,Check1,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,Check1
           IF AutoJumpTo = 1
              SETSTATE w1,Check1,1
           ENDIF

   'Line
   'CONTROL w1,@STATIC,"Navigate",1,77,55,20,@CTEDITRIGHT|0x200,LinePosStatic
   'CONTROL w1,@EDIT,"",68,75,80,20,@CTEDITLEFT,LinePosEdit
   'showwindow w1,@SWHIDE,LinePosEdit

   'CONTROL w1,@STATIC,"Char",155,75,40,20,@CTEDITRIGHT|0x200,LineCharStatic
   CONTROL w1,@EDIT,"",204,75,80,20,@CTEDITLEFT,LineCharEdit
   SHOWWINDOW w1,@SWHIDE,LineCharEdit

   'CONTROL w1,@STATIC,"Edit Pos",285,75,70,20,@CTEDITRIGHT|0x200,nwPosStatic
   CONTROL w1,@EDIT,"",364,75,80,20,@CTEDITLEFT,nwPosEdit
   SHOWWINDOW w1,@SWHIDE,nwPosEdit

			  SETCONTROLCOLOR w1,LinePosStatic,RGB(0,0,0),WindowBackColour
			  SETCONTROLCOLOR w1,LineCharStatic,RGB(0,0,0),WindowBackColour
			  SETCONTROLCOLOR w1,nwPosStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",10,400,0,LinePosStatic
           SETFONT w1,"Arial",10,400,0,LineCharStatic
           SETFONT w1,"Arial",10,400,0,nwPosStatic
           SETFONT w1,"Arial",10,400,0,LinePosEdit
           SETFONT w1,"Arial",10,400,0,LineCharEdit
           SETFONT w1,"Arial",10,400,0,nwPosEdit
           'SETFONT w1,"Arial",10,400,0,EditPosEdit
  
   'Key words
   CONTROL w1,@LISTVIEW,"",1050,0,200,60,@BORDER|@LVSNOCOLUMNHEADER|@LVSSHOWSELALWAYS|@LVSREPORT,ListView
           SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView
           CONTROLCMD w1,ListView,@LVINSERTCOLUMN,0,""
           CONTROLCMD w1,ListView,@LVSETCOLWIDTH,0,280
           CONTROLCMD w1,ListView,@LVINSERTITEM,0,""
           SETFONT w1,"Arial",11,400,0,ListView
           SHOWWINDOW w1,@SWHIDE,ListView

   CONTROL w1,@EDIT,"",10,650,1000,20,@CTEDITLEFT,KeyWordEdit
           SHOWWINDOW w1,@SWHIDE,KeyWordEdit

   'Key word search
   CONTROL w1,@COMBOBOX,"",372,617,310,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo12
			  SETFONT w1,"Arial",11,400,0,Combo12

			  CONTROL w1,@BUTTON,"",690,590,25,25,@CTLBTNBITMAP,KeyFind 
						 SETCONTROLTEXT w1,KeyFind,GETSTARTPATH() + "\\Res\\find.bmp"

           CONTROL w1,@BUTTON,"",690,617,25,25,@CTLBTNBITMAP,KeyDelete
                   SETCONTROLTEXT w1,KeyDelete,GETSTARTPATH() + "\\Res\\delete.bmp"

		     CONTROL w1,@STATIC,"Key word",410,590,60,25,@CTEDITLEFT|0x200,KeyWordStatic
			          SETCONTROLCOLOR w1,KeyWordStatic,RGB(0,0,0),WindowBackColour
			          SETFONT w1,"Arial",11,400,0,KeyWordStatic

			  CONTROL w1,@CHECKBOX,"Begins with",185,617,100,25,@CTEDITLEFT,BeginsWith
						 SETCONTROLCOLOR w1,BeginsWith,RGB(0,0,0),BackColour
						 SETFONT w1,"Arial",11,400,0,BeginsWith
						 setstate w1,BeginsWith,1

			  CONTROL w1,@CHECKBOX,"In word",295,617,70,25,@CTEDITLEFT,InSubName
						 SETCONTROLCOLOR w1,InSubName,RGB(0,0,0),BackColour
						 SETFONT w1,"Arial",11,400,0,InSubName

           CONTROL w1,@EDIT,"",480,590,200,25,@CTEDITAUTOH|@CTEDITLEFT|ES_UPPERCASE,EDIT_2
                   CONTROLCMD w1,EDIT_2,@EDSETLIMITTEXT,255
			          SETFONT w1,"Arial",10,400,0,EDIT_2
                   SETCONTROLNOTIFY(w1,EDIT_2,1,1)
                   MaskEditControl(w1,EDIT_2,LettersOnly)

   'Code word search 
   CONTROL w1,@EDIT,"",750,590,100,25,@CTEDITAUTOH|@CTEDITLEFT,CodeWordEdit1
           CONTROLCMD w1,CodeWordEdit1,@EDSETLIMITTEXT,255
	        SETFONT w1,"Arial",11,400,0,CodeWordEdit1
           SETCONTROLNOTIFY(w1,CodeWordEdit1,1,1)
           MaskEditControl(w1,CodeWordEdit1,LettersOnly)
           showwindow w1,@SWHIDE,CodeWordEdit1

   'Phrase search
   CONTROL w1,@STATIC,"Find exact",740,590,80,25,@CTEDITLEFT|0x200,CodePhraseStatic
			  SETCONTROLCOLOR w1,CodePhraseStatic,RGB(0,0,0),WindowBackColour
			  SETFONT w1,"Arial",11,400,0,CodePhraseStatic

   CONTROL w1,@EDIT,"",830,590,235,25,@CTEDITAUTOH|@CTEDITLEFT,CodePhraseEdit
           CONTROLCMD w1,CodePhraseEdit,@EDSETLIMITTEXT,255
	        SETFONT w1,"Arial",12,400,0,CodePhraseEdit
           SETCONTROLNOTIFY(w1,CodePhraseEdit,1,1)
           SubclassEdit(w1,CodePhraseEdit)

			  CONTROL w1,@CHECKBOX,"Find exact",833,620,90,20,@CTEDITRIGHT,CodePhrase
					    SETCONTROLCOLOR w1,CodePhrase,RGB(0,0,0),WindowBackColour
					    SETFONT w1,"Arial",11,400,0,CodePhrase

			  CONTROL w1,@CHECKBOX,"Specific words",940,620,120,20,@CTEDITRIGHT,CodePhraseWords
					    SETCONTROLCOLOR w1,CodePhraseWords,RGB(0,0,0),WindowBackColour
					    SETFONT w1,"Arial",11,400,0,CodePhraseWords
					    SETSTATE w1,CodePhraseWords,0 

			  CONTROL w1,@CHECKBOX,"First",1120,590,50,25,@CTEDITLEFT,FindFirst
					    SETCONTROLCOLOR w1,FindFirst,RGB(0,0,0),WindowBackColour
					    SETFONT w1,"Arial",11,400,0,FindFirst
					    if FindFirstV = 1 then SETSTATE w1,FindFirst,1

			  CONTROL w1,@CHECKBOX,"All",1187,590,50,25,@CTEDITLEFT,FindAll
					    SETCONTROLCOLOR w1,FindAll,RGB(0,0,0),WindowBackColour
					    SETFONT w1,"Arial",11,400,0,FindAll
					    if FindAllV = 1 then SETSTATE w1,FindAll,1

			  CONTROL w1,@CHECKBOX,"Last",1240,590,50,25,@CTEDITLEFT,FindLast
					    SETCONTROLCOLOR w1,FindLAst,RGB(0,0,0),WindowBackColour
					    SETFONT w1,"Arial",11,400,0,FindLast
					    if FindLastV = 1 then SETSTATE w1,FindLast,1

			  CONTROL w1,@CHECKBOX,"And",1120,618,45,25,@CTEDITLEFT,CodeWordAnd
					    SETCONTROLCOLOR w1,CodeWordAnd,RGB(0,0,0),WindowBackColour
					    SETFONT w1,"Arial",11,400,0,CodeWordAnd
					    SETSTATE w1,CodeWordAnd,AndV 

			  CONTROL w1,@CHECKBOX,"Or",1187,618,45,25,@CTEDITLEFT,CodeWordOr
					    SETCONTROLCOLOR w1,CodeWordOr,RGB(0,0,0),WindowBackColour
					    SETFONT w1,"Arial",11,400,0,CodeWordOr
					    SETSTATE w1,CodeWordOr,OrV 

			  CONTROL w1,@BUTTON,"",1075,590,25,25,@CTLBTNBITMAP,CodePhraseSearch 
						 SETCONTROLTEXT w1,CodePhraseSearch,GETSTARTPATH() + "\\Res\\find.bmp"

           CONTROL w1,@BUTTON,"",1075,618,25,25,@CTLBTNBITMAP,PhraseDeleteButton
                   SETCONTROLTEXT w1,PhraseDeleteButton,GETSTARTPATH() + "\\Res\\delete.bmp"

                   CodePhraseV = 1
                   CodePhraseWordsV = 0
                   showwindow w1,@SWHIDE,CodeWordAnd
                   showwindow w1,@SWHIDE,CodeWordOr
 
    'Load key words into a list view...
    CONTROLCMD w1,ListView,@LVINSERTITEM,0," "
		  FOR a = 1 TO 1661
				CONTROLCMD w1,ListView,@LVINSERTITEM,a,#p[a].words
		  NEXT a

   ENABLECONTROL w1,RichEdit,1
   SETCONTROLNOTIFY(w1,RichEdit,1,1)

   ShowSubRoutineButtons(0)
   ShowWindowButtons(0)

	Tabss = (TabSpacing * 4) 
   SETSIZE w1,119,100,EndButtons-109,rcDepth,RichEdit
   SETSIZE w1,EndButtons+10,100,15,rcDepth,ScrollBar
   SETSIZE w1,1307,rcDepth+105,15,15,BottomButton
   SETSIZE w1,119,100,EndButtons-109,rcDepth,TextBlock1 
   SETSIZE w1,119,100,EndButtons-109,rcDepth,TextBlock2
   SETSIZE w1,119,100,EndButtons-109,rcDepth,TextBlock3
   SETSIZE w1,119,100,EndButtons-109,rcDepth,TextBlock4
   SENDMESSAGE(rHandle,EM_SETTABSTOPS,1,&Tabss)

   InitialLoad = 1
   Scrolling = 1

   'Create and show tool tips
   IF ToolTips = 1

       'Create the individual tool tips
       ToolTipsTotal = 69

		 for a = 1 to ToolTipsTotal
			  if !hwndTooltip[a]
		        hwndTooltip[a] = TOOLTIPCONTROL(w1,@TTS_ALWAYSTIP|@TTS_NOANIMATE|@TTS_NOFADE|@TTS_BALLOON,0)
			  endif
		 next a

		 TTADDTOOL hwndTooltip[1], @TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,DebugCheck),w1.hWnd,"Show line and debug information"
		 TTADDTOOL hwndToolTip[2], @TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CloseButton),w1.hWnd,"Close this file"
		 TTADDTOOL hwndToolTip[3], @TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,NewButton),w1.hWnd,"New file"
		 TTADDTOOL hwndToolTip[4], @TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,SaveButton),w1.hWnd,"Save file"
		 TTADDTOOL hwndToolTip[5], @TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,OpenButton),w1.hWnd,"Open file"
		 TTADDTOOL hwndToolTip[6], @TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,SaveAsButton),w1.hWnd,"Save file as..."
		 TTADDTOOL hwndToolTip[7], @TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BackupButton),w1.hWnd,"Backup file"
		 TTADDTOOL hwndToolTip[8], @TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CogButton),w1.hWnd,"Re-index file"
		 TTADDTOOL hwndToolTip[9], @TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BinButton),w1.hWnd,"Clear undo and redo"
		 TTADDTOOL hwndToolTip[10],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ColourButton),w1.hWnd,"Re-colour screen"
		 TTADDTOOL hwndToolTip[11],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,AutoButton),w1.hWnd,"Turn auto complete of key words on or off"
		 TTADDTOOL hwndToolTip[12],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ConstantsButton),w1.hWnd,"Search WinAPI 32 Messages, Notifications, etc"
		 TTADDTOOL hwndToolTip[13],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowCode),w1.hWnd,"Show main code"
		 TTADDTOOL hwndToolTip[14],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowBlock1),w1.hWnd,"Show block 1 code"
		 TTADDTOOL hwndToolTip[15],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowBlock2),w1.hWnd,"Show block 2 code"
		 TTADDTOOL hwndToolTip[16],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowBlock3),w1.hWnd,"Show block 3 code"
		 TTADDTOOL hwndToolTip[17],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowBlock4),w1.hWnd,"Show block 4 code"
		 TTADDTOOL hwndToolTip[18],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CopyBlockButton),w1.hWnd,"Copy block code to clipboard"
		 TTADDTOOL hwndToolTip[19],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,DeleteBlockButton),w1.hWnd,"Clear code from block"

		 'Subroutines
		 TTADDTOOL hwndToolTip[20],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BUTTON_4),w1.hWnd,"Go to this line"
		 TTADDTOOL hwndToolTip[21],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BUTTON_44),w1.hWnd,"Go to this line"
		 TTADDTOOL hwndToolTip[22],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,SubJump),w1.hWnd,"Go to this subroutine"
		 TTADDTOOL hwndToolTip[23],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,EndSubb),w1.hWnd,"Go to subroutine end"
		 TTADDTOOL hwndToolTip[24],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,SubSearchButton),w1.hWnd,"Search subroutines"
		 TTADDTOOL hwndToolTip[25],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CopySubButton),w1.hWnd,"Copy subroutine to clipboard"
		 TTADDTOOL hwndToolTip[26],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CopySubBlockButton),w1.hWnd,"Copy subroutine to a block"
		 TTADDTOOL hwndToolTip[27],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,MoveSubButton),w1.hWnd,"Move subroutine to clicked position"
		 TTADDTOOL hwndToolTip[28],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,DeleteSubButton),w1.hWnd,"Delete subroutine"
		 TTADDTOOL hwndToolTip[29],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowSubButton),w1.hWnd,"Subroutine multi-select option"
		 TTADDTOOL hwndToolTip[30],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ClearSubs),w1.hWnd,"Clear subroutine selection"

		 'Windows
		 TTADDTOOL hwndToolTip[31],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,WinJump),w1.hWnd,"Go to this window / dialog"
		 TTADDTOOL hwndToolTip[32],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,EndWin),w1.hWnd,"Go to end of window / dialog"
		 TTADDTOOL hwndToolTip[33],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,WinHandler),w1.hWnd,"Go to handler"
		 TTADDTOOL hwndToolTip[34],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CopyWinButton),w1.hWnd,"Copy window to clipboard"
		 TTADDTOOL hwndToolTip[35],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CopyWinBlockButton),w1.hWnd,"Copy window to a block"
		 TTADDTOOL hwndToolTip[36],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,MoveWinButton),w1.hWnd,"Move window to clicked position"
		 TTADDTOOL hwndToolTip[37],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,DeleteWinButton),w1.hWnd,"Delete window"
		 TTADDTOOL hwndToolTip[38],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowWindowButton),w1.hWnd,"Window multi-select option"
		 TTADDTOOL hwndToolTip[39],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ClearWins),w1.hWnd,"Clear window selection"

		 'Bookmarks
		 TTADDTOOL hwndToolTip[40],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BookJump),w1.hWnd,"Go to this bookmark"
		 TTADDTOOL hwndToolTip[41],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BookAdd),w1.hWnd,"Add to bookmarks"
		 TTADDTOOL hwndToolTip[42],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BookDel),w1.hWnd,"Remove bookmark"
		 TTADDTOOL hwndToolTip[43],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BookDelAll),w1.hWnd,"Clear bookmarks"
		 TTADDTOOL hwndToolTip[44],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowBookmarksButton),w1.hWnd,"Bookmark multi-select"
 
		 'Checks
		 TTADDTOOL hwndToolTip[45],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CoorCheck),w1.hWnd,"Show the edit position etc"

		 'Navigarion
		 TTADDTOOL hwndToolTip[46],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,NavBackButton),w1.hWnd,"Go back"
		 TTADDTOOL hwndToolTip[47],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,NavForwardButton),w1.hWnd,"Go forward"
		 TTADDTOOL hwndToolTip[48],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,NavButton),w1.hWnd,"Add location to my places"
		 TTADDTOOL hwndToolTip[49],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,NavDeleteButton),w1.hWnd,"Remove location from my places"

		 'AutoJump
		 TTADDTOOL hwndToolTip[50],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,Check1),w1.hWnd,"Automatically jump to a selection"

		 'Searches
		 TTADDTOOL hwndToolTip[51],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,KeyFind),w1.hWnd,"Seach for in the current file"
		 TTADDTOOL hwndToolTip[52],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,KeyDelete),w1.hWnd,"Clear key word search"
		 TTADDTOOL hwndToolTip[53],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodeWordSearch),w1.hWnd,"Search for specific words"
		 TTADDTOOL hwndToolTip[54],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodeWordDelete),w1.hWnd,"Clear search words"
		 TTADDTOOL hwndToolTip[55],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodeWordAnd),w1.hWnd,"Line must have all these words"
		 TTADDTOOL hwndToolTip[56],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodeWordOr),w1.hWnd,"Line can have any of these words"
		 TTADDTOOL hwndToolTip[57],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodePhrase),w1.hWnd,"Search for a specific phrase, example - IF a = 1"
		 TTADDTOOL hwndToolTip[58],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodePhraseExact),w1.hWnd,"Search for in each line (not just an exact match)"
		 TTADDTOOL hwndToolTip[59],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodePhraseWords),w1.hWnd,"Search for specific words, example - IF THEN GOTO"
		 TTADDTOOL hwndToolTip[60],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodePhraseSearch),w1.hWnd,"Search and replace (optional)"
		 TTADDTOOL hwndToolTip[61],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,PhraseDeleteButton),w1.hWnd,"Clear find search"

		 'Top / Bottom
		 TTADDTOOL hwndToolTip[62],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,TopButton),w1.hWnd,"Go to the first line"
		 TTADDTOOL hwndToolTip[63],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BottomButton),w1.hWnd,"Go to the last line"

       'Controls
		 TTADDTOOL hwndToolTip[64],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CaseSearchButton),w1.hWnd,"Search and find controls"

       'Reload file
		 TTADDTOOL hwndToolTip[65],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ReLoadButton),w1.hWnd,"Reload this file"

		 TTADDTOOL hwndToolTip[66],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,RememberMe),w1.hWnd,"Add the current location to my places before jumping to subroutines, windows, lines etc"
		 TTADDTOOL hwndToolTip[67],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,NavDeleteAllButton),w1.hWnd,"Clear all of my places"
		 TTADDTOOL hwndToolTip[67],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,DupPlaces),w1.hWnd,"Allow duplicate places to be added even though I've been there before"
		 TTADDTOOL hwndToolTip[67],@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,HandyControls),w1.hWnd,"Search for controls and control case statements"
       'Set the font for the tool tips
		 for a = 1 to ToolTipsTotal
			  if hwndTooltip[a]
				  SendMessage(hwndTooltip[a],WM_SETFONT,hfont,0)
			  endif
		 next a
   ENDIF

RETURN
ENDSUB

SUB GetLineSpace()
	 WINDOW wx
	 STRING This$ = " Opening files" + CHR$(32) + CHR$(10) + "Please wait..." + CHR$(32) + CHR$(10) + CHR$(0) 
	 OPENWINDOW wx,0,0,800,600,@MINBOX|@MAXBOX|@SIZE|@CAPTION,0,"Window",&handlerX
	 CONTROL wx,@RICHEDIT,This$,7,35,570,294,0x50B010C4,1
		SETFONT wx,FontName,FontSize,500,0,1
		SETCONTROLCOLOR wx,1,RGB(0,0,0),RGB(255,255,255)
		INT xHandle = GETCONTROLHANDLE(wx,1)

	 'Line space
	 SENDMESSAGE(xHandle,EM_SETSEL,0,0)
	 SETFOCUS wx,1
	 INT ppos,AcrossX,DownY,Offset
	 ppos = GETCARETPOSITION wx,AcrossX,DownY
	 INT StoreFL = DownY

	 Offset = SENDMESSAGE(xHandle,EM_LINEINDEX,1,0)
	 SENDMESSAGE(xHandle,EM_SETSEL,Offset,Offset)
	 SETFOCUS wx,1

	 ppos = GETCARETPOSITION wx,AcrossX,DownY
	 LineSpace = DownY - StoreFL
	 LinesPerPage = (485 /(DownY - StoreFL)-1)
	 rcDepth = (LinesPerPage * LineSpace) + (LineSpace + 5)

	 'Space spacing
	 SENDMESSAGE(xHandle,EM_SETSEL,0,0)
	 SETFOCUS wx,1
	 ppos = GETCARETPOSITION wx,AcrossX,DownY
	 StoreFL = AcrossX

	 SENDMESSAGE(xHandle,EM_SETSEL,1,1)
	 SETFOCUS wx,1

	 ppos = GETCARETPOSITION wx,AcrossX,DownY
	 SpaceSpacing = AcrossX - StoreFL

	 CLOSEWINDOW wx
RETURN DownY - StoreFL
ENDSUB

SUB handlerX(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW wx
    ENDSELECT
RETURN 0
ENDSUB

SUB EditorSettings()
INT size = 0
INT weight = 0
INT flags = 0
INT col = 0
SaveNewDefaults = -1
IF Spelling = 0 THEN SpellWord = "color"
IF Spelling = 1 THEN SpellWord = "colour"

OPENWINDOW w20,0,0,637,720,@MINBOX|@MAXBOX|@SIZE|@CAPTION,0,"Editor settings",&SettingsHandler
   FLOODFILL w20,0,0,RGB(255,255,255)

   CONTROL w20,@CHECKBOX,"Use the spelling ' Colour '",20,5,220,25,@CTEDITLEFT,36
           SETFONT w20,"Arial",12,500,0,36
           SETCONTROLCOLOR w20,36,RGB(0,0,0),RGB(255,255,255)

   CONTROL w20,@CHECKBOX,"Use the spelling ' Color '",250,5,220,25,@CTEDITLEFT,37
           SETFONT w20,"Arial",12,500,0,37
           SETCONTROLCOLOR w20,37,RGB(0,0,0),RGB(255,255,255)

			  IF Spelling = 1 THEN SETSTATE w20,36,1
			  IF Spelling = 0 THEN SETSTATE w20,37,1

   CONTROL w20,@STATIC,"Font name",160,35,100,25,@CTEDITLEFT,1
   CONTROL w20,@STATIC,"Font size",160,60,100,25,@CTEDITLEFT,2
   CONTROL w20,@STATIC,"",260,35,300,25,@CTEDITLEFT,3
           SETCONTROLTEXT(w20,3,FontName)

   CONTROL w20,@STATIC,"",260,60,50,25,@CTEDITLEFT,4
           SETCONTROLTEXT(w20,4,LTRIM$(STR$(FontSize)))

   CONTROL w20,@BUTTON,"Change font",20,35,120,25,0,5

   CONTROL w20,@STATIC,"Key words",20,87,100,25,@CTEDITLEFT,6
   CONTROL w20,@RADIOBUTTON,"Uppercase",130,87,100,25,@CTEDITLEFT,7
   CONTROL w20,@RADIOBUTTON,"Lowercase",250,87,100,25,@CTEDITLEFT,8
   CONTROL w20,@RADIOBUTTON,"As typed",370,87,100,25,@CTEDITLEFT,9
			  IF Ucase = 1 THEN SETSTATE w20,7,1
			  IF Ucase = 2 THEN SETSTATE w20,8,1
			  IF Ucase = 3 THEN SETSTATE w20,9,1

   CONTROL w20,@STATIC,"Text background " + SpellWord,50,115,160,25,@CTEDITLEFT|SS_NOTIFY,10
   CONTROL w20,@BUTTON,"",15,115,20,20,@CTEDITLEFT,210
           SETCONTROLCOLOR w20,210,RGB(0,0,0),ScreenColour

   CONTROL w20,@STATIC,"Text " + SpellWord,332,115,160,25,@CTEDITLEFT|SS_NOTIFY,40
           SETFONT w20,"Arial",12,500,0,40
           SETCONTROLCOLOR w20,40,RGB(0,0,0),RGB(255,255,255)

   CONTROL w20,@BUTTON,"",300,115,20,20,@CTEDITLEFT,222
           SETCONTROLCOLOR w20,222,RGB(0,0,0),TextColour

   CONTROL w20,@STATIC,"Window background " + SpellWord,50,140,200,25,@CTEDITLEFT|SS_NOTIFY,11
   CONTROL w20,@BUTTON,"",15,140,20,20,@CTEDITLEFT,211
           SETCONTROLCOLOR w20,211,RGB(0,0,0),WindowBackColour

   CONTROL w20,@CHECKBOX,"Auto jump to selections",20,165,180,25,@CTEDITLEFT,12
           IF AutoJumpTo = 1 THEN SETSTATE w20,12,1

   CONTROL w20,@CHECKBOX,"Show confirmation messages",20,190,240,25,@CTEDITLEFT,13
           IF ConfirmMessage = 1 THEN SETSTATE w20,13,1

   CONTROL w20,@CHECKBOX,"Save file when closing",20,215,240,25,@CTEDITLEFT,14
           SETSTATE w20,14,AutoSaveOnClose

   CONTROL w20,@CHECKBOX,"Save files when closing editor",20,240,240,25,@CTEDITLEFT,15
           SETSTATE w20,15,AutoSaveOnExit

   CONTROL w20,@STATIC,"Number of lines to scroll using mouse wheel",20,265,310,25,@CTEDITLEFT,16
   CONTROL w20,@EDIT,"",340,265,30,25,@CTEDITLEFT|@CTEDITNUMBER,17
           SETCONTROLTEXT(w20,17,LTRIM$(STR$(WheelScrollLines)))

   CONTROL w20,@CHECKBOX,"Show tooltips",20,287,240,25,@CTEDITLEFT,18
           IF ToolTips = 1 THEN SETSTATE w20,18,1

   CONTROL w20,@STATIC,"Tab spacing",20,315,90,25,@CTEDITLEFT,19
   CONTROL w20,@EDIT,"",120,315,30,25,@CTEDITLEFT|@CTEDITNUMBER,20
           SETCONTROLTEXT(w20,20,LTRIM$(STR$(TabSpacing)))

   CONTROL w20,@CHECKBOX,"Auto complete key words",20,340,240,25,@CTEDITLEFT,21
           SETSTATE w20,21,AutoCompleteKeyWords

   CONTROL w20,@STATIC,"Round bracket " + SpellWord,50,365,200,25,@CTEDITLEFT|SS_NOTIFY,22
   CONTROL w20,@BUTTON,"",15,365,20,20,@CTEDITLEFT,212
           SETCONTROLCOLOR w20,212,RGB(0,0,0),RoundBrackets

   CONTROL w20,@STATIC,"Square bracket " + SpellWord,50,390,200,25,@CTEDITLEFT|SS_NOTIFY,23
   CONTROL w20,@BUTTON,"",15,390,20,20,@CTEDITLEFT,213
           SETCONTROLCOLOR w20,213,RGB(0,0,0),SquareBrackets

   CONTROL w20,@STATIC,"Local subroutine " + SpellWord,50,415,200,25,@CTEDITLEFT|SS_NOTIFY,24
   CONTROL w20,@BUTTON,"",15,415,20,20,@CTEDITLEFT,214
           SETCONTROLCOLOR w20,214,RGB(0,0,0),LocalSubColour

   CONTROL w20,@STATIC,"Local window " + SpellWord,50,440,200,25,@CTEDITLEFT|SS_NOTIFY,51
           SETFONT w20,"Arial",12,500,0,51
           SETCONTROLCOLOR w20,51,RGB(0,0,0),RGB(255,255,255)
   CONTROL w20,@BUTTON,"",15,440,20,20,@CTEDITLEFT,224
           SETCONTROLCOLOR w20,224,RGB(0,0,0),LocalWinColour

   CONTROL w20,@CHECKBOX,"Program debug",305,465,240,25,@CTEDITLEFT,25
           SETSTATE w20,25,DebugOn

   CONTROL w20,@CHECKBOX,"Show edit coordinates",20,465,240,25,@CTEDITLEFT,26
           SETSTATE w20,26,CoOn

   CONTROL w20,@CHECKBOX,"Close subroutine search window when a selection is made",20,490,450,25,@CTEDITLEFT,27
           SETSTATE w20,27,SearchCheckV 

   CONTROL w20,@STATIC,"Constants " + SpellWord,50,515,200,25,@CTEDITLEFT|SS_NOTIFY,28
   CONTROL w20,@BUTTON,"",15,515,20,20,@CTEDITLEFT,215
           SETCONTROLCOLOR w20,215,RGB(0,0,0),KeyWordColourAt

   CONTROL w20,@STATIC,"Definition " + SpellWord,50,540,200,25,@CTEDITLEFT|SS_NOTIFY,29
   CONTROL w20,@BUTTON,"",15,540,20,20,@CTEDITLEFT,216
           SETCONTROLCOLOR w20,216,RGB(0,0,0),KeyWordColourVariables

   CONTROL w20,@STATIC,"Preprocessor ($) " + SpellWord,50,565,250,25,@CTEDITLEFT|SS_NOTIFY,30
   CONTROL w20,@BUTTON,"",15,565,20,20,@CTEDITLEFT,217
           SETCONTROLCOLOR w20,217,RGB(0,0,0),KeyWordColourDollar

   CONTROL w20,@STATIC,"Key word " + SpellWord,332,515,200,25,@CTEDITLEFT|SS_NOTIFY,31
   CONTROL w20,@BUTTON,"",300,515,20,20,@CTEDITLEFT,218
           SETCONTROLCOLOR w20,218,RGB(0,0,0),KeyWordColourAtoZ

   CONTROL w20,@STATIC,"Assembly " + SpellWord,332,540,200,25,@CTEDITLEFT|SS_NOTIFY,32
   CONTROL w20,@BUTTON,"",300,540,20,20,@CTEDITLEFT,219
           SETCONTROLCOLOR w20,219,RGB(0,0,0),KeyWordColourOther

   CONTROL w20,@STATIC,"Comment " + SpellWord,332,365,200,25,@CTEDITLEFT|SS_NOTIFY,38
           SETFONT w20,"Arial",12,500,0,38
           SETCONTROLCOLOR w20,38,RGB(0,0,0),RGB(255,255,255)
   CONTROL w20,@BUTTON,"",300,365,20,20,@CTEDITLEFT,220
           SETCONTROLCOLOR w20,220,RGB(0,0,0),CommentColour

   CONTROL w20,@STATIC,"Quotation " + SpellWord,332,390,200,25,@CTEDITLEFT|SS_NOTIFY,39
           SETFONT w20,"Arial",12,500,0,39
           SETCONTROLCOLOR w20,39,RGB(0,0,0),RGB(255,255,255)
   CONTROL w20,@BUTTON,"",300,390,20,20,@CTEDITLEFT,221
           SETCONTROLCOLOR w20,221,RGB(0,0,0),QuotesColour

   CONTROL w20,@STATIC,"Number " + SpellWord,332,415,200,25,@CTEDITLEFT|SS_NOTIFY,50
           SETFONT w20,"Arial",12,500,0,50
           SETCONTROLCOLOR w20,50,RGB(0,0,0),RGB(255,255,255)
   CONTROL w20,@BUTTON,"",300,415,20,20,@CTEDITLEFT,223
           SETCONTROLCOLOR w20,223,RGB(0,0,0),ColourNumbers

   CONTROL w20,@CHECKBOX,"Remember places",20,590,185,25,@CTEDITLEFT,65
           SETFONT w20,"Arial",12,500,0,65
           SETCONTROLCOLOR w20,65,RGB(0,0,0),RGB(255,255,255)
           SETSTATE w20,65,RememberV

   CONTROL w20,@CHECKBOX,"Allow duplicate places",230,590,220,25,@CTEDITLEFT,66
           SETFONT w20,"Arial",12,500,0,66
           SETCONTROLCOLOR w20,66,RGB(0,0,0),RGB(255,255,255)
           SETSTATE w20,66,DupPlacesV

   CONTROL w20,@CHECKBOX,"Find First",20,620,85,25,@CTEDITLEFT,60
           SETFONT w20,"Arial",12,500,0,60
           SETCONTROLCOLOR w20,60,RGB(0,0,0),RGB(255,255,255)
           SETSTATE w20,60,FindFirstV

   CONTROL w20,@CHECKBOX,"Find All",132,620,85,25,@CTEDITLEFT,61
           SETFONT w20,"Arial",12,500,0,61
           SETCONTROLCOLOR w20,61,RGB(0,0,0),RGB(255,255,255)
           SETSTATE w20,61,FindAllV

   CONTROL w20,@CHECKBOX,"Find Last",230,620,85,25,@CTEDITLEFT,62
           SETFONT w20,"Arial",12,500,0,62
           SETCONTROLCOLOR w20,62,RGB(0,0,0),RGB(255,255,255)
           SETSTATE w20,62,FindLastV

   CONTROL w20,@CHECKBOX,"And",385,620,65,25,@CTEDITLEFT,63
           SETFONT w20,"Arial",12,500,0,63
           SETCONTROLCOLOR w20,63,RGB(0,0,0),RGB(255,255,255)
           SETSTATE w20,63,AndV

   CONTROL w20,@CHECKBOX,"Or",450,620,85,25,@CTEDITLEFT,64
           SETFONT w20,"Arial",12,500,0,64
           SETCONTROLCOLOR w20,64,RGB(0,0,0),RGB(255,255,255)
           SETSTATE w20,64,OrV

   CONTROL w20,@BUTTON,"Save",20,650,100,25,@CTEDITLEFT,33
           SETFONT w20,"Arial",12,500,0,33
           SETCONTROLCOLOR w20,33,RGB(0,0,0),RGB(255,255,255)

   CONTROL w20,@BUTTON,"Defaults",260,650,100,25,@CTEDITLEFT,70
           SETFONT w20,"Arial",12,500,0,70
           SETCONTROLCOLOR w20,70,RGB(0,0,0),RGB(255,255,255)

   CONTROL w20,@BUTTON,"Cancel",500,650,100,25,@CTEDITLEFT,35
           SETFONT w20,"Arial",12,500,0,35
           SETCONTROLCOLOR w20,35,RGB(0,0,0),RGB(255,255,255)

	FOR a = 1 TO 32
		 SETFONT w20,"Arial",12,500,0,a
		 'if a <> 5
		 SETCONTROLCOLOR w20,a,RGB(0,0,0),RGB(255,255,255)
		 'endif
	NEXT a

WAITUNTIL ISWINDOWCLOSED(w20)
SaveNewDefaults = -1
RETURN
ENDSUB

SUB SettingsHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w20

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w20

           CASE @IDCONTROL
                SELECT @CONTROLID
                       CASE 21 'AutoComplete
                            IF @NOTIFYCODE = 0
                               AutoCompleteKeyWords = 1 - AutoCompleteKeyWords 
                            ENDIF 

                       CASE 33 'Save
                            IF @NOTIFYCODE = 0
										 SaveNewDefaults = 0
										 SetKeyWordColours()
										 IF NewFontName <> ""
											 FontName = NewFontName
										 ENDIF
										 IF size
											 FontSize = size
										 ENDIF
										 SETFONT w1,FontName,FontSize,400,0,RichEdit

										 IF GETSTATE(w20,7)
											Ucase = 1
										 ENDIF
										 IF GETSTATE(w20,8)
											Ucase = 2
										 ENDIF
										 IF GETSTATE(w20,9)
											Ucase = 3
										 ENDIF

										 IF GETSTATE(w20,12) = 1
											AutoJumpTo = 1
											NoJumpRV = 1
										 ELSE
											AutoJumpTo = 0
											NoJumpRV = 0
										 ENDIF

										 IF GETSTATE(w20,13) = 1
											 ConfirmMessage = 1
										 ELSE
											 ConfirmMessage = 0
										 ENDIF

										 IF GETSTATE(w20,14) = 1
											 AutoSaveOnClose = 1
										 ELSE
											 AutoSaveOnClose = 0
										 ENDIF

										 IF GETSTATE(w20,15) = 1
											 AutoSaveOnExit = 1
										 ELSE
											 AutoSaveOnExit = 0
										 ENDIF

										 WheelScrollLines = VAL(GETCONTROLTEXT(w20,17))

										 IF GETSTATE(w20,18) = 1
											 ToolTips = 1
											 for a = 1 to ToolTipsTotal
												  SENDMESSAGE(hwndTooltip[a],TTM_ACTIVATE,1,0)
											 next a
										 ELSE
											 ToolTips = 0
											 for a = 1 to ToolTipsTotal
												  SENDMESSAGE(hwndTooltip[a],TTM_ACTIVATE,0,0)
											 next a
										 ENDIF

										 TabSpacing = VAL(GETCONTROLTEXT(w20,20))

										 IF GETSTATE(w20,25) = 1
											 DebugOn = 1
											 showwindow w1,@SWSHOW,Debug1
											 showwindow w1,@SWSHOW,Debug2
											 showwindow w1,@SWSHOW,Debug3
											 setstate w1,DebugCheck,1
										 ELSE
											 DebugOn = 0
											 showwindow w1,@SWHIDE,Debug1
											 showwindow w1,@SWHIDE,Debug2
											 showwindow w1,@SWHIDE,Debug3
											 setstate w1,DebugCheck,0

										 ENDIF

										 IF GETSTATE(w20,26) = 1
											 CoOn = 1
											 showwindow w1,@SWSHOW,PosEdit
											 showwindow w1,@SWSHOW,CharPosEdit
											 showwindow w1,@SWSHOW,PosStatic
											 showwindow w1,@SWSHOW,CharPosStatic
											 setstate w1,CoorCheck,1
										 ELSE
											 CoOn = 0
											 showwindow w1,@SWHIDE,PosEdit
											 showwindow w1,@SWHIDE,CharPosEdit
											 showwindow w1,@SWHIDE,PosStatic
											 showwindow w1,@SWHIDE,CharPosStatic
											 setstate w1,CoorCheck,0
										 ENDIF

										 IF GETSTATE(w20,27) = 1
											 SearchCheckV = 1
										 ELSE
											 SearchCheckV = 0
										 ENDIF
                               SaveUserDefaults()
                               SENDMESSAGE w1,EM_SETBKGNDCOLOR,0,ScreenColour,RichEdit
                               CLOSEWINDOW w20
                               RETURN 0
                            ENDIF

                       CASE 70 'Defaults
                            IF @NOTIFYCODE = 0
										 DELETEFILE GETSTARTPATH + "\\Res\\"+ "xeditor4Defaults.ini"
										 sleep(200)
										 INT Cpy = 0
										 COPYFILE GETSTARTPATH + "\\Res\\"+ "xeditor4DefaultsBackup.ini",GETSTARTPATH + "\\Res\\"+ "xeditor4Defaults.ini",Cpy
										 Load_Defaults()
										 GetLineSpace()
										 SetKeyWordColours()
										 for a = 1 to ToolTipsTotal
											  SENDMESSAGE(hwndTooltip[a],TTM_ACTIVATE,1,0)
										 next a
                               SENDMESSAGE w1,EM_SETBKGNDCOLOR,0,ScreenColour,RichEdit
                               CLOSEWINDOW w20
                               RETURN 0
                            ENDIF

                       CASE 35 'Cancel
                            IF @NOTIFYCODE = 0
                               SaveNewDefaults = -1
                               CLOSEWINDOW w20
                               RETURN 0
                            ENDIF

                       CASE 60 'Find First
                            IF @NOTIFYCODE = 0
                               if getstate(w20,60)
                                  setstate(w20,61,0)
                                  setstate(w20,62,0)
                                  setstate(w1,FindFirst,1)
                                  FindFirstV = 1
                                  FindAllV   = 0
                                  FindLastV  = 0
                                  setfocus w20
                               endif
                            endif

                       CASE 61 'Find All
                            IF @NOTIFYCODE = 0
                               if getstate(w20,61)
                                  setstate(w20,60,0)
                                  setstate(w20,62,0)
                                  setstate(w1,FindAll,1)
                                  FindFirstV = 0
                                  FindAllV   = 1
                                  FindLastV  = 0
                                  setfocus w20
                               endif
                            endif

                       CASE 62 'Find Last
                            IF @NOTIFYCODE = 0
                               if getstate(w20,62)
                                  setstate(w20,60,0)
                                  setstate(w20,61,0)
                                  setstate(w1,FindLast,1)
                                  FindFirstV = 0
                                  FindAllV   = 0
                                  FindLastV  = 1
                                  setfocus w20
                               endif
                            endif

                       CASE 63 'Find And
                            IF @NOTIFYCODE = 0
                               if getstate(w20,63)
                                  setstate(w20,64,0)
                                  setstate(w1,CodeWordAnd,1)
                                  setstate(w1,CodeWordOr,0)
                                  AndV = 1
                                  OrV  = 0
                                  setfocus w20
                               endif
                            endif

                       CASE 64 'Find Or
                            IF @NOTIFYCODE = 0
                               if getstate(w20,64)
                                  setstate(w20,63,0)
                                  setstate(w1,CodeWordOr,1)
                                  setstate(w1,CodeWordAnd,0)
                                  AndV = 0
                                  OrV  = 1
                                  setfocus w20
                               endif
                            endif

                       CASE 65 'Remember places
                            IF @NOTIFYCODE = 0
                               if getstate(w20,65) = 1 
                                  RememberV = 1
                                  setstate(w1,RememberMe,1)
                               endif
                               if getstate(w20,65) = 0 
                                  RememberV = 0
                                  setstate(w1,RememberMe,0)
                               endif
                               setfocus w20
                            endif

                       CASE 66 'Duplicate places
                            IF @NOTIFYCODE = 0
                               if getstate(w20,66) = 1 
                                  DupPlacesV = 1
                                  setstate(w1,DupPlaces,1)
                               endif
                               if getstate(w20,66) = 0 
                                  DupPlacesV = 0
                                  setstate(w1,DupPlaces,0)
                               endif
                               setfocus w20
                            endif

                       CASE 36 'Colour
                            IF @NOTIFYCODE = 0
                               IF GETSTATE(w20,36) = 0 
                                  SETSTATE(w20,37,1)
											 SpellWord = "color"
                                  SetSpelling()
                                  SETFOCUS w20
                                  RETURN 0
                               ENDIF
                               IF GETSTATE(w20,36) = 1
                                  SETSTATE(w20,37,0)
											 SpellWord = "colour"
                                  SetSpelling()
                                  SETFOCUS w20
                                  RETURN 0
                               ENDIF
                            ENDIF

                       CASE 12
                            IF @NOTIFYCODE = 0
                               SETFOCUS w20  
                            ENDIF 
                       CASE 13
                            IF @NOTIFYCODE = 0
                               SETFOCUS w20  
                            ENDIF   
                       CASE 14
                            IF @NOTIFYCODE = 0
                               SETFOCUS w20  
                            ENDIF 
                       CASE 15
                            IF @NOTIFYCODE = 0
                               SETFOCUS w20  
                            ENDIF 
                       CASE 18
                            IF @NOTIFYCODE = 0
                               SETFOCUS w20  
                            ENDIF 
                       CASE 21
                            IF @NOTIFYCODE = 0
                               SETFOCUS w20  
                            ENDIF 
                       CASE 25
                            IF @NOTIFYCODE = 0
                               SETFOCUS w20  
                            ENDIF 
                       CASE 26     
                            IF @NOTIFYCODE = 0
                               SETFOCUS w20  
                            ENDIF  

                       CASE 37 'Color
                            IF @NOTIFYCODE = 0
                               IF GETSTATE(w20,37) = 0 
                                  SETSTATE(w20,36,1)
											 SpellWord = "colour"
											 SETCONTROLTEXT(w20,10,"Text background " + SpellWord)
                                  SetSpelling()
                                  SETFOCUS w20
                                  RETURN 0
                               ENDIF
                               IF GETSTATE(w20,37) = 1
											 SpellWord = "color"
                                  SetSpelling()
                                  SETSTATE(w20,36,0)
                                  SETFOCUS w20
                                  RETURN 0
                               ENDIF
                            ENDIF

                       CASE  10
                       CASE& 210
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               STRING TheColour = DectoRGB(ScreenColour)
										 DefaultSet = 210
                               ColourPicker(TheColour,"Text background " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  ScreenColour = NewColour 
                                  SETCONTROLCOLOR w20,210,RGB(0,0,0),ScreenColour
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE  11
                       CASE& 211
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(WindowBackColour)
										 DefaultSet = 211
                               ColourPicker(TheColour,"Window background " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  WindowBackColour = NewColour 
                                  SETCONTROLCOLOR w20,211,RGB(0,0,0),WindowBackColour
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE  22  
                       CASE& 212
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(RoundBrackets)
										 DefaultSet = 212
                               ColourPicker(TheColour,"Round bracket " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  RoundBrackets = NewColour 
                                  SETCONTROLCOLOR w20,212,RGB(0,0,0),RoundBrackets
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE  23
                       CASE& 213
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(SquareBrackets)
										 DefaultSet = 213
                               ColourPicker(TheColour,"Square bracket " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  SquareBrackets = NewColour 
                                  SETCONTROLCOLOR w20,213,RGB(0,0,0),SquareBrackets
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE  24
                       CASE& 214
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(LocalSubColour)
										 DefaultSet = 214
                               ColourPicker(TheColour,"Local subroutine " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  LocalSubColour = NewColour 
                                  SETCONTROLCOLOR w20,214,RGB(0,0,0),LocalSubColour
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE  28 
                       CASE& 215
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(KeyWordColourAt)
                               DefaultSet = 215
                               ColourPicker(TheColour,"Constants " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  KeyWordColourAt = NewColour 
                                  SETCONTROLCOLOR w20,215,RGB(0,0,0),KeyWordColourAt
                               ENDIF 
                               DefaultSet = 0
                            ENDIF

                       CASE  29 
                       CASE& 216
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(KeyWordColourVariables)
										 DefaultSet = 216
                               ColourPicker(TheColour,"Definition " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  KeyWordColourVariables = NewColour 
                                  SETCONTROLCOLOR w20,216,RGB(0,0,0),KeyWordColourVariables
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE  30 
                       CASE& 217
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(KeyWordColourDollar)
                               DefaultSet = 217
                               ColourPicker(TheColour,"Preprocessor ($) key word " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  KeyWordColourDollar = NewColour 
                                  SETCONTROLCOLOR w20,217,RGB(0,0,0),KeyWordColourDollar
                               ENDIF
                               DefaultSet = 0 
                            ENDIF

                       CASE  31
                       CASE& 218
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(KeyWordColourAtoZ)
										 DefaultSet = 218
                               ColourPicker(TheColour,"Key word " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  KeyWordColourAtoZ = NewColour 
                                  SETCONTROLCOLOR w20,218,RGB(0,0,0),KeyWordColourAtoZ
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE  32
                       CASE& 219
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(KeyWordColourOther)
										 DefaultSet = 219
                               ColourPicker(TheColour)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  KeyWordColourOther = NewColour 
                                  SETCONTROLCOLOR w20,219,RGB(0,0,0),KeyWordColourOther
                               ENDIF 
										 DefaultSet = 0 
                            ENDIF

                       CASE  38
                       CASE& 220
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(CommentColour)
										 DefaultSet = 220
                               ColourPicker(TheColour,"Comment " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  CommentColour = NewColour 
                                  SETCONTROLCOLOR w20,220,RGB(0,0,0),CommentColour
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE  39
                       CASE& 221
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(QuotesColour)
										 DefaultSet = 221
                               ColourPicker(TheColour,"Quotation " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  QuotesColour = NewColour 
                                  SETCONTROLCOLOR w20,221,RGB(0,0,0),QuotesColour
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE  40
                       CASE& 222
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(TextColour)
										 DefaultSet = 222
                               ColourPicker(TheColour,"Text " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  TextColour = NewColour 
                                  SETCONTROLCOLOR w20,222,RGB(0,0,0),TextColour
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE  50
                       CASE& 223
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(ColourNumbers)
										 DefaultSet = 223
                               ColourPicker(TheColour,"Numbers " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  ColourNumbers = NewColour 
                                  SETCONTROLCOLOR w20,223,RGB(0,0,0),ColourNumbers
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE  51
                       CASE& 224
                            IF @NOTIFYCODE = 0
                               SHOWWINDOW w20,@SWHIDE 
                               TheColour = DectoRGB(LocalWinColour)
										 DefaultSet = 224
                               ColourPicker(TheColour,"Local window " + SpellWord)
                               SHOWWINDOW w20,@SWRESTORE
                               IF NewColour > -1
                                  LocalWinColour = NewColour 
                                  SETCONTROLCOLOR w20,224,RGB(0,0,0),LocalWinColour
                               ENDIF 
										 DefaultSet = 0
                            ENDIF

                       CASE 5
                            IF @NOTIFYCODE = 0
                               OldFontName = FontName
                               OldFontSize = FontSize
                               NewFontName = FONTREQUEST(w20,size,weight,flags,col)
                               IF NewFontName <> ""
                                  SETCONTROLTEXT(w20,3,NewFontName)
                                  SETCONTROLTEXT(w20,4,LTRIM$(STR$(size)))
                               ELSE
                                  SETCONTROLTEXT(w20,3,OldFontName)
                                  SETCONTROLTEXT(w20,4,LTRIM$(STR$(OldFontSize)))
                               ENDIF
                            ENDIF
    ENDSELECT
ENDSELECT
RETURN 0
ENDSUB
 
SUB ColourPicker(STRING TheColour,OPT STRING TitleIn)
NewColour = -1

OPENWINDOW w21,0,0,640,440,@MINBOX|@MAXBOX|@SIZE,0,"Please select your preference",&CHandler
	SHOWWINDOW w21, @SWHIDE
	FLOODFILL w21,1,1,RGB(0,0,50)
	SHOWWINDOW w21, @SWRESTORE

	bW = 80
	bH = 40

	bcr = 255
	bcg = 255
	bcb = 255
	bcolor = RGB(bcr,bcg,bcb)

	CONTROL w21,@BUTTON,"Cancel",496,360,70,25,0,1
           SETFONT w21,"Arial",12,400,0,1

	CONTROL w21,@BUTTON,"Default",260,360,70,25,0,100
           SETFONT w21,"Arial",12,400,0,100

	CONTROL w21,@STATIC,"My selection",260,60,305,25,@CTEDITCENTER|0x200,2
           SETFONT w21,"Arial",12,400,0,2
			  SETCONTROLCOLOR w21,2,RGB(255,255,255),RGB(255,255,255)

	CONTROL w21,@STATIC,TitleIn,260,15,305,25,@CTEDITLEFT|0x200,60
           SETFONT w21,"Arial",12,400,0,60
			  SETCONTROLCOLOR w21,60,RGB(255,255,255),RGB(0,0,50)

	CONTROL w21,@BUTTON,"Save",90,360,70,25,0,3
           SETFONT w21,"Arial",12,400,0,3

	CONTROL w21,@EDIT,"",63,315,35,25,@CTEDITCENTER|@TABSTOP,4
	CONTROL w21,@EDIT,"",108,315,35,25,@CTEDITCENTER|@TABSTOP,5
	CONTROL w21,@EDIT,"",152,315,35,25,@CTEDITCENTER|@TABSTOP,6
           ENABLETABS w21,1

	CONTROL w21,@SCROLLBAR,"",70,90,22,220,0x50000001,10
			  SETCONTROLCOLOR w21, 10,RGB(0,0,50), RGB(140,155,150)
	CONTROL w21,@SCROLLBAR,"",115,90,22,220,0x50000001,11
			  SETCONTROLCOLOR w21, 11,RGB(0,0,50), RGB(140,155,150)
	CONTROL w21,@SCROLLBAR,"",160,90,22,220,0x50000001,12
			  SETCONTROLCOLOR w21, 12,RGB(0,0,50), RGB(140,155,150)
	CONTROL w21,@STATIC,"R",68,60,25,22,@CTEDITCENTER,13
			  SETCONTROLCOLOR w21, 13,RGB(255,255,255),RGB(0,0,50)
	CONTROL w21,@STATIC,"G",113,60,25,22,@CTEDITCENTER,14
			  SETCONTROLCOLOR w21, 14,RGB(255,255,255),RGB(0,0,50)
	CONTROL w21,@STATIC,"B",157,60,25,22,@CTEDITCENTER,15
			  SETCONTROLCOLOR w21, 15,RGB(255,255,255),RGB(0,0,50)

	FOR i = 10 TO 12
		 SETSCROLLRANGE w21,i,0,255
	NEXT i

	' set initial scroll positions ...
	SETSCROLLPOS w21, 10, VAL(MID$(TheColour,1,3))
	SETSCROLLPOS w21, 11, VAL(MID$(TheColour,5,3))
	SETSCROLLPOS w21, 12, VAL(MID$(TheColour,9,3))

	' set initial edit box values ...
	SETCONTROLTEXT w21, 4, LTRIM$(STR$(VAL(MID$(TheColour,1,3))))
	SETCONTROLTEXT w21, 5, LTRIM$(STR$(VAL(MID$(TheColour,5,3))))
	SETCONTROLTEXT w21, 6, LTRIM$(STR$(VAL(MID$(TheColour,9,3))))

	'Row 1
	br[201] = 255 : bg[201] = 125 : bb[201] = 130
	br[202] = 255 : bg[202] = 255 : bb[202] = 115
	br[203] = 123 : bg[203] = 255 : bb[203] = 128 
	br[204] =   5 : bg[204] = 251 : bb[204] = 126
	br[205] = 134 : bg[205] = 251 : bb[205] = 255
	br[206] =   0 : bg[206] = 128 : bb[206] = 255
	br[207] = 255 : bg[207] = 122 : bb[207] = 188
	br[208] = 255 : bg[208] = 124 : bb[208] = 248

	'Row 2
	br[209] = 255 : bg[209] =   2 : bb[209] =   0 
	br[210] = 254 : bg[210] = 252 : bb[210] =  17 
	br[211] = 128 : bg[211] = 255 : bb[211] =   0 
	br[212] =  13 : bg[212] = 247 : bb[212] =  72
	br[213] =   1 : bg[213] = 253 : bb[213] = 255
	br[214] =   6 : bg[214] = 127 : bb[214] = 180
	br[215] = 125 : bg[215] = 128 : bb[215] = 197
	br[216] = 251 : bg[216] =  10 : bb[216] = 247

	'Row 3
	br[217] = 127 : bg[217] =  63 : bb[217] =  63   
	br[218] = 255 : bg[218] = 128 : bb[218] =  54
	br[219] =   1 : bg[219] = 255 : bb[219] =   6
	br[220] =   0 : bg[220] = 130 : bb[220] = 133
	br[221] =   0 : bg[221] =  64 : bb[221] = 139
	br[222] = 128 : bg[222] = 128 : bb[222] = 252
	br[223] = 133 : bg[223] =   0 : bb[223] =  67
	br[224] = 255 : bg[224] =   0 : bb[224] = 132

	'Row 4
	br[225] = 128 : bg[225] =   0 : bb[225] =   0 
	br[226] = 241 : bg[226] = 132 : bb[226] =  13
	br[227] =   3 : bg[227] = 125 : bb[227] =   4
	br[228] =   0 : bg[228] = 129 : bb[228] =  54
	br[229] =   2 : bg[229] =   0 : bb[229] = 252
	br[230] =   0 : bg[230] =   9 : bb[230] = 140
	br[231] = 126 : bg[231] =   1 : bb[231] = 121
	br[232] = 134 : bg[232] =   0 : bb[232] = 253

	'Row 5
	br[233] =  60 : bg[233] =   6 : bb[233] =   0
	br[234] = 139 : bg[234] =  60 : bb[234] =   0
	br[235] =   4 : bg[235] =  61 : bb[235] =   8
	br[236] =   1 : bg[236] =  58 : bb[236] =  69
	br[237] =   0 : bg[237] =   0 : bb[237] = 138
	br[238] =   0 : bg[238] =   0 : bb[238] =  69
	br[239] =  72 : bg[239] =   0 : bb[239] =  76
	br[240] =  65 : bg[240] =   0 : bb[240] = 130

	'Row 6
	br[241] =   0 : bg[241] =   0 : bb[241] =   0
	br[242] = 128 : bg[242] = 125 : bb[242] =  12
	br[243] = 129 : bg[243] = 130 : bb[243] =  62
	br[244] = 128 : bg[244] = 128 : bb[244] = 128
	br[245] =  63 : bg[245] = 129 : bb[245] = 128
	br[246] = 192 : bg[246] = 192 : bb[246] = 192
	br[247] =  60 : bg[247] =   1 : bb[247] =  65
	br[248] = 255 : bg[248] = 255 : bb[248] = 255

	INT Crtl = 200
	INT Down = 115
	FOR y = 1 TO 6
		 INT across = 260
		 FOR x = 1 TO 8
			  Crtl ++
			  CONTROL w21,@BUTTON,"",across,Down,25,25,0,Crtl
			  SETCONTROLCOLOR w21,Crtl,RGB(0,0,0),RGB(br[Crtl],bg[Crtl],bb[Crtl])
			  across += 40
		 NEXT x
		 Down += 40
	NEXT y
	DRAWMODE w21,@OPAQUE

WAITUNTIL ISWINDOWCLOSED(w21)
CLOSEWINDOW w21
RETURN
ENDSUB

SUB CHandler(),INT
SELECT @CLASS
CASE @IDCREATE
	  CENTERWINDOW w21

CASE @IDCLOSEWINDOW
     CLOSEWINDOW w21

case @IDCONTROL

   if @CONTROLID >=201 and @CONTROLID <= 248
      setcontroltext(w21,4,ltrim$(str$(br[@CONTROLID]))) 
      setcontroltext(w21,5,ltrim$(str$(bg[@CONTROLID]))) 
      setcontroltext(w21,6,ltrim$(str$(bb[@CONTROLID]))) 
   endif 

	select @CONTROLID
		case 1 'Cancel
			  closewindow w21

      case 100 'Default
           if DefaultSet
              select DefaultSet
                     case 210 'Text background colour
								  setcontroltext(w21,4,"211")
								  setcontroltext(w21,5,"211")
								  setcontroltext(w21,6,"211")

                     case 211 'Window colour
								  setcontroltext(w21,4,"231")
								  setcontroltext(w21,5,"222")
								  setcontroltext(w21,6,"231")

                     case 212 'Round brackets colour
								  setcontroltext(w21,4,"255")
								  setcontroltext(w21,5,"0")
								  setcontroltext(w21,6,"0")

                     case 213 'Square brackets colour
								  setcontroltext(w21,4,"128")
								  setcontroltext(w21,5,"0")
								  setcontroltext(w21,6,"0")

                     case 214 'Local subroutine colour
								  setcontroltext(w21,4,"128")
								  setcontroltext(w21,5,"0")
								  setcontroltext(w21,6,"0")

                     case 215 'Constant key words
 								  'KeyWordColourAt = Orange
								  'FOR a = 1 TO 805
								'	   #Attrib[a].Colour = KeyWordColourAt
								  'NEXT a
								  setcontroltext(w21,4,"255")
								  setcontroltext(w21,5,"140")
								  setcontroltext(w21,6,"0")

                     case 216 'Definition colour
 								  'KeyWordColourAt = Orange
								  'FOR a = 1 TO 805
								'	   #Attrib[a].Colour = KeyWordColourAt
								  'NEXT a
								  setcontroltext(w21,4,"255")
								  setcontroltext(w21,5,"0")
								  setcontroltext(w21,6,"0")

                     case 217 'Preprocessor colour
								  setcontroltext(w21,4,"105")
								  setcontroltext(w21,5,"105")
								  setcontroltext(w21,6,"105")

                     case 218 'Key word colour
								  setcontroltext(w21,4,"0")
								  setcontroltext(w21,5,"0")
								  setcontroltext(w21,6,"255")

                     case 219 'Other (Underscore) colour
								  setcontroltext(w21,4,"105")
								  setcontroltext(w21,5,"105")
								  setcontroltext(w21,6,"105")

                     case 220 'Comment colour
								  setcontroltext(w21,4,"0")
								  setcontroltext(w21,5,"102")
								  setcontroltext(w21,6,"0")

                     case 221 'Quotation colour
								  setcontroltext(w21,4,"148")
								  setcontroltext(w21,5,"0")
								  setcontroltext(w21,6,"211")

                     case 222 'Text colour
								  setcontroltext(w21,4,"0")
								  setcontroltext(w21,5,"0")
								  setcontroltext(w21,6,"0")

                     case 223 'Numbers colour
								  setcontroltext(w21,4,"0")
								  setcontroltext(w21,5,"102")
								  setcontroltext(w21,6,"0")

                     case 224 'Local window colour
								  setcontroltext(w21,4,"128")
								  setcontroltext(w21,5,"0")
								  setcontroltext(w21,6,"0")

              endselect
           endif

      case 3 'Save 
           NewColour = RGBtoDec(val(getcontroltext(w21,4)),val(getcontroltext(w21,5)),val(getcontroltext(w21,6)))
           closewindow w21
           return 0
 
		case& 4
		case& 5
		case& 6
			notifycode = @NOTIFYCODE

			if notifycode = 0x400
				sp = VAL(GETCONTROLTEXT(w21,@CONTROLID))
				if sp > 255
					sp = 255
					SETCONTROLTEXT w21,@CONTROLID,LTRIM$(STR$(sp))
				endif
				if(@CONTROLID >6)
					SETSCROLLPOS w21,@CONTROLID+9,255-sp
				else
					SETSCROLLPOS w21,@CONTROLID+6,255-sp
				endif
				select @CONTROLID
					case 4
						fcr = sp
					case 5
						fcg = sp
					case 6
						fcb = sp
				endselect								
			endif

			if notifycode = 0x100
				select @CONTROLID
					case 4
						SETCONTROLTEXT w21,4,""
					case 5
						SETCONTROLTEXT w21,5,""
					case 6
						SETCONTROLTEXT w21,6,""
				endselect
			endif	

	endselect

	fcolor = RGB(fcr,fcg,fcb)
   if fcolor > 4000000
      SETCONTROLCOLOR w21,2,RGB(0,0,0),fcolor
   else
      SETCONTROLCOLOR w21,2,RGB(255,255,255),fcolor
   endif
case @IDCHAR
     int Key = @CODE
	  if Key = 27 then run = 0

case @IDVSCROLL
	select @CONTROLID
		case 10
			select @CODE
				case @SBTHUMBTRACK
					SETSCROLLPOS w21,10,@QUAL
					sp=255-GETSCROLLPOS(w21,10)
					SETCONTROLTEXT w21, 4, LTRIM$(STR$(sp))
			 		fcr=sp
			endselect
		case 11
			select @CODE
				case @SBTHUMBTRACK
					SETSCROLLPOS w21,11,@QUAL
					sp=255-GETSCROLLPOS(w21,11)
					SETCONTROLTEXT w21, 5, LTRIM$(STR$(sp))
					fcg=sp
			endselect
		case 12
			select @CODE
				case @SBTHUMBTRACK
					SETSCROLLPOS w21,12,@QUAL
					sp=255-GETSCROLLPOS(w21,12)
					SETCONTROLTEXT w21, 6, LTRIM$(STR$(sp))
					fcb=sp
			endselect

	endselect
	fcolor = RGB(fcr,fcg,fcb)

ENDSELECT
RETURN 0
ENDSUB 

SUB RGBtoDec(red:int,green:int,blue:Int),int
'----------------------------------------------------------------------------------------
' Returns and RGB triplet as integer
' Original idea: TexasPete
'----------------------------------------------------------------------------------------
	if blue > 0 then blue = blue * 65536 else blue = 0
	if green > 0 then green = green * 256 else green = 0
RETURN blue + green + red
endsub

'
SUB DecToRGB(decimal:int),string
'----------------------------------------------------------------------------------------
' Returns R G B Triplet from integer
' Original idea: TexasPete
' Please note  : Red,Green and Blue Must be Global and declared outside of this function
'----------------------------------------------------------------------------------------
def GetRed,GetGreen,GetBlue:int
string Red$,Green$,Blue$
' GetRed :
   blue=int(decimal/(256*256))
	green=int((decimal-blue*256*256)/256)
   GetRed= decimal-Blue*256*256-green*256
' Getgreen:
   blue=int(decimal/(256*256))
   GetGreen=int((decimal-blue*256*256)/256)
' GetBLue:
   GetBlue=int(decimal/(256*256))
	red=GetRed:green=GetGreen:blue=GetBlue

	Red$ = ltrim$(str$(GetRed))
	if len(Red$) = 1 then Red$ = "00" + Red$
	if len(Red$) = 2 then Red$ = "0"  + Red$

	Green$ = ltrim$(str$(GetGreen))
	if len(Green$) = 1 then Green$ = "00" + Green$
	if len(Green$) = 2 then Green$ = "0"  + Green$

	Blue$ = ltrim$(str$(GetBlue))
	if len(Blue$) = 1 then Blue$ = "00" + Blue$
	if len(Blue$) = 2 then Blue$ = "0"  + Blue$

RETURN Red$ + "," + Green$ + "," + Blue$
endsub

sub SetSpelling()
	 setcontroltext(w20,10,"Text background " + SpellWord)
	 setcontroltext(w20,11,"Window background " + SpellWord)
	 setcontroltext(w20,22,"Round bracket " + SpellWord)
	 setcontroltext(w20,23,"Square bracket " + SpellWord)
	 setcontroltext(w20,24,"Local subroutine " + SpellWord)
	 setcontroltext(w20,28,"Constant " + SpellWord)
	 setcontroltext(w20,29,"Definition " + SpellWord)
	 setcontroltext(w20,30,"Preprocessor ($) " + SpellWord)
	 setcontroltext(w20,31,"Key word " + SpellWord)
	 setcontroltext(w20,32,"Assembly " + SpellWord)
	 setcontroltext(w20,38,"Comment " + SpellWord)
	 setcontroltext(w20,40,"Text " + SpellWord)
	 setcontroltext(w20,50,"Numbers " + SpellWord)
	 setcontroltext(w20,51,"Local window " + SpellWord)
return
endsub

sub CreateLines()
	 Downs = 102
    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
	 for a = 1 to 29
		  IF CONTROLEXISTS(w1,a+1000)
			  DestroyWindow(GETCONTROLHANDLE(w1,a+1000))
		  ENDIF
    next a
	 for a = 1 to LinesPerPage
		  CONTROL w1,@STATIC,"",32,Downs,80,LineSpace,@CTEDITRIGHT|0x200,a+1000
		  SETFONT w1, FontName,FontSize,400,0,a+1000
		  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
        setcontroltext(w1,a+1000,ltrim$(str$(FirstVisLine+a)))
		  Downs = Downs + LineSpace
	 next a

	 Tabss = (TabSpacing * 4) 
    SETSIZE w1,119,100,EndButtons-109,rcDepth,RichEdit
    setsize w1,EndButtons+10,100,15,rcDepth,ScrollBar
    setsize w1,1307,rcDepth+105,15,15,BottomButton
    setsize w1,110,100,EndButtons-100,rcDepth,TextBlock1 
    setsize w1,110,100,EndButtons-100,rcDepth,TextBlock2
    setsize w1,110,100,EndButtons-100,rcDepth,TextBlock3
    setsize w1,110,100,EndButtons-100,rcDepth,TextBlock4
    SendMessage(rHandle,EM_SETTABSTOPS,1,&Tabss)
return
endsub

sub Defaults()
	 'Spelling
	 ' 1 = Colour, 0 = Color
	 Spelling = 1

	 'Fonts
	 FontSize = 12						' 10, 11, and 12 available
	 FontName = "Courier New"

	 ' Variable Ucase determines how key words appear on screen.
	 ' Ucase values: 1 Upper case, 2 Lower case, 3 As typed. 
	 Ucase = 1

	 ' Text background colour.
	 'uint ScreenColour = RGB(243,242,214)
	 ScreenColour = rgb(211,211,211) 'Light grey

	 ' Window background colour.
	 WindowBackColour = rgb(231,222,231)

	 ' Allows automatic jumping to sub routines, windows and
	 ' automatically inserts blocks of code when selected. 
	 ' 0 = No, 1 = Yes
	 AutoJumpTo = 0

	 ' Default SELECT to show CASES
	 DefaultSelect = "@CONTROLID" 'For possible future use - for now, not used - ignore.

	 ' Confirmation messages - 0 = No, 1 = Yes
	 ConfirmMessage = 1

	 ' Maximum number of program tabs - 6 is maximum
	 MaxTabs = 6

	 ' Save open files on program exit
	 AutoSaveOnExit = 1

	 ' Save a file when closing that file 
	 AutoSaveOnClose = 1

	 ' Number of lines to scroll when mouse wheel is moved 
	 WheelScrollLines = 4

	 ' Tooltips 1 = Yes 0 = No
	 ToolTips = 1

	 ' Timer speed - best left as is
	 TimerSpeed1 = 10

	 ' Subs / winodows reindex speed
	 ReIndexSpeed = 120000

	 ' Undo / Redo keys
	 UndoKey    = 112	'F1 Key
	 RedoKey    = 113	'F2 Key
	 UndoAllKey = 114	'F3 Key
	 RedoAllKey = 115	'F4 Key

	 ' Number of spaces a TAB key press adds
	 TabSpacing = 3
	 Tabss = (TabSpacing * 4) 

	 ' Auto complete key words, 1 = On, 0 = Off 
	 AutoCompleteKeyWords = 1

	 ' Colour of brackets 
	 RoundBrackets = Red     ' ( )
	 SquareBrackets = Claret ' [ ]

	 ' Colour of local sub routine names 
	 LocalSubColour = Claret 'MySub

	 ' Show line debug information 
	 DebugOn = 1

	 ' Show Line number, Word Number, Edit position, char pos 
	 CoOn = 1

	 ' Close subroutine search window when a selection is made
	 SearchCheckV = 1          '1 = Close, 0 = Don't clode

	 ' Select a colour for numbers.
	 ColourNumbers = Green    
 
	 'Key word colours
	 KeyWordColourAt 			   = Orange		' @						Default = Orange
	 KeyWordColourVariables    = Red			' INT, STRING etc		Default = Red
	 KeyWordColourDollar		   = Grey		' Preprocessor			Default = Grey
	 KeyWordColourAtoZ   		= Blue		' A to Z					Default = Blue
	 KeyWordColourOther  		= Grey		' _ (underscore)		Default = Grey

    LocalWinColour = Claret

return
endsub

sub SaveUserDefaults()
	 if openfile(MyFile2,getstartpath + "\Res\\"+ "xeditor4Defaults.ini","W") = 0
		 write MyFile2,ltrim$(str$(Spelling))
		 write MyFile2,ltrim$(str$(FontSize))
		 write MyFile2,FontName
		 write MyFile2,ltrim$(str$(Ucase))
		 write MyFile2,ltrim$(str$(ScreenColour))
		 write MyFile2,ltrim$(str$(WindowBackColour))
		 write MyFile2,ltrim$(str$(AutoJumpTo))
		 write MyFile2,ltrim$(str$(ConfirmMessage))
		 write MyFile2,ltrim$(str$(MaxTabs))
		 write MyFile2,ltrim$(str$(Spelling))
		 write MyFile2,ltrim$(str$(AutoSaveOnExit))
		 write MyFile2,ltrim$(str$(AutoSaveOnClose))
		 write MyFile2,ltrim$(str$(WheelScrollLines))
		 write MyFile2,ltrim$(str$(ToolTips))
		 write MyFile2,ltrim$(str$(TimerSpeed1))
		 write MyFile2,ltrim$(str$(ReIndexSpeed))
		 write MyFile2,ltrim$(str$(UndoKey))
		 write MyFile2,ltrim$(str$(RedoKey))
		 write MyFile2,ltrim$(str$(UndoAllKey))
		 write MyFile2,ltrim$(str$(RedoAllKey))
		 write MyFile2,ltrim$(str$(TabSpacing))
		 write MyFile2,ltrim$(str$(Tabss))
		 write MyFile2,ltrim$(str$(AutoCompleteKeyWords))
		 write MyFile2,ltrim$(str$(RoundBrackets))
		 write MyFile2,ltrim$(str$(SquareBrackets))
		 write MyFile2,ltrim$(str$(LocalSubColour))
		 write MyFile2,ltrim$(str$(LocalWinColour))
		 write MyFile2,ltrim$(str$(DebugOn))
		 write MyFile2,ltrim$(str$(CoOn))
		 write MyFile2,ltrim$(str$(SearchCheckV))
		 write MyFile2,ltrim$(str$(ColourNumbers))
		 write MyFile2,ltrim$(str$(KeyWordColourAt))
		 write MyFile2,ltrim$(str$(KeyWordColourVariables))
		 write MyFile2,ltrim$(str$(KeyWordColourDollar))
		 write MyFile2,ltrim$(str$(KeyWordColourAtoZ))
		 write MyFile2,ltrim$(str$(KeyWordColourOther)) 
		 write MyFile2,ltrim$(str$(FindFirstV))
		 write MyFile2,ltrim$(str$(FindAllV))
		 write MyFile2,ltrim$(str$(FindLastV))
		 write MyFile2,ltrim$(str$(AndV))
		 write MyFile2,ltrim$(str$(OrV))
		 write MyFile2,ltrim$(str$(RememberV))
		 write MyFile2,ltrim$(str$(DupPlacesV))
	 endif
	 closefile MyFile2
return
endsub

sub DisplayLastTab()
    if !InitialTab then return
	 showwindow w1,@SWHIDE,RichEdit
    DisplayTab(InitialTab)
    select InitialTab
           case 1
					 setcaption w1,getcontroltext(w1,FileTab1) + ProgramTitle
           case 2
					 setcaption w1,getcontroltext(w1,FileTab2) + ProgramTitle
           case 3
					 setcaption w1,getcontroltext(w1,FileTab3) + ProgramTitle
           case 4
					 setcaption w1,getcontroltext(w1,FileTab4) + ProgramTitle
           case 5
					 setcaption w1,getcontroltext(w1,FileTab5) + ProgramTitle
           case 6
					 setcaption w1,getcontroltext(w1,FileTab6) + ProgramTitle
    endselect
	 showwindow w1,@SWSHOW,RichEdit
    cLine++
return
endsub

sub Graph2(string SearchIn)
    SearchEnabled = 0
    SubOpen = -1
    CurrentSub = ""
	 ClipText = ltrim$(rtrim$(SearchIn))

	 if CodePhraseV = 0  
		 GetAllWordsToSearch(ClipText)
	 endif
	 
	 int lncount = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
    int state = 0 
    if iswindowclosed(w6) = 0
       state = getstate(w6,FindLast)
    else
       state = getstate(w1,FindLast)
    endif 

    if !state
		 for a = StoppedAt to lncount - 1 
			  wait 1
			  IF (StopGo) 
				  if StopGo = 100 
					  ReplaceNow = 0
					  StopGo     = 0
					  StoppedAt  = 0
					  Toggle     = 0
					  InsertAt   = -1
					  SearchEnabled = 1
					  showwindow w6,@SWHIDE,StopGoButton
                 goto SearchFinished
              endif
				  StoppedAt = a 
				  BREAKFOR
			  ENDIF
			  CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512)
			  if len(ltrim$(line$)) < 3 then goto CheckNextLineW61

			  if CodePhraseV = 1
				  GetWordsFromLine(a,line$)
				  if instr(ucase$(line$),ucase$(ClipText))
					  InsertAt ++
					  CONTROLCMD w6,ListViewResult,@LVINSERTITEM,InsertAt,ltrim$(str$(a+1))
					  CONTROLCMD w6,ListViewResult,@LVSETTEXT,InsertAt,1,Line$
					  CONTROLCMD w6,ListViewResult,@LVSETTEXT,InsertAt,2,CurrentSub
					  if getstate(w6,FindFirst) then goto SearchFinished
				  endif 
			  else
				  if GetWordsFromLine(a,line$)
					  InsertAt ++
					  CONTROLCMD w6,ListViewResult,@LVINSERTITEM,InsertAt,ltrim$(str$(a+1))
					  CONTROLCMD w6,ListViewResult,@LVSETTEXT,InsertAt,1,Line$
					  CONTROLCMD w6,ListViewResult,@LVSETTEXT,InsertAt,2,CurrentSub
					  if getstate(w6,FindFirst) then goto SearchFinished
				  endif
			  endif
			  label CheckNextLineW61
			  int Lines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
			  setcaption w6,"Line " + ltrim$(USING("###,###",a)) + " of " + ltrim$(USING("###,###",Lines))
			  PercentDone ++
			  IF PercentDone = OnePercent
				  PercentCount ++
				  PercentDone = 0 
				  rect w6,wW,wH,PercentCount * 2,10,rgb(0,200,0),rgb(0,200,0)
			  endif
		 next a
    endif

	 if iswindowclosed(w6) = 0
		 state = getstate(w6,FindLast)
	 else
		 state = getstate(w1,FindLast)
	 endif
    if state
		 for a = lncount - 1 to StoppedAt step - 1 
			  wait 1
			  IF (StopGo) 
				  if StopGo = 100 
					  ReplaceNow = 0
					  StopGo     = 0
					  StoppedAt  = 0
					  Toggle     = 0
					  InsertAt   = -1
					  SearchEnabled = 1
					  showwindow w6,@SWHIDE,StopGoButton
                 goto SearchFinished
              endif
				  StoppedAt = a 
				  BREAKFOR
			  ENDIF
			  CONTROLCMD(w1,RichEdit,@RTGETLINE,a,line$,512)
			  if len(ltrim$(line$)) < 3 then goto CheckNextLineW612
			  if CodePhraseV = 1			  
				  'GetWordsFromLine(a,line$)
				  if instr(ucase$(line$),ucase$(ClipText))
					  InsertAt ++
					  CONTROLCMD w6,ListViewResult,@LVINSERTITEM,InsertAt,ltrim$(str$(a+1))
					  CONTROLCMD w6,ListViewResult,@LVSETTEXT,InsertAt,1,Line$
					  CONTROLCMD w6,ListViewResult,@LVSETTEXT,InsertAt,2,CurrentSub
					  goto SearchFinished
				  endif 
			  else
				  if GetWordsFromLine(a,line$)
					  InsertAt ++
					  CONTROLCMD w6,ListViewResult,@LVINSERTITEM,InsertAt,ltrim$(str$(a+1))
					  CONTROLCMD w6,ListViewResult,@LVSETTEXT,InsertAt,1,Line$
					  CONTROLCMD w6,ListViewResult,@LVSETTEXT,InsertAt,2,CurrentSub
					  goto SearchFinished
				  endif
			  endif
			  label CheckNextLineW612
			  Lines = CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT)
			  setcaption w6,"Line " + ltrim$(USING("###,###",a)) + " of " + ltrim$(USING("###,###",Lines))
			  PercentDone ++
			  IF PercentDone = OnePercent
				  PercentCount ++
				  PercentDone = 0 
				  rect w6,wW,wH,PercentCount * 2,10,rgb(0,200,0),rgb(0,200,0)
			  endif
		 next a
    endif

	 if a < CONTROLCMD(w1,RichEdit,@RTGETLINECOUNT) - 1
		 SETCONTROLTEXT w6,StopGoButton,GETSTARTPATH() + "\\Res\\Go.bmp"
		 setcontroltext(w6,4,"Paused")
		 int Results = CONTROLCMD(w6,ListViewResult,@LVGETCOUNT)
		 setcontroltext w6,4,"Results so far for ' " + getcontroltext(w1,CodePhraseEdit) + " ' - " + ltrim$(USING("###,###",Results)) + " found."
	 else
       label SearchFinished
		 ReplaceNow = 0
		 StopGo     = 0
		 StoppedAt  = 0
		 Toggle     = 0
		 InsertAt   = -1
       SearchEnabled = 1
		 setsize w6,10,395,700,50,4
		 rect w6,wW,wH,250,20,BackColour,BackColour
		 showwindow w6,@SWHIDE,StopGoButton
		 showwindow w6,@SWHIDE,StopButton
		 setcaption w6,"Done"
		 Results = CONTROLCMD(w6,ListViewResult,@LVGETCOUNT)
		 setcontroltext w6,4,"Results for " + getcontroltext(w1,CodePhraseEdit) + " ' - " + ltrim$(USING("###,###",Results)) + " found."
	 endif

	 if CONTROLCMD(w6,ListViewResult,@LVGETCOUNT) > 0
		 showwindow w6,@SWSHOW,ReplaceButton
	 endif 

    SubOpen = -1
    CurrentSub = ""

return
endsub

sub DoFind()
    int Mixed = 0
    Loading = 1
    setcontroltext(w1,CodePhraseEdit,ClipText)
    showwindow w1,@SWHIDE,ListView
    FOR b1 = 1 TO len(ClipText)
        Letter = ClipText[b1-1]
        Del = INSTR(CheckLetter2,Letter)
        if Del
           Mixed = 1 
           breakfor
        endif   
    next b1

    if Mixed
       CodePhraseWordsV  = 0
       CodePhraseV       = 1
    else
       CodePhraseWordsV  = 1
       CodePhraseV       = 0
    endif
    setstate w1,CodePhrase,CodePhraseV 
    setstate w1,CodePhraseWords,CodePhraseWordsV
    setcontroltext(w1,CodePhraseStatic,"Find words")
    showwindow w1,@SWSHOW,CodeWordAnd
    showwindow w1,@SWSHOW,CodeWordOr
    if iswindowclosed(w6) = 0 then closewindow w6
    WindowSearchPhrase()

    Loading = 0
    setcontroltext(w1,EDIT_1,ltrim$(str$(cLine)))
    Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
    SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset)
    setfocus w1,RichEdit
return
endsub

sub CaseSelection(opt int Switch)
    int InLine
    int Position
    string text2,text3,text4,FilterList2
	 CONTROLCMD(w16,ListViewResult,@LVDELETEALL)
	 lvcountIn = CONTROLCMD(w1,ListView10,@LVGETCOUNT)
	 FilterList = getstring(w16,Combo4,getselected(w16,Combo4))
	 FilterList2 = getstring(w16,Combo6,getselected(w16,Combo6))

    if FilterList2 = "STATIC" and getstate(w16,ExcludeStatics)
       setstate(w16,ExcludeStatics,0)
       Switch = 0
    endif

	 for a = 0 to lvcountIn - 1
		  CONTROLCMD(w1,ListView10,@LVGETTEXT,a,0,text)
		  CONTROLCMD(w1,ListView10,@LVGETTEXT,a,1,text2)
		  CONTROLCMD(w1,ListView10,@LVGETTEXT,a,2,text3)
		  CONTROLCMD(w1,ListView10,@LVGETTEXT,a,3,text4)
        if mid$(text4,1,1) = "@"
		     text4 = mid$(text4,2,len(text4))
        endif 

        int bx = 0
        int TypeExists = 0 
        for bx = 0 to getstringcount(w16,Combo6) - 1
            if ucase$(text4) = ucase$(getstring(w16,Combo6,bx))
               TypeExists = 1
               breakfor
            endif 
        next bx 

        if TypeExists = 0
           addstring(w16,Combo6,text4)
        endif
        'Conrol has name in it
		  if getstate(w16,InSubName)
			  if instr(ucase$(text),ucase$(getcontroltext(w16,EDIT_1))) or ucase$(getcontroltext(w16,EDIT_1)) = ""  
				  if ucase$(FilterList) = "ALL" then goto AllWindows3
				  if ucase$(FilterList) = ucase$(text3) 'Window name check
					  label AllWindows3
					  if ucase$(FilterList2) = "ALL" then goto DoAll3
					  if ucase$(FilterList2) = ucase$(text4) 'Control type check
						  label DoAll3
                    if Switch and ucase$(text4) = "STATIC" then goto DoNext 
							  CONTROLCMD w16,ListViewResult,@LVINSERTITEM,a,text
							  position = CONTROLCMD(w16,ListViewResult,@LVFINDITEM,text)
							  CONTROLCMD w16,ListViewResult,@LVSETTEXT,position,1,text3
							  CONTROLCMD w16,ListViewResult,@LVSETTEXT,position,2,text2
							  CONTROLCMD w16,ListViewResult,@LVSETTEXT,position,3,text4
					  endif
				  endif
			  endif
		  endif
        'Conrol begins with 
		  if getstate(w16,BeginsWith)
			  InLine = len(getcontroltext(w16,EDIT_1))
			  if ucase$(mid$(text,1,InLine)) = ucase$(getcontroltext(w16,EDIT_1))
				  if ucase$(FilterList) = "ALL" then goto AllWindows4
				  if ucase$(FilterList) = ucase$(text3) 'Window name check
					  label AllWindows4
					  if ucase$(FilterList2) = "ALL" then goto DoAll4
					  if ucase$(FilterList2) = ucase$(text4) 'Control type check
						  label DoAll4
                    if Switch and ucase$(text4) = "STATIC" then goto DoNext 
							  CONTROLCMD w16,ListViewResult,@LVINSERTITEM,a,text
							  position = CONTROLCMD(w16,ListViewResult,@LVFINDITEM,text)
							  CONTROLCMD w16,ListViewResult,@LVSETTEXT,position,1,text3
							  CONTROLCMD w16,ListViewResult,@LVSETTEXT,position,2,text2
							  CONTROLCMD w16,ListViewResult,@LVSETTEXT,position,3,text4
					  endif
				  endif
			  endif
		  endif
    label DoNext
	 next a
    setcontroltext(w16,TotalStatic,"Total " + ltrim$(str$(CONTROLCMD(w16,ListViewResult,@LVGETCOUNT))))
return
endsub

sub ClearSearchPhrase()
	 Loading = 1
	 CodePhraseWordsV  = 1
	 CodePhraseV       = 0
	 setstate w1,CodePhrase,CodePhraseV 
	 setstate w1,CodePhraseWords,CodePhraseWordsV
	 AppendEdit(w1,CodePhraseEdit,"",0)
	 setcontroltext(w1,CodePhraseStatic,"Find words")
	 showwindow w1,@SWSHOW,MaxWordsStatic
	 showwindow w1,@SWSHOW,CodeWordAnd
	 showwindow w1,@SWSHOW,CodeWordOr
	 setfocus w1,CodePhraseEdit 
	 showwindow w1,@SWHIDE,ListView
	 InfoA = ""
	 kw = 0  
	 Loading = 0
return
endsub

sub DoAddNavigationPage(opt int Switch)
    int FirstNavLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1
	 int DupNavMark = 0
    if DupPlacesV = 0
		 for a = 0 to getstringcount(w1,Combo18) - 1
			  string NavString = getstring(w1,Combo18,a)
			  if ltrim$(str$(FirstNavLine)) = ltrim$(NavString)
				  DupNavMark = 1
				  breakfor
			  endif
		 next a
    endif
	 if DupNavMark = 0 and DupPlacesV = 0
       AddToNav(FirstNavLine,Switch)
	 endif
   if DupPlacesV = 1
      if ltrim$(str$(FirstNavLine)) <> getstring(w1,Combo18,getstringcount(w1,Combo18)-1)
         AddToNav(FirstNavLine,Switch)
      endif
   endif
return
endsub

sub AddToNav(int FirstNavLineIn,opt int Switch)
    int InsertAt = 0
	 NavMax ++
	 NavPos = NavMax  
	 insertstring(w1,Combo18,NavMax-1,ltrim$(str$(FirstNavLineIn)))
	 if !Switch then ShowConfirm(18)
	 if NavMax > 1
		 showwindow w1,@SWSHOW,NavBackButton
		 showwindow w1,@SWSHOW,NavForwardButton
		 showwindow w1,@SWHIDE,NavBackGrey
		 showwindow w1,@SWHIDE,NavForwardGrey
	 endif
	 if NavMax = 1 
		 showwindow w1,@SWSHOW,NavBackButton
		 showwindow w1,@SWHIDE,NavBackGrey
		 return 0
	 endif
return
endsub

sub AddToNavStore()

    NavStoreCount[1] = 0
    NavStoreCount[2] = 0
    NavStoreCount[3] = 0
    NavStoreCount[4] = 0
    NavStoreCount[5] = 0
    NavStoreCount[6] = 0

	 if getstringcount(w1,Combo18) >  0
		 select OnTab
				  case 1
						 for a = 0 to getstringcount(w1,Combo18) - 1
							  NavStoreCount[1] ++
							  NavStore1[a+1] = getstring(w1,Combo18,a)
						 next a

				  case 2
						 for a = 0 to getstringcount(w1,Combo18) - 1
							  NavStoreCount[2] ++
							  NavStore2[a+1] = getstring(w1,Combo18,a)
						 next a

				  case 3
						 for a = 0 to getstringcount(w1,Combo18) - 1
							  NavStoreCount[3] ++
							  NavStore3[a+1] = getstring(w1,Combo18,a)
						 next a

				  case 4
						 for a = 0 to getstringcount(w1,Combo18) - 1
						 	  NavStoreCount[4] ++
							  NavStore4[a+1] = getstring(w1,Combo18,a)
						 next a

				  case 5
						 for a = 0 to getstringcount(w1,Combo18) - 1
							  NavStoreCount[5] ++
							  NavStore5[a+1] = getstring(w1,Combo18,a)
						 next a

				  case 6
						 for a = 0 to getstringcount(w1,Combo18) - 1
							  NavStoreCount[6] ++
							  NavStore6[a+1] = getstring(w1,Combo18,a)
						 next a

		 endselect 
	 endif
return
endsub

sub AddToBookStore()

    BookStoreCount[1] = 0
    BookStoreCount[2] = 0
    BookStoreCount[3] = 0
    BookStoreCount[4] = 0
    BookStoreCount[5] = 0
    BookStoreCount[6] = 0

	 if getstringcount(w1,Combo6) >  0
		 select OnTab
				  case 1
						 for a = 0 to getstringcount(w1,Combo6) - 1
							  BookStoreCount[1] ++
							  BookStore1[a+1] = getstring(w1,Combo6,a)
						 next a

				  case 2
						 for a = 0 to getstringcount(w1,Combo6) - 1
							  BookStoreCount[2] ++
							  BookStore2[a+1] = getstring(w1,Combo6,a)
						 next a

				  case 3
						 for a = 0 to getstringcount(w1,Combo6) - 1
							  BookStoreCount[3] ++
							  BookStore3[a+1] = getstring(w1,Combo6,a)
						 next a

				  case 4
						 for a = 0 to getstringcount(w1,Combo6) - 1
						 	  BookStoreCount[4] ++
							  BookStore4[a+1] = getstring(w1,Combo6,a)
						 next a

				  case 5
						 for a = 0 to getstringcount(w1,Combo6) - 1
							  BookStoreCount[5] ++
							  BookStore5[a+1] = getstring(w1,Combo6,a)
						 next a

				  case 6
						 for a = 0 to getstringcount(w1,Combo6) - 1
							  BookStoreCount[6] ++
							  BookStore6[a+1] = getstring(w1,Combo6,a)
						 next a

		 endselect 
	 endif
return
endsub

sub Load_Bookmarks()
return
	 GetFileName(w1,0,ProgPath,1)
	 string MainNameD = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 string StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".txt"

    int AddBackIn  = 0
    int ResetCount = 0
    int Position   = 0 

	 if openfile(MyFile2,StoreBookFileD,"R") = 0

		 AddBackIn  = 0
		 ResetCount = 0
		 SendMessage(GetDlgItem(w1.hwnd,Combo6),CB_RESETCONTENT,0,0)
       CONTROLCMD(w1,ListView6,@LVDELETEALL)

		 do
			 read Myfile2,dIn
				 if instr(dIn,":bmk")      
					 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
				 endif

				 if AddBackIn = 0
					 break
				 endif

				 if AddBackIn > 0
					  ResetCount ++
					  read MyFile,dIn
					  if !instr(dIn,":")
                    if ltrim$(rtrim$(dIn)) <> ""
						     insertstring w1,Combo6,ResetCount-1,dIn
                    endif
						  if instr(dIn," ")
							  string StringLineNo = mid$(dIn,1,instr(dIn," ")-1)
							  string BookMarkDesc = mid$(dIn,instr(dIn," ")+1,len(dIn))
						  else
							  StringLineNo = dIn
							  BookMarkDesc = ""
						  endif
						  CONTROLCMD w1,ListView6,@LVINSERTITEM,ResetCount-1,StringLineNo
						  position = CONTROLCMD(w1,ListView6,@LVFINDITEM,StringLineNo)
						  CONTROLCMD w1,ListView6,@LVSETTEXT,position,1,BookMarkDesc
					  endif 
				 endif
		 until ResetCount = AddBackIn or EOF(MyFile2)

endif
closefile MyFile2
return
endsub

sub AddToBookmarksList(string BookStoreIn,int ResetCountIn)
    if instr(BookStoreIn," ")
	    string StringLineNo = mid$(BookStoreIn,1,instr(BookStoreIn," ")-1)
	    string BookMarkDesc = mid$(BookStoreIn,instr(BookStoreIn," ")+1,len(BookStoreIn))
    else
	    StringLineNo = BookStoreIn
	    BookMarkDesc = ""
    endif
    CONTROLCMD w1,ListView6,@LVINSERTITEM,ResetCountIn,StringLineNo
    int position = CONTROLCMD(w1,ListView6,@LVFINDITEM,StringLineNo)
    CONTROLCMD w1,ListView6,@LVSETTEXT,position,1,BookMarkDesc
return
endsub

sub ShowFileButtons()
    conDrawOn(w1,RichEdit)
    SENDMESSAGE w1,EM_SETBKGNDCOLOR,0,ScreenColour,RichEdit
	 enablecontrol w1,SaveButton,1
	 enablecontrol w1,SaveAsButton,1
	 enablecontrol w1,CogButton,1
	 enablecontrol w1,ColourButton,1
	 enablecontrol w1,BackupButton,1
	 enablecontrol w1,ReloadButton,1
	 enablecontrol w1,BinButton,1
	 enablecontrol w1,CloseButton,1
	 enablecontrol w1,ColourButton,1
	 enablecontrol w1,AutoButton,1
	 showwindow w1,@SWSHOW,TopButton
	 showwindow w1,@SWSHOW,BottomButton
	 showwindow w1,@SWSHOW,ScrollBar
	 FOR a = 1 TO LinesPerPage
		  showwindow w1,@SWSHOW,a+1000
	 next a
return
endsub

sub HideFileButtons()
    conDrawOn(w1,RichEdit)
	 SENDMESSAGE w1,EM_SETBKGNDCOLOR,0,rgb(192,192,192),RichEdit
	 enablecontrol w1,SaveButton,0
	 enablecontrol w1,SaveAsButton,0
	 enablecontrol w1,CogButton,0
	 enablecontrol w1,ColourButton,0
	 enablecontrol w1,BackupButton,0
	 enablecontrol w1,ReloadButton,0
	 enablecontrol w1,BinButton,0
	 enablecontrol w1,CloseButton,0
	 enablecontrol w1,ColourButton,0
	 enablecontrol w1,AutoButton,0
	 showwindow w1,@SWHIDE,TopButton
	 showwindow w1,@SWHIDE,BottomButton
	 showwindow w1,@SWHIDE,ScrollBar
	 FOR a = 1 TO LinesPerPage
		  showwindow w1,@SWHIDE,a+1000
	 next a
    setcaption w1,"Please open a file " + ProgramTitle
    setfocus w1
return
endsub

sub WindowRecentFiles()
    OPENWINDOW w17,0,0,725,360,@TOPMOST|@CAPTION,0,"Recent files",&RecentFilesHandler
    Setwindowcolor w17,BackColour

    CONTROL w17,@LISTVIEW,"",10,10,700,280,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			   SENDMESSAGE w17,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			   CONTROLCMD w17,ListViewResult,@LVINSERTCOLUMN,0,"file name"
			   CONTROLCMD w17,ListViewResult,@LVSETCOLWIDTH,0,700
            SendMessage w17,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
            SendMessage w17,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
            SETFONT w17,"Arial",12,400,0,ListViewResult

    CONTROL w17,@STATIC,"Click on a recent file to open it",250,300,220,25,@CTEDITLEFT|0x200,ControlName
            SETCONTROLCOLOR w17,ControlName,RGB(0,0,0),BackColour
            SETFONT w17,"Arial",12,400,0,ControlName

    CONTROL w17,@BUTTON,"Close",630,300,80,25,@CTEDITCENTER,CloseButton 
            SETFONT w17,"Arial",12,400,0,CloseButton

	 if openfile(MyFile2,getstartpath + "\\Res\\" + "RecentFiles.ini","R") = 0
print "Recent ",getstartpath '+ "\\Res\\"+ "RecentFiles.ini"
		 a = 0 
		 dO 
			read MyFile2,dIn
         if ltrim$(rtrim$(dIn)) <> RecentProgramFiles[a]  
				a ++
				RecentProgramFiles[a] = ltrim$(rtrim$(dIn))
         endif
		 until EOF(MyFile2)
	 endif
    closefile MyFile2

	 int RecentCount = 0
	 for b1 = a to 1 step -1
		  RecentCount ++
		  CONTROLCMD w17,ListViewResult,@LVINSERTITEM,RecentCount,RecentProgramFiles[b1]
	 next b1

    WAITUNTIL IsWindowClosed(w17)

return 
endsub

SUB RecentFilesHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                'Centre window and move down a little
                CENTERWINDOW w17
					 int wl,wt,ww,wh
					 GETSIZE w17,wl,wt,ww,wh
					 SETSIZE w17,wl,wt+100,ww,wh

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w17

           CASE @IDCONTROL
                SELECT @CONTROLID
                       case CloseButton
                            if @NOTIFYCODE = 0
                               closewindow w17
                            endif

							  case ListViewResult
									 if @NOTIFYCODE=@NMCLICK 
										 lvpos=*<NMLISTVIEW>@LPARAM.iItem
										 CONTROLCMD(w17,ListViewResult,@LVGETTEXT,lvpos,0,text)
                               ProgPath = text
                               DoOpen(1)
                               DisplayTab(OnTab)
										 ReSizeTabs()
                               ProgCount ++
                               RecentProgs[ProgCount] = ProgPath

									    'Add to recent files
                               if ltrim$(rtrim$(ProgPath)) <> "" 
											 if openfile(MyFile2,getstartpath + "\\Res\\"+ "RecentFiles.ini","A") = 0
												 write MyFile2,ProgPath
											 endif
                               endif
									    closefile MyFile2
                               ShowFileButtons() 
                               closewindow w17
                            endif                  
                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

sub NewFileProc(opt string RecentIn)
	 NewFile = 1
	 Loading = 1
	 select OnTab
			  case 1
					 buffer1 = ""
					 buffer1 = getcontroltext(w1,RichEdit)
			  case 2
					 buffer2 = ""
					 buffer2 = getcontroltext(w1,RichEdit)
			  case 3
					 buffer3 = ""
					 buffer3 = getcontroltext(w1,RichEdit)
			  case 4
					 buffer4 = ""
					 buffer4 = getcontroltext(w1,RichEdit)
			  case 5
					 buffer5 = ""
					 buffer5 = getcontroltext(w1,RichEdit)
			  case 6
					 buffer6 = ""
					 buffer6 = getcontroltext(w1,RichEdit)
	 endselect

	 DoMinimiseAll()

    if RecentIn = ""
	    NewFileCount ++
	    NewFileName = getstartpath + "\Res\\Untitled" + ltrim$(str$(NewFileCOunt)) + ".iwb"
	    ProgPath = getstartpath + "\Res\\Untitled.iwb"
    else
       NewFileName = RecentIn
       ProgPath = RecentIn
    endif

	 DoOpen(1000)
    if RecentIn = ""
	    setcontroltext(w1,RichEdit,"")
    endif
 
	 ProgPath = NewFileName
	 if NewFile = 1 
		 GetFileName(w1,0,NewFileName,1)
		 select OnTab
				  case 1
						 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),BlueButton
						 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour 
						 setcontroltext(w1,FileTab1,FileNameIs + "*")
						 Tab1Loaded = 1
						 Tab2Loaded = 0 
						 Tab3Loaded = 0
						 Tab4Loaded = 0
						 Tab5Loaded = 0
						 Tab6Loaded = 0
				  case 2
						 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),BlueButton
						 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour 
						 setcontroltext(w1,FileTab2,FileNameIs + "*")
						 Tab1Loaded = 1
						 Tab2Loaded = 1 
						 Tab3Loaded = 0
						 Tab4Loaded = 0
						 Tab5Loaded = 0
						 Tab6Loaded = 0
				  case 3
						 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),BlueButton
						 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour 
						 setcontroltext(w1,FileTab3,FileNameIs + "*")
						 Tab1Loaded = 1
						 Tab2Loaded = 1 
						 Tab3Loaded = 1
						 Tab4Loaded = 0
						 Tab5Loaded = 0
						 Tab6Loaded = 0
				  case 4
						 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),BlueButton
						 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour 
						 setcontroltext(w1,FileTab4,FileNameIs + "*")
						 Tab1Loaded = 1
						 Tab2Loaded = 1 
						 Tab3Loaded = 1
						 Tab4Loaded = 1
						 Tab5Loaded = 0
						 Tab6Loaded = 0
				  case 5
						 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),BlueButton
						 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour 
						 setcontroltext(w1,FileTab5,FileNameIs + "*")
						 Tab1Loaded = 1
						 Tab2Loaded = 1 
						 Tab3Loaded = 1
						 Tab4Loaded = 1
						 Tab5Loaded = 1
						 Tab6Loaded = 0
				  case 6
						 SETCONTROLCOLOR w1,FileTab6,RGB(255,255,255),BlueButton
						 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
						 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour 
						 setcontroltext(w1,FileTab6,FileNameIs + "*")
						 Tab1Loaded = 1
						 Tab2Loaded = 1 
						 Tab3Loaded = 1
						 Tab4Loaded = 1
						 Tab5Loaded = 1
						 Tab6Loaded = 1
		 endselect

		 setcaption w1,FileNameIs + ProgramTitle + "*"
		 ReSizeTabs()
		 ShowFileButtons()
		 setcontroltext(w1,EDIT_1,"1")
		 SENDMESSAGE(rHandle,EM_SETSEL,0,0)
		 setfocus w1,RichEdit
	 endif
	 Loading = 0
	 NewFile = 0
return
endsub

sub OpenFileProc()
	 Loading = 1
	 DoMinimiseAll()
	 DoOpen()
	 if NoNewFile = 1
		 NoNewFile = 0
		 select OnTab
				  case 1
						 DoRestore(0,1)
				  case 2
						 DoRestore(0,2)
				  case 3
						 DoRestore(0,3)
				  case 4
						 DoRestore(0,4)
				  case 5
						 DoRestore(0,5)
				  case 6
						 DoRestore(0,6)
		 endselect
	 endif
	 if Restoring = 1
		 Restoring = 0
	 endif
	 DisplayTab(OnTab)
	 ReSizeTabs()

	 if Tab1Loaded = 1 and getcontroltext(w1,FileTab1) = ""
		 Tab1Loaded = 0
		 TabTaken = 0
		 showwindow w1,@SWHIDE,FileTab1
	 endif

	 if Tab2Loaded = 1 and getcontroltext(w1,FileTab2) = ""
		 Tab2Loaded = 0
		 TabTaken = 1
		 showwindow w1,@SWHIDE,FileTab2
	 endif

	 if Tab3Loaded = 1 and getcontroltext(w1,FileTab3) = ""
		 Tab3Loaded = 0
		 TabTaken = 2
		 showwindow w1,@SWHIDE,FileTab3
	 endif

	 if Tab4Loaded = 1 and getcontroltext(w1,FileTab4) = ""
		 Tab4Loaded = 0
		 TabTaken = 3
		 showwindow w1,@SWHIDE,FileTab4
	 endif

	 if Tab5Loaded = 1 and getcontroltext(w1,FileTab5) = ""
		 Tab5Loaded = 0
		 TabTaken = 4
		 showwindow w1,@SWHIDE,FileTab5
	 endif

	 if Tab6Loaded = 1 and getcontroltext(w1,FileTab6) = ""
		 Tab6Loaded = 0
		 TabTaken = 5
		 showwindow w1,@SWHIDE,FileTab6
	 endif
	 if Tab1Loaded or Tab2Loaded or Tab3Loaded or Tab4Loaded or Tab5Loaded or Tab6Loaded
		 ShowFileButtons() 
	 endif

	 'Add to recent files
	 if ltrim$(rtrim$(ProgPath)) <> "" 
		 if openfile(MyFile2,getstartpath + "\\Res\\"+ "RecentFiles.ini","A") = 0
			 write MyFile2,ProgPath
		 endif
	 endif
	 closefile MyFile2
return
endsub

sub SaveAsProc()
	 DoSaveAs()
	 ReSizeTabs()
	 string MainNameD = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 string StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".pth"
	 if openfile(MyFile2,StoreBookFileD,"W") = 0
		 write MyFile2,ltrim$(ProgPath) 
	 endif
	 closefile MyFile2

	 'Add to recent files
	 if ltrim$(rtrim$(ProgPath)) <> "" 
		 if openfile(MyFile2,getstartpath + "\\Res\\"+ "RecentFiles.ini","A") = 0
			 write MyFile2,ProgPath
		 endif
	 endif
	 closefile MyFile2
return
endsub

SUB SubclassEdit(parent AS WINDOW,id AS INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    lpfn = SetWindowLongA(hEdit,-4,&Edit_Handler)
    SetPropA(hEdit,"edit_handler2",lpfn)   
RETURN
ENDSUB
SUB UnSubclassEdit(parent AS WINDOW,id AS INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    SetWindowLongA(hEdit,-4,GetPropA(hEdit,"edit_handler2"))
    RemovePropA(hEdit,"edit_handler2")
RETURN
ENDSUB

SUB Edit_Handler(hwnd:INT,uMsg:INT,wParam:INT,lParam:POINTER),INT
    SELECT uMsg
           CASE WM_KEYUP
                GetSelPosEdit()
           case WM_CHAR
                if wParam = 32
                   showwindow w1,@SWHIDE,ListView
                endif 
    ENDSELECT
RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler2"),hwnd,uMsg,wParam,lParam)
ENDSUB

SUB SubclassEditFind(parent AS WINDOW,id AS INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    lpfn = SetWindowLongA(hEdit,-4,&Edit_Handler_Find)
    SetPropA(hEdit,"edit_handler4",lpfn)   
RETURN
ENDSUB
SUB UnSubclassEditFind(parent AS WINDOW,id AS INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    SetWindowLongA(hEdit,-4,GetPropA(hEdit,"edit_handler4"))
    RemovePropA(hEdit,"edit_handler4")
RETURN
ENDSUB

SUB Edit_Handler_Find(hwnd:INT,uMsg:INT,wParam:INT,lParam:POINTER),INT
    SELECT uMsg
           CASE WM_KEYUP
                GetSelPosEditFind()
           case WM_CHAR
                if wParam = 32
                   showwindow w1,@SWHIDE,ListView
                endif 
    ENDSELECT
RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler4"),hwnd,uMsg,wParam,lParam)
ENDSUB

'====================================================================
'                                                                   '
'   Sub routine to turn notifications from the rich edit control    ' 
'                  to the parent window on or off                   ' 
'                                                                   '
' Don't forget, after using QuietMode(1), you must use QuietMode(0) '
'                                                                   ' 
'====================================================================
sub QuietMode(int Switch)
    if Switch 'Turn off notifications - QuietMode(1)
		 eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
		 SendMessage(rHandle,WM_SETREDRAW,FALSE,0)
    endif
    if !Switch 'Turn on notifications - QuiteMode(0)
		 SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
		 InvalidateRect(rHandle,0,TRUE)
		 SendMessage(rHandle,EM_SETEVENTMASK,TRUE,eventMask|ENM_CHANGE)
    endif
return
endsub

sub RTGetLastSel(window WinIn,int ControlIn),int
    int Lines = CONTROLCMD(WinIn,ControlIn,@RTGETLINECOUNT)
	 CONTROLCMD(WinIn,ControlIn,@RTGETLINE,Lines-1,line$,512)
	 Offset = SendMessage(getcontrolhandle(WinIn,ControlIn),EM_LINEINDEX,Lines-1,0)
    Int LastSel = (Offset + len(line$)) - 1
return LastSel
endsub

sub RTSelectAll(window WinIn,int ControlIn)
    SendMessage(getcontrolhandle(WinIn,ControlIn),EM_SETSEL,0,RTGetLastSel(WinIn,ControlIn))
    CONTROLCMD WinIn,ControlIn,@RTGETSELTEXT,CutLine
endsub
