Attribute VB_Name = "managermod"
Global curpagenamebbs$
Global CR$, bbspage$, bbstrailtext$, BBSCHOICE$(100, 4)
Global ctx
Global binputtext$, varrs$(200, 4)
Global PROGRAMARRY$(5000), programarry1$(805, 80)
Global nodelistdatabase$(128, 5)
Global bbsfileapppath$
Global virtualcomport$, RACBBSPATH$
Global BBSTEXTDIM$(100)
Global BBSCOMDWDIM$(100)
Global RacMANGCurrenteditmode$
Global musictransfers$(100, 10)

Public Sub builddebugtext()

l = Len(bbstrailtext$)
For zt = 1 To (l)
ch$ = Mid$(bbstrailtext$, zt, 1)
 If ch$ <> Chr$(13) And ch$ <> Chr$(10) Then sent$ = sent$ + ch$
 sl = Len(sent$)
 If ch$ = Chr$(10) Or ch$ = Chr$(13) And sl > 1 Then
  
  If sl > 1 Then BBSTEXTDIM$(J) = sent$: t$ = t$ + Str$(J) + " ] " + sent$ + ">" + CR$: J = J + 1
   sent$ = ""
   sl = 0
 End If
 Next zt
 
End Sub


Public Function findfilename$(n$)
l = Len(n$)

ot$ = ""
ct = l
Do
ch$ = Mid$(n$, ct, 1)
If ch$ <> "\" Then ot$ = ch$ + ot$
ct = ct - 1
Loop Until ct <= 1 Or ch$ = "\"

findfilename$ = ot$

End Function

Public Sub raccloadsave(na$, ch$)
'ch$ = label1
ch$ = UCase$(ch$)
text$ = ""
bbspage$ = ""
'na$ = Text1
'choicedata.label1 = na$
Select Case (ch$)
Case Is = "OPEN"
 Call EMPTYBBSDIMDATA
 Call CLEARBBSCHOICE
 bbstrailtext$ = ""
FILENUM = FreeFile
 Open na$ For Input As #FILENUM
 'bbsfileapppath$ = Dir1 + "\"
 Do
 Line Input #FILENUM, a$
  text$ = text$ + a$ + CR$
 Loop Until EOF(1)
 Close #FILENUM
 t3$ = Right$(na$, 4)
 t3$ = UCase$(t3$)
   'If t3$ = ".TXT" Then
     bbspage$ = text$
    Debug.Print "proc - " + bbspage$
    Call procbbspage(bbspage$)
    
   'End If
 Call builddebugtext
 
Case Is = "SAVE"

End Select
'LoadSave.Hide
End Sub

Public Sub WRITEPAGETODISK()
Rem WRITE PAGE TO DISK
na$ = choicedata.label1 ' rem get filename

FILENUM = FreeFile
Open na$ For Output As #FILENUM
Print #FILENUM, "BBS@TEXT ------------------"
Print #FILENUM, "BBS@CLS"
For J = 0 To 100
 TXT$ = BBSTEXTDIM$(J)
 If TXT$ <> "" Then Print #FILENUM, "BBS@TEXT " + TXT$ + CR$
Next J

For J = 0 To 100
 t1$ = BBSCHOICE(J, 0)
 t2$ = BBSCHOICE(J, 1)
 t3$ = BBSCHOICE(J, 2)
 t4$ = BBSCHOICE(J, 3)
 t5$ = BBSCHOICE(J, 4)
 If t1$ <> "" Then Print #FILENUM, "BBS@CHOICE " + t1$ + " " + t2$ + " " + t3$ + " " + t4$ + " " + t5$ + CR$
Next J

 Print #FILENUM, "BBS@END" + CR$

Close #FILENUM
End Sub
Public Sub EMPTYBBSDIMDATA()
For ct = 0 To 100
BBSCOMDWDIM$(ct) = ""
BBSTEXTDIM$(ct) = ""
Next ct
End Sub


Public Sub procbbsentry(NODENAME$, bbstext$)
Dim RETVAL$
Rem process cr input from bbs window
Rem uses the bbschoice$(x,x)
ext = 0
cx = 0

Debug.Print " [bbs input ] "; bbstext$
d$ = UCase$(bbstext$)
Do
ch$ = BBSCHOICE$(cx, 0)
 n$ = BBSCHOICE$(cx, 1)
 n2$ = BBSCHOICE$(cx, 2)
  p3$ = BBSCHOICE$(cx, 3)
 n2$ = UCase$(n2$)
 var$ = n2$
 Call cut32(var$, RETVAL$)
 n2$ = RETVAL$
If ch$ <> "" And d$ <> "" Then Debug.Print ch$ + " " + n$ + " " + n2$ + " > " + p3$
ch$ = UCase$(ch$)
If ch$ = (d$) Then
   Select Case (n2$)
    Case Is = "QUPLOAD"
     'Speechform.Text1 = "Q BASIC UPLOAD INITIATED "
      'Speechform.Command1 = True
        Debug.Print "QBASIC LOADING " + n$
        z$ = "BBS@REQUESTQBASIC " + n$
         Call NODEOUT(NODENAME$, z$ + CR$)
      'Open qbasicpath$ + N$ For Input As #15
    Case Is = "RUPLOAD"
     Speechform.Text1 = "R BASIC UPLOAD INITIATED "
      Speechform.Command1 = True
        Debug.Print "R LOADING " + n$
        z$ = "BBS@REQUESTRBASIC " + n$
         Call NODEOUT(NODENAME$, z$ + CR$)
    Case Is = "MUSICSHARE"
      Speechform.Text1 = "MUSIC SHARE OF " + n$ + " INITIATED."
      Speechform.Command1 = True
        OUTTOCRTTEXT$ = OUTTOCRTTEXT$ + "DOWNLOADING MP3" + n$ + " TO " + NODENAME$
         z$ = "BBS@TEXT STARTING DOWNLOAD OF " + n$ + " FROM " + NODENAME$ + CR$
         z$ = z$ + "BBS@REQUESTMUSIC " + n$
         Open App.Path + "\MUSIC\" + n$ For Output As #51
         Call NODEOUT(NODENAME$, z$ + CR$)
        Case Else
    If virtualcomport$ = "COM" Then Call NODEOUT(NODENAME$, "BBS@REQUESTPAGE " + n$ + CR$)
    If virtualcomport$ = "FILE" Then
      
      Debug.Print " verify ."; ch$ + " - " + n$ + " - " + n2$ + " - " + p3$
      If p3$ = "" Then
       FILENUM = FreeFile
        t$ = ""
        fname$ = bbsfileapppath$ + n$
        Debug.Print "opening -->" + fname$
        choicedata.label1 = fname$
        On Error GoTo nopagefound:
        Open fname$ For Input As #FILENUM
        Call EMPTYBBSDIMDATA
        Do
        Line Input #FILENUM, a$
         NODENAME$ = "VBTERM"
           text$ = a$
           Call PROCTEXT(NODENAME$, text$, nodereturndata$)
        Loop Until EOF(FILENUM)
         't$ = t$ + a$ + CR$
        Close #FILENUM
        'bbspage$ = t$
        'Call procbbspage(bbspage$)
          Call builddebugtext
      End If
    End If
    
   End Select
   ext = 1
 End If
