 Rem File: DndeditC for Dndbbs Version v5.0a Release r2.0 Tweak t5.0a
 Rem Sub: EditMessBase
 Rem $Include: 'dndedit.inc'

 On Error Goto Main.Error
 Call Stdin(Var)
 If Chained2=0 Then
    Call Init.Arrays
    Call Read.Rows(Var2)
    Max.Row=Var2
    Call Save.Screen(False)
    Call Clear.Screen2
    Call Init.Mouse
    Call Read.Config(False)
    Call Passwrd5(Var,"c")
    Close #TempFile1
    If Var=False Then
       Call Terminate.Program(True)
       End
    Endif
 Endif
Main.Resume:
 Call EditMessBase
 If Chained2 Then
    Chain DND.Path+"DNDEDIT.EXE"
 Endif
 Call Terminate.Program(True)
 End
Main.Error:
 Resume Main.Resume

Sub EditMessBase
 On Local Error Goto Error.Trap230
 Message.Base.Number=1!
 Out3="Sysop Mess Base Edit"
 Call DisplayEditScreen(9,4,Out3)
 Call MessBaseStatusLine
 Call DisplayMessBase
 Do While Lost.Carrier=False
    TempX$=Nul
    Do While TempX$=Nul
       If Lost.Carrier Then
          Exit Do
       Endif
       Call Read.Keyboard(TempX$)
       Call MouseDriver(3)
       If Mouse.Button2 Then
          TempX$=Chr$(27)
       Endif
       If Mouse.Button Then
          Call MouseButton(4)
          If Len(TempX$) Then
             Exit Do
          Endif
       Endif
       If Mouse.Row Or Mouse.Column Then
          Call MouseSelect(4)
       Endif
    Loop
    TempX=False
    Select Case Len(TempX$)
    Case 1
       TempX=Asc(TempX$)
       Select Case TempX
       Case 65 To 90 ' A to Z
          Call SearchMessBasePrefix(TempX)
       Case 97 To 122 ' a to z
          Call SearchMessBasePrefix(TempX)
       Case 1
          Call AddMessBase
          Call MessBaseStatusLine
          Call RedisplayField
          Call DisplayMessBase
       Case 4 ' ^d
          If Message.Base.Number>2! Then
             MessageBaseRecord.BaseDeleted=True
             Call Write.Record(MessBaseFile,Message.Base.Number-2!)
             Out3="Sysop Mess Base Edit"
             Call DisplayEditScreen(9,4,Out3)
             Call MessBaseStatusLine
             Call DisplayMessBase
          Endif
       Case 21 ' ^u
          If Message.Base.Number>2! Then
             MessageBaseRecord.BaseDeleted=False
             Call Write.Record(MessBaseFile,Message.Base.Number-2!)
             Out3="Sysop Mess Base Edit"
             Call DisplayEditScreen(9,4,Out3)
             Call MessBaseStatusLine
             Call DisplayMessBase
          Endif
       Case 5
          Call EditEmail
          If Message.Base.Number>2! Then
             Call Write.Record(MessBaseFile,Message.Base.Number-2!)
          Endif
          Out3="Sysop Mess Base Edit"
          Call DisplayEditScreen(9,4,Out3)
          Call MessBaseStatusLine
          TempX=1
          Call DisplayMessBase
          Call RedisplayField
       Case 8
          Call Help(11)
          Out3="Sysop Mess Base Edit"
          Call DisplayEditScreen(9,4,Out3)
          Call MessBaseStatusLine
          Call DisplayMessBase
       Case 13
          Call MessBaseEdit
          If Message.Base.Number>2! Then
             Call Write.Record(MessBaseFile,Message.Base.Number-2!)
          Endif
          Call MessBaseStatusLine
          TempX=Selection
          Call ShowMessBase
          Call RedisplayField
       Case 14
          Call NextMessBase
          Call MessBaseStatusLine
       Case 17
          Call PreviousMessBase
          Call MessBaseStatusLine
       Case 18
          Call SelectNextMessBase
          Call MessBaseStatusLine
          Call RedisplayField
       Case 23
          Call SearchMessBase
          Call MessBaseStatusLine
       Case 27
          If Message.Base.Number>2! Then
             Call Write.Record(MessBaseFile,Message.Base.Number-2!)
          Endif
          Exit Sub
       End Select
    Case 2
       TempX=Asc(Mid$(TempX$,2,1))
       If TempX=0 Then
          Call Write.Record(MessBaseFile,Message.Base.Number-2!)
          Exit Do
       Endif
       Call MessBaseSelect
    End Select
 Loop
Error.Resume230:
 Exit Sub
Error.Trap230:
 Resume Error.Resume230
End Sub

Sub SearchMessBasePrefix(VarQ)
 On Local Error Goto Error.Trap107x
 If Message.Base.Number>2! Then
    Call Write.Record(MessBaseFile,Message.Base.Number-2!)
 Endif
 VarQ$=Nul
 If VarQ>=65 And VarQ<=90 Then
    VarQ$=Chr$(VarQ)
 Endif
 If VarQ>=97 And VarQ<=122 Then
    VarQ$=Ucase$(Chr$(VarQ))
 Endif
 If Len(VarQ$) Then
    VarX = 0
    For Var2!=Message.Base.Number + 1! - 2! To Lof(MessBaseFile)/MessBaseRecLen
       Call Read.Record(MessBaseFile,Var2!)
       Strng=Rtrim$(MessageBaseRecord.BaseMessName)
       Strng=Ucase$(Strng)
       If Len(Strng) Then
          If Left$(Strng,1)=VarQ$ Then
             VarX = -1
             Message.Base.Number=Var2!+2!
             Exit For
          Endif
       Endif
    Next
    If VarX = 0 Then
       For Var2!=1! To Message.Base.Number - 2!
          Call Read.Record(MessBaseFile,Var2!)
          Strng=Rtrim$(MessageBaseRecord.BaseMessName)
          Strng=Ucase$(Strng)
          If Len(Strng) Then
             If Left$(Strng,1)=VarQ$ Then
                VarX = -1
                Message.Base.Number=Var2!+2!
                Exit For
             Endif
          Endif
       Next
    Endif
 Endif
 Call DisplayMessBase
Error.Resume107x:
 Exit Sub
Error.Trap107x:
 Resume Error.Resume107x
End Sub

Sub MessBaseStatusLine
 On Local Error Goto Error.Trap230a
 Strng="^ Cursor Select "+Chr$(60)+Chr$(217)
 Strng=Strng+" Enter Choice <esc> Exit"
 If Message.Base.Number>2! Then
    Strng=Strng+" ^d Delete ^u Undelete"
 Endif
 Out2="^h Help ^a Add ^n Next ^q Prev ^r Select ^w Search ^e Email"
 Call StatusLine
Error.Resume230a:
 Exit Sub
Error.Trap230a:
 Resume Error.Resume230a
End Sub

Sub DisplayMessBase
 On Local Error Goto Error.Trap230b
 ' public/private
 If Message.Base.Number>=1! And Message.Base.Number<=2! Then
    For TempX=0 To 4
       Call ShowMessBase
    Next
    Call RedisplayField
    Exit Sub
 Endif
 ' messbase record
 If Message.Base.Number>2! Then
    Var!=Message.Base.Number-2!
    If Var!>=SFalse And Var!<=Lof(MessBaseFile)/MessBaseRecLen Then
       Call Read.Record(MessBaseFile,Var!)
       For TempX=0 To 4
          Call ShowMessBase
       Next
       Call RedisplayField
    Endif
 Endif
Error.Resume230b:
 Exit Sub
Error.Trap230b:
 Resume Error.Resume230b
End Sub