cx = cx + 1
Loop Until cx > 100 Or ext = 1

Exit Sub
nopagefound:
FFF = FreeFile
Open na$ For Output As FFF
Print #FFF, "BBS@TEXT"
Print #FFF, "BBSTEXT NEWPAGE"
Close FFF

'Resume

End Sub

Public Sub NODEOUT(n$, noderest$)
n$ = UCase$(n$)
Select Case (n$)
Case Is = "0", "QBASIC"
qbasicouttext$ = qbasicouttext$ + noderest$ + Chr$(13)
Case Is = "1", "PROMPT", "VBTERM"
node1outtext$ = noderest$ + Chr$(13)
Case Is = "2", "NODE2"
node2outtext$ = noderest$ + Chr$(13)
Case Is = "3", "NODE3"
NODE3OUTTEXT$ = noderest$ + Chr$(13)
Case Is = "4", "NODE4"
node4outtext$ = noderest$ + Chr$(13)
Case Is = "5", "NODE5"
NODE5OUTTEXT$ = noderest$ + Chr$(13)
Case Is = "6", "NODE6"
NODE6OUTTEXT$ = noderest$ + Chr$(13)
Case Is = "7", "NODE7"
NODE7OUTTEXT$ = noderest$ + Chr$(13)
Case Is = "8", "NODE8"
NODE8OUTTEXT$ = noderest$ + Chr$(13)
Case Is = "9", "NODE9"
NODE9OUTTEXT$ = noderest$ + Chr$(13)
Case Is = "10", "NODE10"
node10outtext$ = noderest$ + Chr$(13)
Case Is = "11", "NODE11"
node11outtext$ = noderest$ + Chr$(13)
Case Is = "12", "NODE12"
node12outtext$ = noderest$ + Chr$(13)
Case Is = "13", "NODE11"
node13outtext$ = noderest$ + Chr$(13)
Case Is = "14", "NODE14"
node14outtext$ = noderest$ + Chr$(13)
Case Is = "15", "NODE15"
node15outtext$ = noderest$ + Chr$(13)
Case Is = "16", "NODE16"
node16outtext$ = noderest$ + Chr$(13)
Case Is = "17", "NODE17"
node17outtext$ = noderest$ + Chr$(13)
Case Is = "18", "NODE18"
node18outtext$ = noderest$ + Chr$(13)
Case Is = "19", "NODE19"
node19outtext$ = noderest$ + Chr$(13)
Case Is = "20", "NODE20"
node20outtext$ = noderest$ + Chr$(13)
Case Is = "21", "NODE21"
NODE21OUTTEXT$ = noderest$ + Chr$(13)

End Select
End Sub




Public Sub cut32(var$, RETVAL$)
RETVAL$ = ""
z$ = var$
l = Len(z$)
For x = 1 To (l)
ch$ = Mid$(z$, x, 1)
If ch$ <> Chr$(32) Then
 w$ = w$ + ch$
End If
Next x
RETVAL$ = w$
'Debug.Print "cut32 "; retval$
End Sub
Public Sub boot()
RacMANGCurrenteditmode$ = "PAGE"
virtualcomport$ = "FILE"
CR$ = Chr$(13) + Chr$(10)
FILENUM = FreeFile
Open App.Path + "\RACPATH.INI" For Input As #FILENUM
Line Input #FILENUM, RACBBSPATH$
Close #FILENUM

End Sub

Public Sub procbbspage(bbspage$)
l = Len(bbspage$)
ct = 1
Do
ch$ = Mid$(bbspage$, ct, 1)
sent$ = sent$ + ch$

If ch$ = Chr$(13) Or ch$ = Chr$(10) Then
ZTEXT$ = sent$
NODENAME$ = "VBTERM"
Call PROCTEXT(NODENAME$, ZTEXT$, nodereturndata$)
  
z = Len(sent$)
 b$ = Left$(sent$, 8)
  b$ = UCase$(b$)
  'Debug.Print "Z TEXT.. < " + B$
  If b$ = "BBS@TEXT" Then
    ENDTEXT$ = Right$(sent$, z - 8)
    
    'rENDTEXT$ = Right$(SENT$, z - 9)
     ' bbstrailtext$ = bbstrailtext$ + rENDTEXT$ + CR$
       Debug.Print "BBS TEXT " + rENDTEXT$
  End If
  NODENAME$ = "PROMPT"
 BB$ = Left$(sent$, 10)
 BB$ = UCase$(BB$)
 'Debug.Print "PROC BASIC COMMAND ["; BB$ + " "
 If BB$ = "BBS@BASIC" Then
  ENDTEXT$ = Right$(sent$, z - 9)
  text$ = ENDTEXT$
  NODENAME$ = "VBTERM"
  Call PROCTEXT(NODENAME$, text$, nodereturndata$)
  
 End If


sent$ = ""
End If






ct = ct + 1




Loop Until ct >= (l)
End Sub
Public Sub CLEARBBSCHOICE()
Rem CLEAR THE CHOICE VARIABLES
Rem   FOR THE BBS

For cx = 0 To 100
BBSCHOICE$(cx, 0) = ""
BBSCHOICE$(cx, 1) = ""
BBSCHOICE$(cx, 2) = ""
BBSCHOICE$(cx, 3) = ""
BBSCHOICE$(cx, 4) = ""

Next cx

End Sub
Sub PROCTEXT(NODENAME$, text$, nodereturndata$)

Dim RETVAL$
Dim BB As Integer
 If text$ <> "" Then
htext$ = text$

'AXTEXTC >=
AXTEXTCL = Len(htext$)
AXTEXTC = 1
Do
 text$ = ""
 Do
  ch$ = Mid$(htext$, AXTEXTC, 1)
  If ch$ <> Chr$(13) And ch$ <> Chr$(10) Then text$ = text$ + ch$
  AXTEXTC = AXTEXTC + 1
 Loop Until ch$ = Chr$(13) Or AXTEXTC > (AXTEXTCL)
 l = Len(text$)
If l > 10 Then qbasictextin$ = Right$(text$, l - 10)
If l > 14 Then MUSICDATAINBINARY$ = Right$(text$, l - 14)
 musicoption$ = ""
 If l > 13 Then musicoption$ = Left$(text$, 13)
 'Debug.Print "processing ["; text$; "]"
 
 'text$ = UCase$(text$)

  text$ = text$ + " "
alltext$ = text$
alltextcl = Len(alltext$)
ALLTEXTC = 1
Do
 text$ = ""
 q = 0
 Do
   ch$ = Mid$(alltext$, ALLTEXTC, 1)
   
   text$ = text$ + ch$
    If ch$ = Chr$(34) Then
    ALLTEXTC = ALLTEXTC + 1
     Do
      ch$ = Mid$(alltext$, ALLTEXTC, 1)
      ALLTEXTC = ALLTEXTC + 1
       text$ = text$ + ch$
     Loop Until ch$ = Chr$(34) Or (ALLTEXTC) >= (alltextcl)
    End If
 ALLTEXTC = ALLTEXTC + 1
 Loop Until ch$ = ":" Or ch$ = Chr$(13) Or ALLTEXTC > (alltextcl)
 
pWORD$ = ""
 l = Len(text$)
 x = 1
 Call gnpart(text$, otxt$, q): pWORD$ = otxt$: rest$ = Right$(text$, l - q + 1): pWORD$ = UCase$(pWORD$)
If musicoption$ <> "BBS@MUSICDATA" Then
 Call gnpart(text$, otxt$, q): p1$ = otxt$: noderest$ = Right$(text$, l - q + 1)
 Call gnpart(text$, otxt$, q): p2$ = otxt$: NODEREST2$ = Right$(text$, l - q + 1)
 Call gnpart(text$, otxt$, q): p3$ = otxt$: NODEREST3$ = Right$(text$, l - q + 1)
 Call gnpart(text$, otxt$, q): p4$ = otxt$: NODEREST4$ = Right$(text$, l - q + 1)
 Call gnpart(text$, otxt$, q): p5$ = otxt$
 Call gnpart(text$, otxt$, q): p6$ = otxt$
 Call gnpart(text$, otxt$, q): p7$ = otxt$
 Call gnpart(text$, otxt$, q): p8$ = otxt$
   var$ = p1$: Call getvar(var$, RETVAL$): v1 = CONVRTSMLINT(RETVAL$)
   var$ = p2$: Call getvar(var$, RETVAL$): V2 = CONVRTSMLINT(RETVAL$)
   var$ = p3$: Call getvar(var$, RETVAL$): v3 = CONVRTSMLINT(RETVAL$)
   var$ = p4$: Call getvar(var$, RETVAL$): v4 = Val(RETVAL$)
   var$ = p5$: Call getvar(var$, RETVAL$): v5 = Val(RETVAL$)
   var$ = p6$: Call getvar(var$, RETVAL$): V6 = Val(RETVAL$)
   var$ = p7$: Call getvar(var$, RETVAL$): V7 = Val(RETVAL$)
   var$ = p8$: Call getvar(var$, RETVAL$): V8 = Val(RETVAL$)
  
  LNV = Val(pWORD$)
  If LNV > 0 Or pWORD$ = "0" Then
   INCERT$ = rest$
  'Debug.Print " INCERT "; INCERT$
  
  PROGRAMARRY$(LNV) = INCERT$
  If LNV > (PROGLENGTH) Then PROGLENGTH = LNV
  End If
  End If
 Debug.Print pWORD$; "-"; rest$
 'SLEEP

Select Case (pWORD$)
Case Is = "GRPRINT", "GR?"
Call GRPRINT(v1, V2, v3, NODEREST3$)

Case Is = "RND"
zRND = Int(Rnd(1) * (V2)) + 1

putvaR$ = Str$(zRND)
 var$ = p1$
 Call putval(var$, putvaR$)

 
 Case Is = "INCVAR"
   v1 = v1 + V2
    var$ = p1$: putvaR$ = Str$(v1)
     Call putval(var$, putvaR$)
 Case Is = "CLS", "TEXT", "AUDIO"
      TEXTSHOW = 1
      PROMPT$ = "READY" + CR$
      Text12$ = "": TEXT8$ = "": TEXT4$ = "": text$ = ""
      text11$ = "": text7$ = "": text3$ = ""
      text10$ = "": text6$ = "": text2$ = ""
      text9$ = "": text5$ = "": Text1$ = ""
      
Case Is = "BBSTIMER", "BBSTIMERSHOW"
BBStimer.Show
Case Is = "FONTSIZE"
basicprompt.FontSize = v1
Case Is = "SAY", "SPEECH"
  TXT$ = rest$ + " "
   Call buildinexp(TXT$, outtext$)
    rest$ = outtext$
     'debugform.Text1 = debugform.Text1 + "SAY " + rest$
     'Speechform.Text1 = rest$
      'Speechform.Command1 = True

Case Is = "DEBUG"
 DTEXT$ = debugform.Text1
  TXT$ = rest$
    
Call buildinexp(TXT$, outtext$)
 
 
 DTEXT$ = DTEXT$ + outtext$ + CR$
debugform.Text1 = DTEXT$
Case Is = "DEBUGSHOW"
debugform.Show
Case Is = "BBS@USERNAME"
 na$ = p1$
  PW$ = p2$