Sub ShowMessBase
 On Local Error Goto Error.Trap230c
 Select Case TempX
 Case 0
    Call ANSI(4,33,44)
    Call ANSI(2,2,2)
    Strng="Base"
    Call Scrn(Strng)
    Call ANSI(2,2,16)
    Strng="of"
    Call Scrn(Strng)
    Call ANSI(4,37,40)
    Call ANSI(2,2,7)
    Strng=Space$(8)
    Call Scrn(Strng)
    Call ANSI(2,2,19)
    Strng=Space$(8)
    Call Scrn(Strng)
    Call ANSI(2,2,7)
    Strng=Mid$(Str$(Message.Base.Number),2)
    Call Scrn(Strng)
    Var!=Lof(MessBaseFile)/MessBaseRecLen+2!
    Call ANSI(2,2,19)
    Strng=Mid$(Str$(Var!),2)
    Call Scrn(Strng)
 Case 1
    Call ANSI(4,37,40)
    Call ANSI(2,4,2)
    Strng=Space$(78)
    Call Scrn(Strng)
    Call ANSI(2,4,2)
    Select Case Message.Base.Number
    Case 1!
       Strng="(public) "
    Case 2!
       Strng="(private)"
    Case Else
       Strng=Left$(MessageBaseRecord.BaseMessName,78)
    End Select
    Call Scrn(Strng)
 Case 2
    Call ANSI(4,37,40)
    Call ANSI(2,6,10)
    If Message.Base.Number>2! Then
       If MessageBaseRecord.BaseDeleted Then
          Strng="Yes  "
       Else
          Strng="No   "
       Endif
    Else
       Strng="<n/a>"
    Endif
    Call Scrn(Strng)
 Case 3
    Call ANSI(4,33,44)
    Call ANSI(2,9,2)
    Strng="Public      "
    Call Scrn(Strng)

    Call ANSI(2,10,2)
    Strng="Private     "
    Call Scrn(Strng)

    Call ANSI(2,11,2)
    Strng="DMs only    "
    Call Scrn(Strng)

    Call ANSI(2,12,2)
    Strng="Sysop only  "
    Call Scrn(Strng)

    Call ANSI(2,13,2)
    Strng="Town Mayor  "
    Call Scrn(Strng)

    Call ANSI(2,14,2)
    Strng="Governor    "
    Call Scrn(Strng)

    Call ANSI(2,15,2)
    Strng="Guild Master"
    Call Scrn(Strng)

    Call ANSI(2,16,2)
    Strng="Assistant DM"
    Call Scrn(Strng)

    Call ANSI(4,37,40)
    If Message.Base.Number=1! Then ' public messbase
       Call ANSI(2,9,15)
       Strng="Y"
       Call Scrn(Strng)
       Call ANSI(2,10,15)
       Strng="N"
       Call Scrn(Strng)
       For Var=3 To 8
          Call ANSI(2,Var+8,15)
          Strng="N"
          Call Scrn(Strng)
       Next
    Endif
    If Message.Base.Number=2! Then ' private messbase
       Call ANSI(2,9,15)
       Strng="N"
       Call Scrn(Strng)
       Call ANSI(2,10,15)
       Strng="Y"
       Call Scrn(Strng)
       For Var=3 To 8
          Call ANSI(2,Var+8,15)
          Strng="N"
          Call Scrn(Strng)
       Next
    Endif
    If Message.Base.Number>2! Then
       For Var=0 To 7
          Call ANSI(2,Var+9,15)
          Strng="N"
          If (MessageBaseRecord.BaseType And 2^Var)=2^Var Then
             Strng="Y"
          Endif
          Call Scrn(Strng)
       Next
    Endif
 Case 4
    Call ANSI(4,37,40)
    Call ANSI(2,17,16)
    Strng=Space$(8)
    Call Scrn(Strng)
    Call ANSI(2,17,16)
    If Message.Base.Number<=2! Then
       Strng="<none>"
    Else
       Strng=Ucase$(MessageBaseRecord.BaseFileName)
    Endif
    Call Scrn(Strng)
 End Select
Error.Resume230c:
 Exit Sub
Error.Trap230c:
 Resume Error.Resume230c
End Sub

Sub AddMessBase
 On Local Error Goto Error.Trap230d
 Call GetMessBaseFilename(Var)
 If Var Then
    Message.Base.Number=Lof(MessBaseFile)/MessBaseRecLen+3!
    MessageBaseRecord.BaseFileName=Ucase$(Edit.Data(1))
    MessageBaseRecord.BaseDeleted=False
    MessageBaseRecord.BaseMessName=Nul
    MessageBaseRecord.BaseType=Public.Base
    Call Write.Record(MessBaseFile,Message.Base.Number-2!)
    Close #MessageFile
    Var2$=Data.Path4+Rtrim$(MessageBaseRecord.BaseFileName)+".DAT"
    Open Var2$ For Random Shared As #MessageFile Len=Len(BufferRecord)
 Endif
Error.Resume230d:
 Exit Sub
Error.Trap230d:
 Resume Error.Resume230d
End Sub

Sub GetMessBaseFilename(Var)
 On Local Error Goto Error.Trap230e
 ' get base filename
 VarX = 1
 Do
    TempX$="BASE"+Mid$(Str$(VarX),2)
    FileName=Data.Path4+TempX$+".TBL"
    If Dir$(FileName)=Nul Then
       FileName=Data.Path4+TempX$+".DAT"
       If Dir$(FileName)=Nul Then
          FileName=Data.Path4+TempX$+".NEW"
          If Dir$(FileName)=Nul Then
             Exit Do
          Endif
       Endif
    Endif
    VarX = VarX + 1
    If VarX = 10000 Then ' base9999
       TempX$=Nul
       Exit Do
    Endif
 Loop
 ' edit base filename
 Var=True
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field "
 Call StatusLine
 Call ANSI(4,33,44)
 Call ANSI(2,23,2)
 Strng="Enter File: "
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,23,14)
 Strng=Space$(8)
 Call Scrn(Strng)
 Edit.Data(1)=TempX$
 Restore DataMess2
 Read Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
 Call ScreenEdit
 Var$=Rtrim$(Edit.Data(1))
 If Var$=Nul Then
    Strng="Missing filename."
    Call ErrorMessage
    Var=False
    Exit Sub
 Endif
 For VarX=1 To Len(Var$)
    VarZ=Asc(Mid$(Var$,VarX,1))
    If VarZ>=0 And VarZ<=31 Then
       Strng="Illegal characters."
       Call ErrorMessage
       Var=False
       Exit Sub
    Endif
 Next
 If Instr(Var$,":") Or Instr(Var$,"/") Or Instr(Var$,".") Or _
 Instr(Var$,"\") Or Instr(Var$,"?") Or Instr(Var$,"*") Then
    Strng="Illegal characters."
    Call ErrorMessage
    Var=False
    Exit Sub
 Endif
 Var2$=Data.Path4+Var$+".DAT"
 Var3$=Data.Path4+Var$+".NEW"
 Var4$=Data.Path4+Var$+".TBL"
 If Dir$(Var2$)<>Nul Or Dir$(Var3$)<>Nul Or Dir$(Var4$)<>Nul Then
    Strng="Filename already exists."
    Call ErrorMessage
    Var=False
 Endif
Error.Resume230e:
 Exit Sub
Error.Trap230e:
 Resume Error.Resume230e
End Sub

Sub SelectNextMessBase
 On Local Error Goto Error.Trap230f
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field "
 Call StatusLine
 Call ANSI(4,33,44)
 Call ANSI(2,23,2)
 Strng="Enter Base: "
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,23,14)
 Strng=Space$(6)
 Call Scrn(Strng)
 Call ANSI(4,37,44)
 Call ANSI(2,23,23)
 Strng="(1-"+Mid$(Str$(Lof(MessBaseFile)/MessBaseRecLen+2!),2)+")"
 Multiplier=Len(Strng)+23
 Strng=Strng+" (+/-/x)"
 Call Scrn(Strng)
 Restore DataMess1
 Read Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
 Edit.Data(1)=Nul
 Call ScreenEdit
 Multiplier=False
 Var2!=Int(Val(Edit.Data(1))+.5)
 If Var2!=1! Or Var2!=2! Then
    If Message.Base.Number>2! Then
       Call Write.Record(MessBaseFile,Message.Base.Number-2!)
    Endif
    Message.Base.Number=Var2!
    Call DisplayMessBase
    Exit Sub
 Endif
 If Var2!>2! Then
    Var2!=Var2!-2!
    If Var2!>SFalse And Var2!<=Lof(MessBaseFile)/MessBaseRecLen Then
       If Message.Base.Number>2! Then
          Call Write.Record(MessBaseFile,Message.Base.Number-2!)
       Endif
       Message.Base.Number=Var2!+2!
       Call DisplayMessBase
       Exit Sub
    Endif
 Endif
 Strng="The value is not within the existing mess base numbers."
 Call ErrorMessage
Error.Resume230f:
 Exit Sub
Error.Trap230f:
 Resume Error.Resume230f
End Sub

Sub NextMessBase
 On Local Error Goto Error.Trap230g
 If Message.Base.Number>=2! Then
    If Message.Base.Number!-1!>Lof(MessBaseFile)/MessBaseRecLen Then
       Strng="This is the last base in the base file."
       Call ErrorMessage
       Exit Sub
    Endif
 Endif
 If Message.Base.Number>2! Then
    Call Write.Record(MessBaseFile,Message.Base.Number-2!)
 Endif
 Message.Base.Number=Message.Base.Number+1!
 Call DisplayMessBase
Error.Resume230g:
 Exit Sub
Error.Trap230g:
 Resume Error.Resume230g
End Sub

Sub PreviousMessBase
 On Local Error Goto Error.Trap230h
 If Message.Base.Number<=1! Then
    Strng="This is the first base in the base file."
    Call ErrorMessage
    Exit Sub
 Endif
 If Message.Base.Number>2! Then
    Call Write.Record(MessBaseFile,Message.Base.Number-2!)
 Endif
 Message.Base.Number=Message.Base.Number-1!
 Call DisplayMessBase