NODE$ = NODENAME$
Call LOGINUSERTOBBS(NODE$, na$, PW$)
Case Is = "BBS@LOGINHIDE"
 BBSLOGINFRM.Hide
Case Is = "BBS@LOGIN"
If NODENAME$ <> "QBASIC" Then BBSLOGINFRM.Show
If NODENAME$ = "QBASIC" Then
NODE$ = "QBASIC"
 na$ = "qbasic"
 PW$ = "qbpassword"
Call LOGINUSERTOBBS(NODE$, na$, PW$)
End If
Case Is = "BBS@MUSICEND"
 Close #51
 OUTTOCRTTEXT$ = OUTTOOCRTTEXT$ + " MUSIC DOWNLOAD FINISHED."
 
Case Is = "BBS@MUSICDATA"
Print #51, MUSICDATAINBINARY$;

Case Is = "BBS@REQUESTMUSIC"
n$ = rest$
Nd$ = NODENAME$
Call ADDMUSICUPLOAD(Nd$, n$)

Case Is = "BBS@QBASICNAME"
Open qbasicpath$ + p1$ For Output As #15

Case Is = "BBS@QBASICEND"
Close #15
Case Is = "BBS@QBASIC"
Print #15, qbasictextin$

Case Is = "BBS@REQUESTQBASIC"
n$ = rest$

OUTTOCRTTEXT$ = OUTTOCRTTEXT$ + "SENDING " + n$ + " TO " + NODENAME$
Open qbasicpath$ + n$ For Input As 1
Do
 Line Input #1, a$
 t$ = t$ + "BBS@QBASIC " + a$ + CR$
 'Call NODEOUT(NODENAME$, "BBS@QBASIC " + a$ + CR$)
Loop Until EOF(1)

Close #1
nodereturndata$ = nodereturndata$ + "BBS@TEXT TIME STARTED " + Time$ + CR$
nodereturndata$ = nodereturndata$ + "BBS@TEXT RETRIVING " + n$ + " FOR QBASIC" + CR$
nodereturndata$ = nodereturndata$ + "BBS@QBASICNAME " + n$ + CR$
nodereturndata$ = nodereturndata$ + t$ + CR$
nodereturndata$ = nodereturndata$ + "BBS@QBASICEND" + CR$
Case Is = "BBS@REQUESTRBASIC"
n$ = rest$

OUTTOCRTTEXT$ = OUTTOCRTTEXT$ + "SENDING " + n$ + " TO " + NODENAME$
Open App.Path + "\BASIC\" + n$ For Input As 1
Do
 Line Input #1, a$
 t$ = t$ + a$ + CR$
 'Call NODEOUT(NODENAME$, "BBS@RBASIC " + a$ + CR$)
Loop Until EOF(1)

Close #1
nodereturndata$ = nodereturndata$ + "BBS@TEXT RETRIVING" + n$ + CR$

nodereturndata$ = nodereturndata$ + t$ + CR$
Case Is = "BBS@RBASIC"

  LNV = Val(p1$)
   PROGRAMARRY$(LNV) = noderest$
 Debug.Print "BBS@RBASIC "; Str$(LNV) + " " + noderest$
Case Is = "BBS@CHOICE"

    Call PUTBBSCHOICE(p1$, p2$, NODEREST2$)
Case Is = "BBSWINDOW", "BBSSHOW"
bbswindow.Show
Case Is = "BBS@TEXT"
bbstrailtext$ = bbstrailtext$ + rest$ + CR$
Case Is = "BBS@CLS"
bbstrailtext$ = ""
Call CLEARBBSCHOICE

Case Is = "BBS@REQUESTPAGE"
 On Error GoTo ERNOPAGE:
 Open App.Path + "\BBS\" + rest$ For Input As #1
   Do
      Line Input #1, a$
     t$ = t$ + a$ + CR$
       Loop Until EOF(1)
  Close #1
   nodereturndata$ = nodereturndata$ + t$ + CR$
     Debug.Print "NODERETURNDATA " + nodereturndata$ + "-----"
   Speechform.Text1 = "someone is logging in to the bulliten board."
      Speechform.Command1 = True

Case Is = "BBS@OPEN"
        Open App.Path + "\bbs\welcome.txt" For Input As #1
   Do
      Line Input #1, a$
     t$ = t$ + a$ + CR$
       Loop Until EOF(1)
  Close #1
   nodereturndata$ = nodereturndata$ + t$ + CR$
     Debug.Print "NODERETURNDATA " + nodereturndata$ + "-----"
   Speechform.Text1 = "someone is logging in to the bulliten board."
      Speechform.Command1 = True
Case Is = "EXCEL"
excelform.Text1 = p1$
excelform.text2 = p2$
excelform.text3 = NODEREST2$
excelform.Command1 = True


Case Is = "NODEOUT"

 Call NODEOUT(p1$, noderest$)

Case Is = "SENDNODE0", "QBASICOUT"
 qbasicouttext$ = qbasicouttext$ + rest$ + Chr$(13)

Case Is = "SENDNODE1"

 node1outtext$ = rest$ + Chr$(13)
Case Is = "SENDNODE2"
 node2outtext$ = rest$ + Chr$(13)

Case Is = "SENDNODE3"
 NODE3OUTTEXT$ = rest$ + Chr$(13)

Case Is = "SENDNODE4"
 node4outtext$ = rest$ + Chr$(13)

Case Is = "SENDNODE5"
 NODE5OUTTEXT$ = rest$ + Chr$(13)

Case Is = "SENDNODE6"
 NODE6OUTTEXT$ = rest$ + Chr$(13)

Case Is = "SENDNODE7"
 NODE7OUTTEXT$ = rest$ + Chr$(13)

Case Is = "SENDNODE8"
 NODE8OUTTEXT$ = rest$ + Chr$(13)

Case Is = "SENDNODE9"
 NODE9OUTTEXT$ = rest$ + Chr$(13)

Case Is = "SENDNODE10"
 node10outtext$ = rest$ + Chr$(13)

Case Is = "SENDNODE11"
 node11outtext$ = rest$ + Chr$(13)



'Case Is = "CONNECTNODE"
'NODEVAR = V1
'Call Vbterm.CONNECTNODE(NODEVAR)