Error.Resume230h:
 Exit Sub
Error.Trap230h:
 Resume Error.Resume230h
End Sub

Sub MessBaseEdit
 On Local Error Goto Error.Trap230i
 If Message.Base.Number<=2! Then
    Strng="This base cannot be edited."
    Call ErrorMessage
    Exit Sub
 Endif
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field"
 Call StatusLine
 If Selection=3 Then
    If Message.Base.Number<=2! Then
       Exit Sub
    Endif
    For Var=0 To 7
       Edit.Data(1)="N"
       If (MessageBaseRecord.BaseType And 2^Var)=2^Var Then
          Edit.Data(1)="Y"
       Endif
       Xcoor=Var+9
       Ycoor=15
       Column=15
       Line.Length=1
       Max.Lines=1
       Row=Var+9
       Line.Number=1
       Call ScreenEdit
       Select Case Ucase$(Edit.Data(1))
       Case "Y"
          MessageBaseRecord.BaseType=MessageBaseRecord.BaseType Or 2^Var
       Case "N"
          MessageBaseRecord.BaseType=MessageBaseRecord.BaseType And Not 2^Var
       End Select
    Next
    Exit Sub
 Endif
 Restore MessBaseEditData
 For TempX=1 To Selection
    Read Xcoor, Ycoor, Column, Line.Length, Max.Lines, Row, Line.Number
 Next
 Select Case Selection
 Case 1
    Edit.Data(1)=MessageBaseRecord.BaseMessName
 Case 2
    If MessageBaseRecord.BaseDeleted Then
       Edit.Data(1)="Yes"
    Else
       Edit.Data(1)="No"
    Endif
 Case 4
    Edit.Data(1)=Ucase$(MessageBaseRecord.BaseFileName)
 End Select
 Call ScreenEdit
 Select Case Selection
 Case 1
    MessageBaseRecord.BaseMessName=Edit.Data(1)
 Case 2
    Select Case Ucase$(Left$(Edit.Data(1),1))
    Case "Y"
       MessageBaseRecord.BaseDeleted=True
    Case "N"
       MessageBaseRecord.BaseDeleted=False
    End Select
 Case 4
    Var$=Ucase$(Edit.Data(1))

    For VarX=1 To Len(Var$)
       VarZ=Asc(Mid$(Var$,VarX,1))
       If VarZ>=0 And VarZ<=31 Then
          Strng="Illegal characters."
          Call ErrorMessage
          Var=False
          Exit Sub
       Endif
    Next

    If Instr(Var$,":") Or Instr(Var$,"/") Or Instr(Var$,".") Or _
    Instr(Var$,"\") Or Instr(Var$,"?") Or Instr(Var$,"*") Then
       Strng="Illegal characters."
       Call ErrorMessage
       Var=False
       Exit Sub
    Endif
    MessageBaseRecord.BaseFileName=Ucase$(Edit.Data(1))
 End Select
Error.Resume230i:
 Exit Sub
Error.Trap230i:
 Resume Error.Resume230i
End Sub

Sub SearchMessBase
 On Local Error Goto Error.Trap230j
 If Message.Base.Number>2! Then
    Call Write.Record(MessBaseFile,Message.Base.Number-2!)
 Endif
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field  "
 Out2=Out2+"Append # sign and number for specific base"
 Call StatusLine
 Call ANSI(4,33,44)
 Call ANSI(2,23,2)
 Strng="Enter Mess Base or Number: "
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,23,29)
 Strng=Space$(30)
 Call Scrn(Strng)
 Restore DataMess3
 Read Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
 Edit.Data(1)=Nul
 Call ScreenEdit
 Call MessBaseStatusLine
 Var2!=Int(Val(Edit.Data(1))+.5)
 Temp$=Ucase$(Edit.Data(1))
 If Var2!>=1! And Var2!<=2! Then
    Message.Base.Number=Var2!
    Call DisplayMessBase
    Exit Sub
 Endif
 If Var2!>2! Then
    If Var2!-2!<=Lof(MessBaseFile)/MessBaseRecLen Then
       Message.Base.Number=Var2!
       Call DisplayMessBase
       Exit Sub
    Endif
 Endif
 Temp.Index=SFalse
 Temp1=Instr(Temp$,"#")
 If Temp1 Then
    Temp.Index=Csng(Int(Val(Mid$(Temp$,Temp1+1))+.5))
    Temp$=Left$(Temp$,Temp1-1)
 Endif
 Temp!=SFalse
 Temp3!=SFalse
 For Var2!=1! To Lof(MessBaseFile)/MessBaseRecLen
    Call Read.Record(MessBaseFile,Var2!)
    Strng=Rtrim$(MessageBaseRecord.BaseMessName)
    Call InstrSUB(TempX,Strng,Temp$)
    If TempX Then
       Temp3!=Temp3!+1!
       If Temp3!=1! Then
          Temp!=Var2!
       Endif
       If Temp.Index Then
          If Temp3!=Temp.Index Then
             Message.Base.Number=Var2!+2!
             Call DisplayMessBase
             Exit Sub
          Endif
       Endif
    Endif
 Next
 If Temp.Index=SFalse And Temp3!=1! Then
    Message.Base.Number=Temp!+2!
    Call DisplayMessBase
    Exit Sub
 Endif
 If Temp3!=SFalse Then
    Strng="The base desc was not found in the base file."
    Call ErrorMessage
    Call DisplayMessBase
    Exit Sub
 Endif
 Strng="There was more than one base found."
 Call ErrorMessage
 Strng="^ Scroll Base  "+Chr$(60)+Chr$(217)+" Select Base ("+Ltrim$(Str$(Temp3!))+" found)."
 Out2=Nul
 Call StatusLine
 Message.Base.Number=Temp!+2!
 Var2!=Temp!
 Call DisplayMessBase
 Call RedisplayField
 Do While Lost.Carrier=False
    TempX$=Nul
    Do While TempX$=Nul
       If Lost.Carrier Then
          Exit Do
       Endif
       Call Read.Keyboard(TempX$)
       Call MouseDriver(3)
       If Mouse.Button2 Then
          TempX$=Chr$(27)
       Endif
       If Mouse.Button Then
          Call MouseCheck
          Exit Do
       Endif
    Loop
    TempX=False
    Select Case Len(TempX$)
    Case 1
       If TempX$=Chr$(13) Then
          Message.Base.Number=Var2!+2!
          Call MessBaseStatusLine
          Call RedisplayField
          Call DisplayMessBase
          Exit Sub
       Endif
    Case 2
       TempX=Asc(Mid$(TempX$,2,1))
       Select Case TempX
       Case 72, 141, 152
          VarA=False
          For Var3!=Var2!-1! To 1! Step -1!
             Call Read.Record(MessBaseFile,Var3!)
             Strng=Rtrim$(MessageBaseRecord.BaseMessName)
             Call InstrSUB(TempX,Strng,Temp$)
             If TempX Then
                VarA=True
                Var2!=Var3!
                Message.Base.Number=Var3!+2!
                Call DisplayMessBase
                Call RedisplayField
                Exit For
             Endif
          Next
          If VarA=False Then
             Strng="This is the first base in the search."
             Call ErrorMessage
          Endif
       Case 80, 145, 160
          VarA=False
          For Var3!=Var2!+1! To Lof(MessBaseFile)/MessBaseRecLen
             Call Read.Record(MessBaseFile,Var3!)
             Strng=Rtrim$(MessageBaseRecord.BaseMessName)
             Call InstrSUB(TempX,Strng,Temp$)
             If TempX Then
                VarA=True
                Var2!=Var3!
                Message.Base.Number=Var3!+2!
                Call DisplayMessBase
                Call RedisplayField
                Exit For
             Endif
          Next
          If VarA=False Then
             Strng="This is the last base in the search."
             Call ErrorMessage
          Endif
       End Select
    End Select
 Loop
Error.Resume230j:
 Exit Sub
Error.Trap230j:
 Resume Error.Resume230j
End Sub

Sub MessBaseSelect
 On Local Error Goto Error.Trap230k
 Next.Field=False
 Select Case TempX
 Case 72, 141, 152
    Select Case Selection
    Case 2 To 4
       Next.Field=Selection-1
    End Select
 Case 80, 145, 160
    Select Case Selection
    Case 1 To 3
       Next.Field=Selection+1
    End Select
 Case 71, 119
    If Selection<>1 Then
       Next.Field=1
    Endif
 Case 79, 117
    If Selection<>4 Then
       Next.Field=4
    Endif
 End Select
 Call ShowField
Error.Resume230k:
 Exit Sub
Error.Trap230k:
 Resume Error.Resume230k
End Sub

' Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
DataMess1:
 Data 23,14,14,6,23,1,1