Case Is = "TESTNODES"
For KZL = 1 To 127
 nodelistdatabase$(KZL, 1) = rest$
Next KZL

Case Is = "NODELIST"
nodelist.Show
'Case Is = "VBTERMLOGIN"

 'ConfigScrnnode1.Command2 = True
Case Is = "MSCOMM", "VBTERM"
 Configallnodes.Show
  Configallnodes.text3 = p1$
   Call Configallnodes.initallnodes
Case Is = "CHATNODE"
chatform.text3 = rest$

Case Is = "CHAT"
'p1$
'noderest$
If NODENAME$ = "VBTERM" Or NODENAME$ = "PROMPT" Then INCOMMINGCHAT$ = INCOMMINGCHAT$ + noderest$ + CR$
Case Is = "SENDCHAT"
chatform.text2 = rest$
chatform.Command1 = True

Case Is = "DOSPROMPT"

    'ChDrive Variables.Drive1.Drive
    Dim i
    'ChDir Variables.Dir1.Path
    Rem PATH CHANGED FOR xp
    i = Shell("C:\WINDOWS\SYSTEM32\Command.com", 1)
OUTTOCRTTEXT$ = OUTTOCRTTEXT$ + "DOS # " + Str$(i) + CR$

 'Call UPDATECTRSCREEN

Case Is = "PLAYFORMSHOW"
playform.Show
Case Is = "PLAY"
'EnablePlay = False
'Call Play(rest$)
'playform.Text1 = rest$
Case Is = "PROGRAMDATABASESHOW"
 programdatabase.Show
 Case Is = "MIDISHOW"
  mainmidi.Show
 Case Is = "MIDI"
  If v1 > 127 Then
     v1 = 127
     OUTTOCRTTEXT$ = "Midi number value cannot exceed 127 "
     'Call UPDATECTRSCREEN

  End If
  mainmidi.Label7 = Str$(v1)
 Case Is = "SPEECHSHOW"
 Speechform.Show
 Case Is = "MAINJOYSTICK"
 Joystickdebug.Text1 = p1$
 Case Is = "JOYSTICK"
 Joystickdebug.Show
 Case Is = "SYS"
'Call procsys(p1$, p2$, P3$, P4$, rest$, noderest$)
 Case Is = "PROMPT2"
 prompt2.Show
 Case Is = "CLIPBOARD"
 Clipboard.SetText (rest$)
 
 Case Is = "QBASICFEED", "QBFEEDON"
 basicprompt.Timer2 = True
 
 Case Is = "QBASICFEEDOFF", "QBFEEDOFF"
 basicprompt.Timer2 = False
 
 Case Is = "TONE", "SOUND"
 tonefrequency = v1
 toneduration = V2
 
 Case Is = "QBASIC"
 Shell "QBASIC.BAT"
 
 Case Is = "DRAWTA"
  DRAWTA = v1
 Case Is = "DRAWQA"
  DRAWQA = v1
  
 Case Is = "DRAW"
  dta$ = rest$
   'cad.text1 = DTA$
    FRMN = 1
 AG = 3
 QA = DRAWQA
 TA = DRAWTA
 BB = 6
   'Call grdraw(AG, QA, TA, dta$, H, V, BB, 1, scal)
 
 
 Case Is = "MOVE"
  Call getvar(p1$, OUTVAL$)
    AA = Val(OUTVAL$)
  Call getvar(p2$, OUTVAL$)
    b = Val(OUTVAL$)
  Call getvar(p3$, OUTVAL$)
    C = Val(p3$)
    If b > (AA) Then AA = AA + C
    If b < (AA) Then AA = AA - C
   Call putval(p1$, Str$(AA))
 
 Case Is = "STOPTIMER"
  RUNTIMER = 0
 Case Is = "RUNTIMER"
 RUNTIMER = 1
 
 Case Is = "INCERTTIMER", "LOADTIMER"
  PROMPT$ = PROMPT$ + "INCERTTIMER " + rest$ + ":"
  zz = 0
  Do
   n$ = programarry1$(MAXPROGSIZE + 2, zz)
       If Len(n$) > 0 Then zz = zz + 1
  Loop Until Len(n$) = 0 Or zz >= 80
   programarry1$(MAXPROGSIZE + 2, zz) = rest$
   programarry1$(MAXPROGSIZE + 1, zz) = "0"
    Rem
Rem LOADS PROGRAM INTO INTEGER BASIC TIMNER WRAPPER
Rem
z$ = rest$
Call cut32(z$, RETVAL$)
 z$ = RETVAL$
 If Right$(z$, 4) <> ".COB" Then z$ = z$ + ".COB"
PROMPT$ = PROMPT$ + " PUTTING " + z$ + " INTO TIMER"
ChDir App.Path + "\basic\"
Close #8
On Error GoTo nofileon8:
Open z$ For Input As #8
x = 1
Do
 If EOF(8) = False Then Line Input #8, a$
 programarry1$(x, zz) = a$
 x = x + 1
Loop Until EOF(8)
Close #8
  PROMPT$ = PROMPT$ + Chr$(13) + rest$ + " IN TIMER MEMORY -" + Str$(zz)
 Case Is = "INCERTLINE"
   Call PROCTEXT(NODENAME$, rest$, nodereturndata$)
 Case Is = "PROGRAMTOSOURCE"
  w$ = ""
  For ax = 0 To (MAXPROGSIZE)
    t$ = PROGRAMARRY$(ax)
     l = Len(t$)
     If l > 0 Then w$ = w$ & Str$(ax) + " " + t$ + Chr$(13) + Chr$(13)
  Next ax
  Source.Text1 = Source.Text1 + w$
 Case Is = "PRINT", "?"
   
   TXT$ = rest$
    
Call buildinexp(TXT$, outtext$)
   If NODENAME$ = "PROMPT" Or NODENAME$ = "PROMPT$" Or NODENAME$ = "TIMER" Then OUTTOCRTTEXT$ = outtext$
  nodereturndata$ = outtext$ + CR$ ' to be passed to node
  
 Case Is = "RUN"

'  Call progrun
 
Case Is = "GOTO"
  LGOTO$ = rest$