DataMess2:
 Data 23,14,14,8,23,1,1

DataMess3:
 Data 23,29,29,20,23,1,1

' Xcoor, Ycoor, Column, Line.Length, Max.Lines, Row, Line.Number
MessBaseEditData:
 Data 4,2,2,78,1,4,1
 Data 6,10,10,3,1,6,1
 Data 0,0,0,0,0,0,0
 Data 17,16,16,8,1,17,1

Sub EditEmail
 On Local Error Goto Error.Trap231
 Call Open.Mail
 Email.Number=SFalse
 If Lof(TableFile)/TableRecLen>SFalse Then
    Email.Number=1!
 Endif
 Out3="Sysop Email Edit"
 Call DisplayEditScreen(10,13,Out3)
 Call EmailStatusLine
 Call DisplayEmail
 Do While Lost.Carrier=False
    TempX$=Nul
    Do While TempX$=Nul
       If Lost.Carrier Then
          Exit Do
       Endif
       Call Read.Keyboard(TempX$)
       Call MouseDriver(3)
       If Mouse.Button2 Then
          TempX$=Chr$(27)
       Endif
       If Mouse.Button Then
          Call MouseButton(13)
          If Len(TempX$) Then
             Exit Do
          Endif
       Endif
       If Mouse.Row Or Mouse.Column Then
          Call MouseSelect(13)
       Endif
    Loop
    TempX=False
    Select Case Len(TempX$)
    Case 1
       TempX=Asc(TempX$)
       Select Case TempX
       Case 1
          Call AddEmail
          Call EmailStatusLine
          Call RedisplayField
       Case 4 ' ^d
          If Email.Number>SFalse Then
             TableRecord.Killed=True
             Call Write.Record(TableFile,Email.Number)
             Out3="Sysop Email Edit"
             Call DisplayEditScreen(10,13,Out3)
             Call EmailStatusLine
             Call DisplayEmail
          Endif
       Case 21 ' ^u
          If Email.Number>SFalse Then
             TableRecord.Killed=False
             Call Write.Record(TableFile,Email.Number)
             Out3="Sysop Email Edit"
             Call DisplayEditScreen(10,13,Out3)
             Call EmailStatusLine
             Call DisplayEmail
          Endif
       Case 8
          Call Help(12)
          Out3="Sysop Email Edit"
          Call DisplayEditScreen(10,13,Out3)
          Call EmailStatusLine
          Call DisplayEmail
       Case 13
          If Email.Number>SFalse Then
             If Selection<>7 Then
                Call EmailEdit
                Call Write.Record(TableFile,Email.Number)
                If Selection=1 Then
                   Out3="Sysop Email Edit"
                   Call DisplayEditScreen(10,13,Out3)
                   Call DisplayEmail
                Endif
                Call EmailStatusLine
                TempX=Selection
                Call ShowEmail
                Call RedisplayField
             Endif
          Endif
       Case 14
          Call NextEmail
       Case 17
          Call PreviousEmail
       Case 18
          Call SelectNextEmail
          Call EmailStatusLine
          Call RedisplayField
       Case 23 ' ^w
          Call SearchEmail
       Case 6 ' ^f
          Call SearchEmail1
       Case 24 ' ^x
          Call SearchEmail2
       Case 27
          Exit Sub
       End Select
    Case 2
       TempX=Asc(Mid$(TempX$,2,1))
       Call EmailSelect
    End Select
 Loop
Error.Resume231:
 Exit Sub
Error.Trap231:
 Resume Error.Resume231
End Sub

Sub Open.Mail
 On Local Error Goto Error.Trap231a
 NewMessRecLen=Len(NewMessages)
 TableRecLen=Len(TableRecord)
 MessageRecLen=Len(BufferRecord)

 If Message.Base.Number=1! Then
    Message.Base.Name=Public.Filename
 Endif
 If Message.Base.Number=2! Then
    Message.Base.Name=Private.Filename
 Endif
 If Message.Base.Number>2! Then
    Message.Base.Name=MessageBaseRecord.BaseFileName
    Message.Base.Name=Rtrim$(Message.Base.Name)
 Endif

 Close #TableFile, #NewFile, #MessageFile
 FileName=Data.Path4+Message.Base.Name+".TBL"
 Open FileName For Random Shared As #TableFile Len=TableRecLen
 FileName=Data.Path4+Message.Base.Name+".NEW"
 Open FileName For Random Shared As #NewFile Len=NewMessRecLen
 FileName=Data.Path4+Message.Base.Name+".DAT"
 Open FileName For Random Shared As #MessageFile Len=MessageRecLen
Error.Resume231a:
 Exit Sub
Error.Trap231a:
 Resume Error.Resume231a
End Sub

Sub EmailStatusLine
 On Local Error Goto Error.Trap231a2
 Strng="^ Cursor Select "+Chr$(60)+Chr$(217)
 Strng=Strng+" Enter Choice <esc> Exit"
 If Email.Number>SFalse Then
    Strng=Strng+" ^d Delete ^u Undelete ^f Find Text"
 Endif
 Out2="^h Help ^a Add ^n Next ^q Prev ^r Select ^w Search Subject ^x Search From/To"
 Call StatusLine
Error.Resume231a2:
 Exit Sub
Error.Trap231a2:
 Resume Error.Resume231a2
End Sub

Sub DisplayEmail
 On Local Error Goto Error.Trap231b
 Var!=Email.Number
 If Var!>=SFalse And Var!<=Lof(TableFile)/TableRecLen Then
    Call Read.Record(TableFile,Var!)
 Endif
 For TempX=0 To 13
    Call ShowEmail
 Next
 Call RedisplayField
Error.Resume231b:
 Exit Sub
Error.Trap231b:
 Resume Error.Resume231b
End Sub

Sub ShowEmail
 On Local Error Goto Error.Trap231c
 Select Case TempX
 Case 0
    Call ANSI(4,33,44)
    Call ANSI(2,2,2)
    Strng="Email"
    Call Scrn(Strng)
    Call ANSI(2,2,17)
    Strng="of"
    Call Scrn(Strng)
    Call ANSI(4,37,40)
    Call ANSI(2,2,8)
    Strng=Space$(8)
    Call Scrn(Strng)
    Call ANSI(2,2,8)
    Strng=Mid$(Str$(Email.Number),2)
    Call Scrn(Strng)
    Call ANSI(2,2,20)
    Strng=Space$(8)
    Call Scrn(Strng)
    Call ANSI(2,2,20)
    Var!=Lof(TableFile)/TableRecLen
    Strng=Mid$(Str$(Var!),2)
    Call Scrn(Strng)
 Case 1 ' text
    Call ANSI(4,33,44)
    Call ANSI(2,3,7)
    Strng=Space$(13)
    Call Scrn(Strng)
    Call ANSI(2,3,7)
    If Email.Number>SFalse Then
       Strng=Mid$(Str$(TableRecord.Length),2)+" lines"
    Endif
    Call Scrn(Strng)
 Case 2 ' private
    Call ANSI(4,37,40)
    Call ANSI(2,4,10)
    Strng=Space$(3)
    Call Scrn(Strng)
    Call ANSI(2,4,10)
    If Email.Number>SFalse Then
       If TableRecord.Private Then
          Strng="Yes"
       Else
          Strng="No "
       Endif
    Endif
    Call Scrn(Strng)
 Case 3 ' deleted
    Call ANSI(4,37,40)
    Call ANSI(2,6,10)
    Strng=Space$(3)
    Call Scrn(Strng)
    Call ANSI(2,6,10)
    If Email.Number>SFalse Then
       If TableRecord.Killed Then
          Strng="Yes"
       Else
          Strng="No "
       Endif
    Endif
    Call Scrn(Strng)
 Case 4 ' from
    Call ANSI(4,37,40)
    Call ANSI(2,8,7)
    Strng=Space$(30)
    Call Scrn(Strng)
    Call ANSI(2,8,7)
    If Email.Number>SFalse Then
       Strng=TableRecord.From
       Strng=Lcase$(Rtrim$(Strng))
       If Len(Strng) Then
          Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
       Endif
    Endif
    Call Scrn(Strng)
 Case 5 ' subject
    Call ANSI(4,37,40)
    Call ANSI(2,10,10)
    Strng=Space$(20)
    Call Scrn(Strng)
    Call ANSI(2,10,10)
    If Email.Number>SFalse Then
       Strng=TableRecord.Subject
       Strng=Rtrim$(Strng)
    Endif
    Call Scrn(Strng)
 Case 6 ' to
    Call ANSI(4,37,40)
    Call ANSI(2,12,5)
    Strng=Space$(30)
    Call Scrn(Strng)
    Call ANSI(2,12,5)
    If Email.Number>SFalse Then
       Strng=TableRecord.TO
       Strng=Rtrim$(Strng)
       If Strng=Nul Then
          Strng="ALL"
       Else
          Strng=Lcase$(Strng)
          Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
       Endif
    Endif
    Call Scrn(Strng)
 Case 7 ' time
    Call ANSI(4,37,40)
    Call ANSI(2,14,7)
    Strng=Space$(21)
    Call Scrn(Strng)
    Call ANSI(2,14,7)
    If Email.Number>SFalse Then
       Strng=TableRecord.Clock
       Strng=Rtrim$(Strng)
       If Strng=Nul Then
          Strng=Fclock2$
          TableRecord.Clock=Strng
          Call Write.Record(TableFile,Email.Number)
       Endif
    Endif
    Call Scrn(Strng)
 Case 8 ' received
    Call ANSI(4,37,40)
    Call ANSI(2,4,49)
    Strng=Space$(3)
    Call Scrn(Strng)
    Call ANSI(2,4,49)
    If Email.Number>SFalse Then
       If TableRecord.Received Then
          Strng="Yes"
       Else
          Strng="No "
       Endif
    Endif
    Call Scrn(Strng)
 Case 9 ' times read
    Call ANSI(4,37,40)
    Call ANSI(2,6,51)
    Strng=Space$(7)
    Call Scrn(Strng)
    Call ANSI(2,6,51)
    If Email.Number>SFalse Then
       Strng=Mid$(Str$(TableRecord.TimesRead),2)
    Endif
    Call Scrn(Strng)
 Case 10 ' replied to
    Call ANSI(4,37,40)
    Call ANSI(2,8,51)
    Strng=Space$(3)
    Call Scrn(Strng)
    Call ANSI(2,8,51)
    If Email.Number>SFalse Then
       If TableRecord.Reply Then
          Strng="Yes"
       Else
          Strng="No "
       Endif
    Endif
    Call Scrn(Strng)
 Case 11 ' thread
    Call ANSI(4,37,40)
    Call ANSI(2,10,47)
    Strng=Space$(10)
    Call Scrn(Strng)
    Call ANSI(2,10,47)
    If Email.Number>SFalse Then
       If TableRecord.Reply Then
          If TableRecord.Thread=SFalse Then
             Strng="(forward)"
          Else
             Strng=Mid$(Str$(TableRecord.Thread),2)
          Endif
       Else
          Strng="<none>"
       Endif
    Endif
    Call Scrn(Strng)
 Case 12 ' stat
    Call ANSI(4,37,40)
    Call ANSI(2,13,40)
    Strng=Space$(15)
    Call Scrn(Strng)
    Call ANSI(2,13,40)
    If Email.Number>SFalse Then
       Var3=TableRecord.ClassType
       Select Case Var3
       Case 1 To 10
          Strng=Rtrim$(Class.Name(Var3))
       Case Else
          Strng="<none>"
       End Select
    Endif
    Call Scrn(Strng)
    Call ANSI(2,12,45)
    Strng=Space$(2)
    Call Scrn(Strng)
    Call ANSI(2,12,45)
    If Email.Number>SFalse Then
       Var3=TableRecord.ClassType
       Strng=Mid$(Str$(Var3),2)
       Call Scrn(Strng)
    Endif
    Call ANSI(4,33,44)
    Call ANSI(2,12,48)
    Strng="(1-10)"
    Call Scrn(Strng)
 Case 13 ' type
    Call ANSI(4,33,44)
    Call ANSI(2,15,40)
    Strng="Town Mayor        "
    Call Scrn(Strng)

    Call ANSI(4,33,44)
    Call ANSI(2,16,40)
    Strng="Governor          "
    Call Scrn(Strng)

    Call ANSI(4,33,44)
    Call ANSI(2,17,40)
    Strng="Guild Master      "
    Call Scrn(Strng)

    Call ANSI(4,33,44)
    Call ANSI(2,18,40)
    Strng="Sysop             "
    Call Scrn(Strng)

    Call ANSI(4,37,40)
    If Email.Number=SFalse Then
       For Var=15 To 18
          Call ANSI(2,Var,60)
          Strng=" "
          Call Scrn(Strng)
       Next
    Endif

    If Email.Number>SFalse Then
       Call ANSI(2,15,60)
       Strng="N"
       If TableRecord.Flags And Special.Char1 Then
          Strng="Y"
       Endif
       Call Scrn(Strng)

       Call ANSI(2,16,60)
       Strng="N"
       If TableRecord.Flags And Special.Char2 Then
          Strng="Y"
       Endif
       Call Scrn(Strng)

       Call ANSI(2,17,60)
       Strng="N"
       If TableRecord.Flags And Special.Char3 Then
          Strng="Y"
       Endif
       Call Scrn(Strng)

       Call ANSI(2,18,60)
       Strng="N"
       If TableRecord.Flags And Special.Char4 Then
          Strng="Y"
       Endif
       Call Scrn(Strng)
    Endif
 End Select
Error.Resume231c:
 Exit Sub
Error.Trap231c:
 Resume Error.Resume231c
End Sub

Sub AddEmail
 On Local Error Goto Error.Trap231d
 TableRecord.ClassType=False
 TableRecord.Clock=Fclock2$
 TableRecord.Date=DateS$
 TableRecord.Flags=False
 TableRecord.From=Nul
 TableRecord.Killed=False
 TableRecord.Length=False
 TableRecord.Private=False
 TableRecord.Received=False
 TableRecord.Reply=False
 TableRecord.Start=SFalse
 TableRecord.Subject=Nul
 TableRecord.Time=Format$(Now,"hh:mm:ss")
 TableRecord.Timer=Timeit!
 TableRecord.TimesRead=False
 TableRecord.To=Nul
 TableRecord.Thread=SFalse
 Email.Number=Lof(TableFile)/TableRecLen+1!
 Call Write.Record(TableFile,Email.Number)
 Call DisplayEmail
Error.Resume231d:
 Exit Sub
Error.Trap231d:
 Resume Error.Resume231d
End Sub

Sub SelectNextEmail
 On Local Error Goto Error.Trap231e
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field "
 Call StatusLine
 Call ANSI(4,33,44)
 Call ANSI(2,23,2)
 Strng="Enter Email: "
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,23,15)
 Strng=Space$(8)
 Call Scrn(Strng)
 Call ANSI(4,37,44)
 Call ANSI(2,23,24)
 Strng="(1-"+Mid$(Str$(Lof(TableFile)/TableRecLen),2)+")"
 Multiplier=Len(Strng)+24
 Strng=Strng+" (+/-/x)"
 Call Scrn(Strng)
 Restore DataEmail1
 Read Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
 Edit.Data(1)=Nul
 Call ScreenEdit
 Multiplier=False
 Var2!=Int(Val(Edit.Data(1))+.5)
 If Var2!>SFalse And Var2!<=Lof(TableFile)/TableRecLen Then
    Call Write.Record(TableFile,Email.Number)
    Email.Number=Var2!
    Call DisplayEmail
    Exit Sub
 Endif
 Strng="The value is not within the existing email numbers."
 Call ErrorMessage
Error.Resume231e:
 Exit Sub
Error.Trap231e:
 Resume Error.Resume231e
End Sub

Sub NextEmail
 On Local Error Goto Error.Trap231g
 If Email.Number!>=Lof(TableFile)/TableRecLen Then
    Strng="This is the last email in the email file."
    Call ErrorMessage
    Exit Sub
 Endif
 Call Write.Record(TableFile,Email.Number)
 Email.Number=Email.Number+1!
 Call DisplayEmail
Error.Resume231g:
 Exit Sub
Error.Trap231g:
 Resume Error.Resume231g
End Sub

Sub PreviousEmail
 On Local Error Goto Error.Trap231h
 If Email.Number<=1! Then
    Strng="This is the first email in the email file."
    Call ErrorMessage
    Exit Sub
 Endif
 Call Write.Record(TableFile,Email.Number)
 Email.Number=Email.Number-1!
 Call DisplayEmail
Error.Resume231h:
 Exit Sub
Error.Trap231h:
 Resume Error.Resume231h
End Sub