Case Is = "MATHINVAL"
 TXT$ = rest$
  Call buildinexp(TXT$, outtext$)
   TiCalculator.txtExpr = outtext$
Case Is = "MATHRETVAL"
Call putval(p1$, TiCalculator.Text1)

Case Is = "MATH"
TXT$ = rest$

Call buildinexp(TXT$, outtext$)
'TiCalculator.Text1 = avaliarExpr(outtext$)
 
 Case Is = "LET"
 var$ = p2$
 Call getvar(var$, RETVAL$)
 p2$ = RETVAL$
 Call putval(p1$, p2$)
 
 'Debug.Print p1$, p2$
 Case Is = "VARIABLES"
 Variables.Show
 Case Is = "NEW"
 xx = 1
Break = 0

Do
 xx = xx + 1
PROGRAMARRY$(xx) = ""

Loop Until xx >= (MAXPROGSIZE) Or xx > (PROGLENGTH)
PROGLENGTH = 0
 MsgBox ("PROGRAM CLEARED")

 
 Case Is = "FILES"
 filepad2.Show
 
 Case Is = "GRMAX"

 Case Is = "BYE", "EXIT"
  'Call exitprogsub
 Case Is = "KEYBOARD"
  Keyboard.Show
  
  Case Is = "END"
 PRFUNCTION$ = "BREAK"
 
 Case Is = "DTA"
 PROMPT$ = vbcad.Text1
 Case Is = "HELP"
  PROMPT$ = PROMPT$ + "----------- HELP ----------- " + CR$
  PROMPT$ = PROMPT$ + "Beep tone print srun task source sendnode0" + CR$
  PROMPT$ = PROMPT$ + "goto node1show sendnode1  " + CR$
  PROMPT$ = PROMPT$ + "nodelist               CirCle Pset " + CR$
  PROMPT$ = PROMPT$ + "              line   Box " + CR$
  PROMPT$ = PROMPT$ + "GR SYS  " + CR$
 
 
 Case Is = "SRUN"
 PRFUNCTION$ = "RUN"
 Case Is = "TASK"
 PROMPT$ = PROMPT$ + PRFUNCTION$ + CR$
 Case Is = "SOURCE"
 Source.Show
 
 Case Is = "L", "LINE"
 
' Call grline(v1, V2, v3, v4, v5)
    
 Case Is = "GR"
 GR.Show
 
 Case Is = "GRCLS"
 GR.Cls
 Case Is = "VRCLS"
 VRwindow.Cls
 Case Is = "NOTEXT"
 TEXTSHOW = 0

 Case Is = "CIRCLE", "CIRC", "C"
    'Call grcircle(v1, V2, v3, v4)
    
 Case Is = "CADDATABASE"
   caddatabase.Show

 Case Is = "CAD"
 Close #1
 Open Root$ + "CADOBJ.DAT" For Output As #1
 'Print "BUILDING CAD DATA"
 Print #1, SWTH / 2
 Print #1, SHHT / 2
 Print #1, Chr$(34) + p1$ + Chr$(34)
 Close #1
 'CHAIN Root$ + "QBCAD.BAS"

 
  
 Case Is = "SAVE"
  'Call SVPROGRAM(p1$)


 Case Is = "LOAD"
  l = Len(rest$)
  'If l > 2 Then Call LDPROGRAM(p1$)


 Case Is = "LPRINT"
     Rem If LP1 = 1 Then Print #8, SUFFIX$

      Rem If prnbr = 0 Then LPRINT P1$

 'Select Case (prnsd$)
 'Case Is = "S"
 'prnouttext$ = P1$
 'Case Is = "P"
 'LPRINT P1$
 
 
 Case Is = "LIST"
  
  PROLIST$ = "1"
  
 Case Is = "BEEP"
 Beep
 
 
 End Select


 text$ = ""
 ' 10, 1: PRINT STRING$(20, " ")
Loop Until ALLTEXTC >= (alltextcl)
Loop Until AXTEXTC >= (AXTEXTCL)

End If
Exit Sub
ERNOPAGE:
'REST$ = "MENU.TXT"
RETURNNODEDATA$ = "BBS@TEXT ERROR 404 PAGE " + rest$ + "   DOES NOT EXIST " + CR$
Close #1
Exit Sub
nofileon8:
OUTTOCRTTEXT$ = OUTTOCRTTEXT$ + " error " + z$ + " not found." + CR$
Exit Sub

End Sub
Public Sub ADDMUSICUPLOAD(Nd$, n$)
Rem add an upload to the music upload list


cx = 0
Do
ch$ = musictransfers$(cx, 0)


If ch$ = (p1$) Or ch$ = "" Then
   musictransfers$(cx, 0) = Nd$
   musictransfers$(cx, 1) = n$
   musictransfers$(cx, 2) = Str$(cx)
   musictransfers$(cx, 3) = "OPEN"
   Select Case (cx)
   Case Is = 0
    Open App.Path + "\MUSIC\" + n$ For Binary Access Read As #40
   Case Is = 1
    Open App.Path + "\MUSIC\" + n$ For Binary Access Read As #41
   Case Is = 2
    Open App.Path + "\MUSIC\" + n$ For Binary Access Read As #42
   Case Is = 3
    Open App.Path + "\MUSIC\" + n$ For Binary Access Read As #43
   Case Is = 4
    Open App.Path + "\MUSIC\" + n$ For Binary Access Read As #44
   Case Is = 5
    Open App.Path + "\MUSIC\" + n$ For Binary Access Read As #45
   Case Is = 6
    Open App.Path + "\MUSIC\" + n$ For Binary Access Read As #46
   Case Is = 7
    Open App.Path + "\MUSIC\" + n$ For Binary Access Read As #47
   Case Is = 8
    Open App.Path + "\MUSIC\" + n$ For Binary Access Read As #48
   Case Is = 9
    Open App.Path + "\MUSIC\" + n$ For Binary Access Read As #49
   Case Is = 10
    Open App.Path + "\MUSIC\" + n$ For Binary Access Read As #50
   
    
    
    
    
   
   
   End Select
   
   'BBSCHOICE$(cx, 0) = p1$
   'BBSCHOICE$(cx, 1) = p2$
   'BBSCHOICE$(cx, 2) = NODEREST2$