Sub EmailEdit
 On Local Error Goto Error.Trap231i
 If Selection=1 Then
    Call EditEmailText
    Exit Sub
 Endif
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field"
 Call StatusLine
 Restore EmailEditData
 For TempX=1 To Selection
    Read Xcoor, Ycoor, Column, Line.Length, Max.Lines, Row, Line.Number
 Next
 Select Case Selection
 Case 2
    If TableRecord.Private Then
       Edit.Data(1)="Yes "
    Else
       Edit.Data(1)="No  "
    Endif
 Case 3
    If TableRecord.Killed Then
       Edit.Data(1)="Yes "
    Else
       Edit.Data(1)="No  "
    Endif
 Case 4
    Edit.Data(1)=Rtrim$(TableRecord.From)
 Case 5
    Edit.Data(1)=Rtrim$(TableRecord.Subject)
 Case 6
    Strng=TableRecord.TO
    Strng=Rtrim$(Strng)
    If Strng=Nul Then
       Strng="ALL"
    Endif
    Edit.Data(1)=Strng
 Case 7
    Strng=TableRecord.Clock
    Strng=Rtrim$(Strng)
    If Strng=Nul Then
       Strng=Fclock2$
    Endif
    Edit.Data(1)=Strng
 Case 8
    If TableRecord.Received Then
       Edit.Data(1)="Yes "
    Else
       Edit.Data(1)="No  "
    Endif
 Case 9
    Edit.Data(1)=Mid$(Str$(TableRecord.TimesRead),2)
 Case 10
    If TableRecord.Reply Then
       Edit.Data(1)="Yes "
    Else
       Edit.Data(1)="No  "
    Endif
 Case 11
    If TableRecord.Reply Then
       If TableRecord.Thread=SFalse Then
          Strng="(forward)"
       Else
          Strng=Mid$(Str$(TableRecord.Thread),2)
       Endif
    Else
       Strng="<none>"
    Endif
    Edit.Data(1)=Strng
 Case 12
    Call DisplayClassBox
    Var3=TableRecord.ClassType
    Select Case Var3
    Case 1 To 10
       Strng=Mid$(Str$(Var3),2)
    Case Else
       Strng="0"
    End Select
    Edit.Data(1)=Strng
 Case 13
    Edit.Data(1)="N"
    If TableRecord.Flags And Special.Char1 Then
       Edit.Data(1)="Y"
    Endif
    Xcoor=15
    Ycoor=60
    Column=60
    Line.Length=1
    Row=15
    Max.Lines=1
    Line.Number=1
    Call ScreenEdit
    If Ucase$(Edit.Data(1))="Y" Then
       TableRecord.Flags=TableRecord.Flags Or Special.Char1
    Else
       TableRecord.Flags=TableRecord.Flags And Not Special.Char1
    Endif

    Edit.Data(1)="N"
    If TableRecord.Flags And Special.Char2 Then
       Edit.Data(1)="Y"
    Endif
    Xcoor=16
    Ycoor=60
    Column=60
    Line.Length=1
    Row=16
    Max.Lines=1
    Line.Number=1
    Call ScreenEdit
    If Ucase$(Edit.Data(1))="Y" Then
       TableRecord.Flags=TableRecord.Flags Or Special.Char2
    Else
       TableRecord.Flags=TableRecord.Flags And Not Special.Char2
    Endif

    Edit.Data(1)="N"
    If TableRecord.Flags And Special.Char3 Then
       Edit.Data(1)="Y"
    Endif
    Xcoor=17
    Ycoor=60
    Column=60
    Line.Length=1
    Row=17
    Max.Lines=1
    Line.Number=1
    Call ScreenEdit
    If Ucase$(Edit.Data(1))="Y" Then
       TableRecord.Flags=TableRecord.Flags Or Special.Char3
    Else
       TableRecord.Flags=TableRecord.Flags And Not Special.Char3
    Endif

    Edit.Data(1)="N"
    If TableRecord.Flags And Special.Char4 Then
       Edit.Data(1)="Y"
    Endif
    Xcoor=18
    Ycoor=60
    Column=60
    Line.Length=1
    Row=18
    Max.Lines=1
    Line.Number=1
    Call ScreenEdit
    If Ucase$(Edit.Data(1))="Y" Then
       TableRecord.Flags=TableRecord.Flags Or Special.Char4
    Else
       TableRecord.Flags=TableRecord.Flags And Not Special.Char4
    Endif
    Exit Sub
 End Select
 Call ScreenEdit
 Select Case Selection
 Case 2
    Select Case Ucase$(Left$(Edit.Data(1),1))
    Case "Y"
       TableRecord.Private=True
    Case "N"
       TableRecord.Private=False
    End Select
 Case 3
    Select Case Ucase$(Left$(Edit.Data(1),1))
    Case "Y"
       TableRecord.Killed=True
    Case "N"
       TableRecord.Killed=False
    End Select
 Case 4
    TableRecord.From=Ucase$(Edit.Data(1))
 Case 5
    Var$=Lcase$(Edit.Data(1))
    Mid$(Var$,1,1)=Ucase$(Mid$(Var$,1,1))
    TableRecord.Subject=Var$
 Case 6
    TableRecord.To=Ucase$(Rtrim$(Edit.Data(1)))
    If TableRecord.To=Nul Then
       TableRecord.To="ALL"
    Endif
 Case 7
    TableRecord.Clock=Rtrim$(Edit.Data(1))
    If TableRecord.Clock=Nul Then
       TableRecord.Clock=Fclock2$
    Endif
 Case 8
    Select Case Ucase$(Left$(Edit.Data(1),1))
    Case "Y"
       TableRecord.Received=True
    Case "N"
       TableRecord.Received=False
    End Select
 Case 9
    Var!=Int(Val(Edit.Data(1))+.5)
    If Var!>=0 Then
       TableRecord.TimesRead=Var!
    Endif
 Case 10
    Select Case Ucase$(Left$(Edit.Data(1),1))
    Case "Y"
       TableRecord.Reply=True
    Case "N"
       TableRecord.Reply=False
    End Select
 Case 11
    If TableRecord.Reply Then
       Var!=Int(Val(Edit.Data(1))+.5)
       If Var!>=0 Then
          TableRecord.Thread=Var!
       Endif
    Endif
 Case 12
    Var3=Int(Val(Edit.Data(1))+.5)
    Select Case Var3
    Case 1 To 10
       TableRecord.ClassType=Var3
    End Select
    Call Write.Record(TableFile,Email.Number)
    Call ANSI(3,0,0)
    Out3="Sysop Email Edit"
    Call DisplayEditScreen(10,13,Out3)
    Call EmailStatusLine
    Call DisplayEmail
 End Select
Error.Resume231i:
 Exit Sub
Error.Trap231i:
 Resume Error.Resume231i
End Sub

Sub SearchEmail
 On Local Error Goto Error.Trap231j
 Call Write.Record(TableFile,Email.Number)
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field  "
 Out2=Out2+"Append # sign and number for specific email"
 Call StatusLine
 Call ANSI(4,33,44)
 Call ANSI(2,23,2)
 Strng="Enter Subject or Number: "
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,23,27)
 Strng=Space$(30)
 Call Scrn(Strng)
 Restore DataEmail3
 Read Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
 Edit.Data(1)=Nul
 Call ScreenEdit
 Call EmailStatusLine
 Var2!=Int(Val(Edit.Data(1))+.5)
 Temp$=Ucase$(Edit.Data(1))
 If Var2!>SFalse And Var2!<=Lof(TableFile)/TableRecLen Then
    Email.Number=Var2!
    Call DisplayEmail
    Exit Sub
 Endif
 Temp.Index=SFalse
 Temp1=Instr(Temp$,"#")
 If Temp1 Then
    Temp.Index=Csng(Int(Val(Mid$(Temp$,Temp1+1))+.5))
    Temp$=Left$(Temp$,Temp1-1)
 Endif
 Temp!=SFalse
 Temp3!=SFalse
 For Var2!=1! To Lof(TableFile)/TableRecLen
    Call Read.Record(TableFile,Var2!)
    Strng=Rtrim$(TableRecord.Subject)
    Call InstrSUB(TempX,Strng,Temp$)
    If TempX Then
       Temp3!=Temp3!+1!
       If Temp3!=1! Then
          Temp!=Var2!
       Endif
       If Temp.Index Then
          If Temp3!=Temp.Index Then
             Email.Number=Var2!
             Call DisplayEmail
             Exit Sub
          Endif
       Endif
    Endif
 Next
 If Temp.Index=SFalse And Temp3!=1! Then
    Email.Number=Temp!
    Call DisplayEmail
    Exit Sub
 Endif
 If Temp3!=SFalse Then
    Strng="The email subject was not found in the email file."
    Call ErrorMessage
    Call DisplayEmail
    Exit Sub
 Endif
 Strng="There was more than one email found."
 Call ErrorMessage
 Strng="^ Scroll Email  "+Chr$(60)+Chr$(217)+" Select Email ("+Ltrim$(Str$(Temp3!))+" found)."
 Out2=Nul
 Call StatusLine
 Email.Number=Temp!
 Var2!=Temp!
 Call DisplayEmail
 Call RedisplayField
 Do While Lost.Carrier=False
    TempX$=Nul
    Do While TempX$=Nul
       If Lost.Carrier Then
          Exit Do
       Endif
       Call Read.Keyboard(TempX$)
       Call MouseDriver(3)
       If Mouse.Button2 Then
          TempX$=Chr$(27)
       Endif
       If Mouse.Button Then
          Call MouseCheck
          Exit Do
       Endif
    Loop
    TempX=False
    Select Case Len(TempX$)
    Case 1
       If TempX$=Chr$(13) Then
          Email.Number=Var2!
          Call EmailStatusLine
          Call RedisplayField
          Call DisplayEmail
          Exit Sub
       Endif
    Case 2
       TempX=Asc(Mid$(TempX$,2,1))
       Select Case TempX
       Case 72, 141, 152
          VarA=False
          For Var3!=Var2!-1! To 1! Step -1!
             Call Read.Record(TableFile,Var3!)
             Strng=Rtrim$(TableRecord.Subject)
             Call InstrSUB(TempX,Strng,Temp$)
             If TempX Then
                VarA=True
                Var2!=Var3!
                Email.Number=Var3!
                Call DisplayEmail
                Call RedisplayField
                Exit For
             Endif
          Next
          If VarA=False Then
             Strng="This is the first email in the search."
             Call ErrorMessage
          Endif
       Case 80, 145, 160
          VarA=False
          For Var3!=Var2!+1! To Lof(TableFile)/TableRecLen
             Call Read.Record(TableFile,Var3!)
             Strng=Rtrim$(TableRecord.Subject)
             Call InstrSUB(TempX,Strng,Temp$)
             If TempX Then
                VarA=True
                Var2!=Var3!
                Email.Number=Var3!
                Call DisplayEmail
                Call RedisplayField
                Exit For
             Endif
          Next
          If VarA=False Then
             Strng="This is the last email in the search."
             Call ErrorMessage
          Endif
       End Select
    End Select
 Loop