End If
cx = cx + 1


Loop Until ch$ = (p1$) Or ch$ = "" Or cx >= 10




End Sub


Public Sub LOGINUSERTOBBS(NODE$, na$, PW$)
Dim RETVAL$
Rem LOGIN USERS TO THE BBS
Rem

On Error GoTo nomainuserstxt:
FILENUM = FreeFile
Open App.Path + "\USERS\mainusers.txt" For Input As #FILENUM
na$ = UCase$(na$)
 'var$ = NA$
  'Call cut32(var$, retval$)
   'NA$ = retval$
PW$ = UCase$(PW$)
 'var$ = PW$
  'Call cut32(var$, retval$)
   'PW$ = retval$
Do
Line Input #FILENUM, d$
Debug.Print "CHECKING "; na$; " "; PW$
text$ = d$ + " "
q = 1
Call gnpart(text$, otxt$, q): NTC$ = otxt$: otxt$ = ""
Call gnpart(text$, otxt$, q): PWTC$ = otxt$: otxt$ = ""
 var$ = NTC$
  Call cut32(var$, RETVAL$)
   NTC$ = RETVAL$
 var$ = PW$
  Call cut32(var$, RETVAL$)
   PW$ = RETVAL$
 
 NTC$ = UCase$(NTC$)
  PWTC$ = UCase$(PWTC$)

Debug.Print "AGAINST "; NTC$; " "; PWTC$

If na$ = (NTC$) And PW$ = (PWTC$) Then

t$ = "BBS@TEXT *********" + CR$
t$ = t$ + "BBS@TEXT username & password accepted " + CR$
t$ = t$ + "BBS@TEXT YOU ARE LOGGED IN " + na$ + CR$
t$ = t$ + "-------------------------------------" + CR$
t$ = t$ + "BBS@LOGINHIDE" + CR$
FILENUM2 = FreeFile
Open App.Path + "\BBS\MAINMENU.TXT" For Input As #FILENUM2
 g$ = ""
 Do
  Line Input #FILENUM2, w$
  g$ = g$ + w$ + CR$
 Loop Until EOF(2)
Close #FILENUM2
t$ = t$ + g$ + CR$

n$ = NODE$
Call NODEOUT(n$, t$ + CR$)

Select Case (n$)
Case Is = "0", "QBASIC"
 patchnode0$ = "BBS"
  nodelistdatabase$(0, 5) = NTC$
Case Is = "1", "NODE1", "VBTERM", "PROMPT"
 patchnode1$ = "BBS"
  nodelistdatabase$(1, 5) = NTC$
Case Is = "2", "NODE2"
 patchnode1$ = "BBS"
  nodelistdatabase$(2, 5) = NTC$
Case Is = "3", "NODE3"
 patchnode4$ = "BBS"
  nodelistdatabase$(3, 5) = NTC$
Case Is = "4", "NODE4"
 patchnode4$ = "BBS"
  nodelistdatabase$(4, 5) = NTC$
Case Is = "5", "NODE5"
 patchnode5$ = "BBS"
  nodelistdatabase$(5, 5) = NTC$

Case Is = "6", "NODE6"
 patchnode6$ = "BBS"
  nodelistdatabase$(6, 5) = NTC$
Case Is = "7", "NODE7"
 patchnode7$ = "BBS"
  nodelistdatabase$(7, 5) = NTC$
Case Is = "8", "NODE8"
 patchnode8$ = "BBS"
  nodelistdatabase$(8, 5) = NTC$
Case Is = "9", "NODE9"
 patchnode9$ = "BBS"
  nodelistdatabase$(9, 5) = NTC$
Case Is = "10", "NODE10"
 PATCHNODE10$ = "BBS"
  nodelistdatabase$(10, 5) = NTC$
Case Is = "11", "NODE11"
 PATCHNODE11$ = "BBS"
  nodelistdatabase$(11, 5) = NTC$
Case Is = "12", "NODE12"
 PATCHNODE12$ = "BBS"
  nodelistdatabase$(12, 5) = NTC$
Case Is = "13", "NODE13"
 PATCHNODE13$ = "BBS"
  nodelistdatabase$(13, 5) = NTC$
Case Is = "14", "NODE14"
 PATCHNODE14$ = "BBS"
  nodelistdatabase$(14, 5) = NTC$
Case Is = "15", "NODE15"
 PATCHNODE15$ = "BBS"
  nodelistdatabase$(15, 5) = NTC$
Case Is = "16", "NODE16"
 PATCHNODE16$ = "BBS"
  nodelistdatabase$(16, 5) = NTC$
Case Is = "17", "NODE17"
 PATCHNODE17$ = "BBS"
  nodelistdatabase$(17, 5) = NTC$
Case Is = "18", "NODE18"
 PATCHNODE18$ = "BBS"
  nodelistdatabase$(18, 5) = NTC$
Case Is = "19", "NODE19"
 PATCHNODE19$ = "BBS"
  nodelistdatabase$(19, 5) = NTC$
Case Is = "20", "NODE20"
 PATCHNODE21$ = "BBS"
  nodelistdatabase$(20, 5) = NTC$
Case Is = "21", "NODE21"
 PATCHNODE21$ = "BBS"
  nodelistdatabase$(21, 5) = NTC$
   
End Select

End If


Loop Until EOF(FILENUM)

Close #FILENUM


Exit Sub
nomainuserstxt:
 Close #1
  OUTTOCRTTEXT$ = OUTTOCRTTEXT$ + " error accessing bbs user data."

End Sub


Public Sub buildinexp(TXT$, outtext$)
Dim RETVAL$
l = Len(TXT$)
outtext$ = ""

'If X <= (l) Then ch$ = Mid$(TXT$, X, 1)
'If X >= (l) Or ch$ = " " Or ch$ = "," Or ch$ = "+" Or ch$ = "-" Or ch$ = "*" Or ch$ = "/" Or ch$ = "(" Or ch$ = ")" Then
'   var$ = WD$
'   Call cut32(var$, retval$)
'   var$ = retval$
'   Call getvar(var$, retval$)
'   WD$ = ""
'   outtext$ = outtext + retval$
'End If

q = 1
cmd$ = TXT$ + " "
Do

'WD$ = WD$ + ch$

Call gnpart(cmd$, otxt$, q)
q = q - 1
var$ = otxt$
Call cut32(var$, RETVAL$)
   var$ = RETVAL$
   Call getvar(var$, RETVAL$)
   WD$ = ""
   outtext$ = outtext + RETVAL$ + " "
q = q + 1
Loop Until q > (l)
'Debug.Print "outtext$ "; ouTtext$

End Sub







Public Sub putval(var$, putvaR$)
ext = 0
Do
ch$ = varrs$(x, 0)
If ch$ = "" Or ch$ = (var$) Then varrs$(x, 0) = var$: varrs$(x, 1) = putvaR$: ext = 1
x = x + 1
Loop Until x >= 200 Or ext = 1
End Sub

Public Sub GRPRINT(v1, V2, v3, NODEREST3$)
Dim RETVAL$
v1 = Val(v1)
V2 = Val(V2)
v3 = Val(v3)
g$ = UCase$(groutputdevice$)
Select Case (g$)
   Case Is = "GR"
      GR.PSet (v1, V2), QBColor(v3)
      GR.Print NODEREST3$
   Case Is = "VRWINDOW"
      VRwindow.PSet (v1, V2), QBColor(v3)
      VRwindow.Print NODEREST3$
   
   Case Else
    
    n$ = UCase$(groutputdevice$)
     var$ = n$
      Call cut32(var$, RETVAL$)
       n$ = RETVAL$
    var$ = "GR? " + Str$(v1) + "," + Str$(V2) + "," + Str$(v3) + "," + NODEREST3$
    
    'Call cut32(var$, retval$)
    
    noderest$ = var$
   ' retval$
    Debug.Print "grcon "; n$; " - "; noderest$
    Call NODEOUT(n$, noderest$ + CR$)
      
 End Select
End Sub

Public Function CONVRTSMLINT(RETVAL$) As Integer
l = Len(RETVAL$)
If l < 8 Then
CONVRTSMLINT = Val(RETVAL$)
Else
CONVRTSMLINT = 0
End If
End Function


Public Sub getvar(var$, RETVAL$)

If Left$(var$, 1) = Chr$(34) Then
   RETVAL$ = var$
Else
   On Error GoTo BADVAR:
   z = Val(var$)
   If z <> 0 Then
    RETVAL$ = var$
   Else

    x = 0
    Do
    ch$ = varrs$(x, 0)
    If ch$ = (var$) Then RETVAL$ = varrs$(x, 1)
    x = x + 1
    Loop Until x >= 200

    End If
  End If
If RETVAL$ = "" Then RETVAL$ = var$
var$ = UCase$(var$)
'Debug.Print "evaluating ..."; var$; "-"
Select Case (var$)
Case Is = "BIGINT"
RETVAL$ = BIGINTVAR$
Case Is = "RAMDISK$"
RETVAL$ = ""

Case Is = "DATE$"
RETVAL$ = Date$
Case Is = "TIME$"
RETVAL$ = Time$
Case Is = "MOUSEX"
        RETVAL$ = Str$(mousex)
Case Is = "MOUSEY"
        RETVAL$ = Str$(mousey)
Case Is = "MOUSEBUTTON"
        RETVAL$ = Str$(mousebutton)
Case Is = "GRMOUSEX"
        RETVAL$ = Str$(grmousex)
Case Is = "GRMOUSEY"
        RETVAL$ = Str$(grmousey)
Case Is = "GRBUTTON"
        RETVAL$ = Str$(grbutton)
        
Case Is = "JOY0HVAL"
        RETVAL$ = Joystickdebug.label1
Case Is = "JOY0VVAL"
        RETVAL$ = Joystickdebug.Label2
Case Is = "JOYBUT0"
        RETVAL$ = Joystickdebug.Label3
Case Is = "JOY1HVAL"
        RETVAL$ = Joystickdebug.Label5
Case Is = "JOY1VVAL"
        RETVAL$ = Joystickdebug.Label6
Case Is = "JOYBUT1"
        RETVAL$ = Joystickdebug.Label7
        




Case Is = "DRAWQA"
       RETVAL$ = Str$(DRAWQA)
Case Is = "DRAWTA"
       RETVAL$ = Str$(DRAWTA)
End Select
Exit Sub
BADVAR:
RETVAR$ = var$

End Sub


Sub gnpart(cmd$, otxt$, q)

ll = Len(cmd$)
If q <= (ll) Then
If q = 0 Then q = 1

otxt$ = ""
ch$ = ""


 ch$ = Mid$(cmd$, q, 1)
If ch$ = Chr$(34) Then
 ext = 1
 otxt$ = otxt$ + ch$
  q = q + 1
  Do
    ch$ = Mid$(cmd$, q, 1)
  otxt$ = otxt$ + ch$
  q = q + 1
  Loop Until ch$ = Chr$(34) Or q > (ll)
Debug.Print "chr$(34) " + otxt$
End If

If ext = 0 Then

Do
 
  ch$ = Mid$(cmd$, q, 1)

If ch$ <> "=" And ch$ <> "," And ch$ <> ":" And ch$ <> "(" And ch$ <> ")" And ch$ <> Chr$(32) And ch$ <> Chr$(34) Then
otxt$ = otxt$ + ch$
End If

If q <= (ll) Then
  q = q + 1
End If
If q + 1 <= (l1) Then nch$ = Mid$(cmd$, q + 1, 1)

Loop Until nch$ = Chr$(32) Or ch$ = "=" Or ch$ = Chr$(13) Or ch$ = ":" Or ch$ = "," Or ch$ = Chr$(34) Or ch$ = Chr$(32) Or q >= (ll)

End If
End If

End Sub





Public Sub PUTBBSCHOICE(p1$, p2$, NODEREST2$)

cx = 0
Do
ch$ = BBSCHOICE$(cx, 0)


If ch$ = (p1$) Or ch$ = "" Then
   BBSCHOICE$(cx, 0) = p1$
   BBSCHOICE$(cx, 1) = p2$
   BBSCHOICE$(cx, 2) = NODEREST2$
End If
cx = cx + 1


Loop Until ch$ = (p1$) Or ch$ = "" Or cx >= 100

End Sub