Error.Resume231j:
 Exit Sub
Error.Trap231j:
 Resume Error.Resume231j
End Sub

Sub SearchEmail1
 On Local Error Goto Error.Trap231j2
 Call Write.Record(TableFile,Email.Number)
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field  "
 Out2=Out2+"Append # sign and number for specific email"
 Call StatusLine
 Call ANSI(4,33,44)
 Call ANSI(2,23,2)
 Strng="Enter Message Text or Number: "
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,23,32)
 Strng=Space$(40)
 Call Scrn(Strng)
 Restore DataEmail4
 Read Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
 Edit.Data(1)=Nul
 Call ScreenEdit
 Call EmailStatusLine
 Var2!=Int(Val(Edit.Data(1))+.5)
 Temp$=Ucase$(Edit.Data(1))
 If Var2!>SFalse And Var2!<=Lof(TableFile)/TableRecLen Then
    Email.Number=Var2!
    Call DisplayEmail
    Exit Sub
 Endif
 Temp.Index=SFalse
 Temp1=Instr(Temp$,"#")
 If Temp1 Then
    Temp.Index=Csng(Int(Val(Mid$(Temp$,Temp1+1))+.5))
    Temp$=Left$(Temp$,Temp1-1)
 Endif
 Temp!=SFalse
 Temp3!=SFalse
 For Var2!=1! To Lof(TableFile)/TableRecLen
    Call Read.Record(TableFile,Var2!)
    TempS!=TableRecord.Start
    TempT!=TempS!+Csng(TableRecord.Length)-1!
    For Var3!=TempS! To TempT!
       Call Read.Record(MessageFile,Var3!)
       Strng=BufferRecord.Buffer
       Call Crypto(Strng)
       Strng=Rtrim$(Strng)
       ' see if Temp$ matches in Strng case-sensitive
       TempX=False
       If Len(Strng) Then
          Call InstrSUB(TempX,Strng,Temp$)
       Endif
       If TempX Then
          Temp3!=Temp3!+1!
          If Temp3!=1! Then
             Temp!=Var2!
          Endif
          If Temp.Index Then
             If Temp3!=Temp.Index Then
                Email.Number=Var2!
                Call DisplayEmail
                Exit Sub
             Endif
          Endif
          Exit For
       Endif
    Next
 Next
 If Temp.Index=SFalse And Temp3!=1! Then
    Email.Number=Temp!
    Call DisplayEmail
    Exit Sub
 Endif
 If Temp3!=SFalse Then
    Strng="The email message text was not found in the email file."
    Call ErrorMessage
    Call DisplayEmail
    Exit Sub
 Endif
 Strng="There was more than one email found."
 Call ErrorMessage
 Strng="^ Scroll Email  "+Chr$(60)+Chr$(217)+" Select Email ("+Ltrim$(Str$(Temp3!))+" found)."
 Out2=Nul
 Call StatusLine
 Email.Number=Temp!
 Var2!=Temp!
 Call DisplayEmail
 Call RedisplayField
 Do While Lost.Carrier=False
    TempX$=Nul
    Do While TempX$=Nul
       If Lost.Carrier Then
          Exit Do
       Endif
       Call Read.Keyboard(TempX$)
       Call MouseDriver(3)
       If Mouse.Button2 Then
          TempX$=Chr$(27)
       Endif
       If Mouse.Button Then
          Call MouseCheck
          Exit Do
       Endif
    Loop
    TempX=False
    Select Case Len(TempX$)
    Case 1
       If TempX$=Chr$(13) Then
          Email.Number=Var2!
          Call EmailStatusLine
          Call RedisplayField
          Call DisplayEmail
          Exit Sub
       Endif
    Case 2
       TempX=Asc(Mid$(TempX$,2,1))
       Select Case TempX
       Case 72, 141, 152
          VarA=False
          TempX=False
          For Var3!=Var2!-1! To 1! Step -1!
             Call Read.Record(TableFile,Var3!)
             TempS!=TableRecord.Start
             TempT!=TempS!+Csng(TableRecord.Length)-1!
             For Var2!=TempS! To TempT!
                Call Read.Record(MessageFile,Var2!)
                Strng=BufferRecord.Buffer
                Call Crypto(Strng)
                Strng=Rtrim$(Strng)
                If Len(Strng) Then
                   Call InstrSUB(TempX,Strng,Temp$)
                Endif
                If TempX Then
                   VarA=True
                   Var2!=Var3!
                   Email.Number=Var3!
                   Call DisplayEmail
                   Call RedisplayField
                   Exit For
                Endif
             Next
             If TempX Then
                Exit For
             Endif
          Next
          If VarA=False Then
             Strng="This is the first email in the search."
             Call ErrorMessage
          Endif
       Case 80, 145, 160
          VarA=False
          TempX=False
          For Var3!=Var2!+1! To Lof(TableFile)/TableRecLen
             Call Read.Record(TableFile,Var3!)
             TempS!=TableRecord.Start
             TempT!=TempS!+Csng(TableRecord.Length)-1!
             For Var2!=TempS! To TempT!
                Call Read.Record(MessageFile,Var2!)
                Strng=BufferRecord.Buffer
                Call Crypto(Strng)
                Strng=Rtrim$(Strng)
                If Len(Strng) Then
                   Call InstrSUB(TempX,Strng,Temp$)
                Endif
                If TempX Then
                   VarA=True
                   Var2!=Var3!
                   Email.Number=Var3!
                   Call DisplayEmail
                   Call RedisplayField
                   Exit For
                Endif
             Next
             If TempX Then
                Exit For
             Endif
          Next
          If VarA=False Then
             Strng="This is the last email in the search."
             Call ErrorMessage
          Endif
       End Select
    End Select
 Loop
Error.Resume231j2:
 Exit Sub
Error.Trap231j2:
 Resume Error.Resume231j2
End Sub

Sub SearchEmail2
 On Local Error Goto Error.Trap231j3
 Call Write.Record(TableFile,Email.Number)
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field  "
 Out2=Out2+"Append # sign and number for specific email"
 Call StatusLine
 Call ANSI(4,33,44)
 Call ANSI(2,23,2)
 Strng="Enter To/From or Number: "
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,23,27)
 Strng=Space$(30)
 Call Scrn(Strng)
 Restore DataEmail3
 Read Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
 Edit.Data(1)=Nul
 Call ScreenEdit
 Call EmailStatusLine
 Var2!=Int(Val(Edit.Data(1))+.5)
 Temp$=Ucase$(Edit.Data(1))
 If Var2!>SFalse And Var2!<=Lof(TableFile)/TableRecLen Then
    Email.Number=Var2!
    Call DisplayEmail
    Exit Sub
 Endif
 Temp.Index=SFalse
 Temp1=Instr(Temp$,"#")
 If Temp1 Then
    Temp.Index=Csng(Int(Val(Mid$(Temp$,Temp1+1))+.5))
    Temp$=Left$(Temp$,Temp1-1)
 Endif
 Temp!=SFalse
 Temp3!=SFalse
 For Var2!=1! To Lof(TableFile)/TableRecLen
    Call Read.Record(TableFile,Var2!)
    Strng=Ucase$(TableRecord.From)
    Strng2=Ucase$(TableRecord.To)
    Call InstrSUB(TempX,Strng,Temp$)
    Call InstrSUB(TempY,Strng2,Temp$)
    If TempX Or TempY Then
       Temp3!=Temp3!+1!
       If Temp3!=1! Then
          Temp!=Var2!
       Endif
       If Temp.Index Then
          If Temp3!=Temp.Index Then
             Email.Number=Var2!
             Call DisplayEmail
             Exit Sub
          Endif
       Endif
    Endif
 Next
 If Temp.Index=SFalse And Temp3!=1! Then
    Email.Number=Temp!
    Call DisplayEmail
    Exit Sub
 Endif
 If Temp3!=SFalse Then
    Strng="The email to/from was not found in the email file."
    Call ErrorMessage
    Call DisplayEmail
    Exit Sub
 Endif
 Strng="There was more than one email found."
 Call ErrorMessage
 Strng="^ Scroll Email  "+Chr$(60)+Chr$(217)+" Select Email ("+Ltrim$(Str$(Temp3!))+" found)."
 Out2=Nul
 Call StatusLine
 Email.Number=Temp!
 Var2!=Temp!
 Call DisplayEmail
 Call RedisplayField
 Do While Lost.Carrier=False
    TempX$=Nul
    Do While TempX$=Nul
       If Lost.Carrier Then
          Exit Do
       Endif
       Call Read.Keyboard(TempX$)
       Call MouseDriver(3)
       If Mouse.Button2 Then
          TempX$=Chr$(27)
       Endif
       If Mouse.Button Then
          Call MouseCheck
          Exit Do
       Endif
    Loop
    TempX=False
    Select Case Len(TempX$)
    Case 1
       If TempX$=Chr$(13) Then
          Email.Number=Var2!
          Call EmailStatusLine
          Call RedisplayField
          Call DisplayEmail
          Exit Sub
       Endif
    Case 2
       TempX=Asc(Mid$(TempX$,2,1))
       Select Case TempX
       Case 72, 141, 152
          VarA=False
          For Var3!=Var2!-1! To 1! Step -1!
             Call Read.Record(TableFile,Var3!)
             Strng=Rtrim$(TableRecord.From)
             Strng2=Rtrim$(TableRecord.To)
             Call InstrSUB(TempX,Strng,Temp$)
             Call InstrSUB(TempY,Strng2,Temp$)
             If TempX Or TempY Then
                VarA=True
                Var2!=Var3!
                Email.Number=Var3!
                Call DisplayEmail
                Call RedisplayField
                Exit For
             Endif
          Next
          If VarA=False Then
             Strng="This is the first email in the search."
             Call ErrorMessage
          Endif
       Case 80, 145, 160
          VarA=False
          For Var3!=Var2!+1! To Lof(TableFile)/TableRecLen
             Call Read.Record(TableFile,Var3!)
             Strng=Ucase$(TableRecord.From)
             Strng2=Ucase$(TableRecord.To)
             Call InstrSUB(TempX,Strng,Temp$)
             Call InstrSUB(TempY,Strng2,Temp$)
             If TempX Or TempY Then
                VarA=True
                Var2!=Var3!
                Email.Number=Var3!
                Call DisplayEmail
                Call RedisplayField
                Exit For
             Endif
          Next
          If VarA=False Then
             Strng="This is the last email in the search."
             Call ErrorMessage
          Endif
       End Select
    End Select
 Loop
Error.Resume231j3:
 Exit Sub
Error.Trap231j3:
 Resume Error.Resume231j3
End Sub

Sub EmailSelect
 On Local Error Goto Error.Trap231k
 Next.Field=False
 If TempX$=Chr$(9) Then
    TempX=77
 Endif
 Select Case TempX
 Case 9, 77, 157, 116 ' right
    Select Case Selection
    Case 1
       Next.Field=2
    Case 2 To 7
       Next.Field=Selection+6
    End Select
 Case 15, 75, 155, 115 ' left
    Select Case Selection
    Case 2
       Next.Field=1
    Case 8 To 13
       Next.Field=Selection-6
    End Select
 Case 72, 141, 152 ' up
    If Selection>1 Then
       Next.Field=Selection-1
    Endif
 Case 80 ' down
    If Selection<13 Then
       Next.Field=Selection+1
    Endif
 Case 71, 119 ' home
    If Selection<>1 Then
       Next.Field=1
    Endif
 Case 79, 117 ' end
    If Selection<>13 Then
       Next.Field=13
    Endif
 Case 73, 132 ' pageup
    Select Case Selection
    Case 2 To 7
       Next.Field=1
    Case 9 To 13
       Next.Field=8
    End Select
 Case 81, 118 ' pagedown
    Select Case Selection
    Case 1 To 6
       Next.Field=7
    Case 7 To 12
       Next.Field=13
    End Select
 End Select
 Call ShowField
Error.Resume231k:
 Exit Sub
Error.Trap231k:
 Resume Error.Resume231k
End Sub

Sub EditEmailText
 On Local Error Goto Error.Trap231l
 Restore DataEmail2
 Read Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
 Call ANSI(4,37,40)
 Redim Edit.Data(1 To 19) AS STRING
 For Var=1 To 19
    Call ANSI(2,Var+3,1)
    Strng=Space$(80)
    Call Scrn(Strng)
 Next
 For Var=1 To 19
    Edit.Data(Var)=Nul
 Next
 Var=False
 For Temp4!=TableRecord.Start To TableRecord.Start+Csng(TableRecord.Length)-1!
    Call Read.Record(MessageFile,Temp4!)
    Strng3=BufferRecord.Buffer
    Strng3=Rtrim$(Strng3)
    Call Crypto(Strng3)
    Strng3=Left$(Strng3,80)
    Var=Var+1
    Edit.Data(Var)=Strng3
    Call ANSI(2,Var+3,1)
    Strng=Strng3
    Call Scrn(Strng)
    If Var>=19 Then
       Exit For
    Endif
 Next

 Strng="Email text editor screen."
 Out2="^ Cursor Edit and <esc> Exit Screen "
 Call StatusLine

 Hidden=False
 Call MultiLineScreenEdit ' io8x
 For Var=19 To 1 Step -1
    If Rtrim$(Edit.Data(Var))<>Nul Then
       Exit For
    Endif
 Next
 If Var=0 Then
    Var=1
 Endif
 Call StoreEmailText(Var)
Error.Resume231l:
 Exit Sub
Error.Trap231l:
 Resume Error.Resume231l
End Sub

Sub StoreEmailText(Var)
 On Local Error Goto ErrResume82
StartStore1:
 If Share.Installed Then
    Lock #MessageFile
 Endif
 TempX!=Lof(MessageFile)/MessageRecLen+1!
 TableRecord.Start=TempX!
 TableRecord.Length=Var
 Call Write.Record(TableFile,Email.Number)
 For Temp=1 To Var
    Strng=Edit.Data(Temp)
    Strng=Left$(Strng,80)
    Call Valid(Strng,80)
    Call Crypto(Strng)
    BufferRecord.Buffer=Strng
    Put MessageFile,TempX!,BufferRecord
    TempX!=TempX!+1!
 Next
 If Share.Installed Then
    Unlock #MessageFile
 Endif
ErrExit82:
 Exit Sub
ErrResume82:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       Resume StartStore1
    Endif
 Endif
 Resume ErrExit82
End Sub

Sub DisplayClassBox
 On Local Error Goto Error.Trap231lx
 Call MakeBox(3,58,14,78)
 Call ANSI(4,37,40)
 Strng="Cless"
 Call ANSI(2,3,65)
 Call Scrn(Strng)
 Call ANSI(4,37,44)
 For Var=1 To MaxClassNames
    Strng=Ltrim$(Str$(Var))+"="+Class.Name(Var)
    Call ANSI(2,Var+3,59) 
    Call Scrn(Strng)
 Next
Error.Resume231lx:
 Exit Sub
Error.Trap231lx:
 Resume Error.Resume231lx
End Sub

' Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
DataEmail1:
 Data 23,15,15,8,23,1,1

DataEmail2:
 Data 4,1,1,79,4,19,1

DataEmail3:
 Data 23,27,27,20,23,1,1

DataEmail4:
 Data 23,32,32,40,23,1,1

' Xcoor, Ycoor, Column, Line.Length, Max.Lines, Row, Line.Number
EmailEditData:
 Data 0,0,0,0,0,0,0
 Data 4,10,10,3,1,4,1
 Data 6,10,10,3,1,6,1
 Data 8,7,7,30,1,8,1
 Data 10,10,10,20,1,10,1
 Data 12,5,5,30,1,12,1
 Data 14,7,7,21,1,14,1
 Data 4,49,49,3,1,4,1
 Data 6,51,51,7,1,6,1
 Data 8,51,51,3,1,8,1
 Data 10,47,47,10,1,10,1
 Data 12,45,45,2,1,12,1
 Data 14,45,45,35,1,14,1
