Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 496
» Latest member: braveparrot
» Forum threads: 2,846
» Forum posts: 26,669

Full Statistics

Latest Threads
Editor WIP
Forum: bplus
Last Post: aadityap0901
4 hours ago
» Replies: 12
» Views: 665
QBJS v0.9.0 - Release
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
7 hours ago
» Replies: 14
» Views: 221
1990's 3D Doom-Like Walls...
Forum: Programs
Last Post: SierraKen
7 hours ago
» Replies: 7
» Views: 226
Fun with Ray Casting
Forum: a740g
Last Post: a740g
11 hours ago
» Replies: 2
» Views: 66
Big problem for me.
Forum: General Discussion
Last Post: bplus
Today, 12:20 AM
» Replies: 7
» Views: 86
discover graphics with xa...
Forum: Programs
Last Post: hsiangch_ong
Yesterday, 10:39 PM
» Replies: 0
» Views: 28
another variation of "10 ...
Forum: Programs
Last Post: Jack002
Yesterday, 10:05 PM
» Replies: 37
» Views: 571
Aloha from Maui guys.
Forum: General Discussion
Last Post: doppler
Yesterday, 03:32 PM
» Replies: 14
» Views: 349
Cautionary tale of open, ...
Forum: General Discussion
Last Post: doppler
Yesterday, 03:28 PM
» Replies: 0
» Views: 31
Extended KotD #22: _MOUSE...
Forum: Keyword of the Day!
Last Post: SMcNeill
Yesterday, 12:29 AM
» Replies: 0
» Views: 57

 
  Tree + lights + options
Posted by: bplus - 12-18-2022, 08:05 PM - Forum: Christmas Code - Replies (16)

Code: (Select All)
Option _Explicit
_Title "Programmable Tree Lights v2" ' b+ 2020-12-19 2022-12-18 fixed k$
Randomize Timer
Const Xmax = 700, Ymax = 700, N_Rows = 10, N_Cols = 2 * N_Rows - 1
Const X_Spacer = 30, Y_Spacer = 52, X_Offset = 50
Type ColorSeed
    Red As Single
    Green As Single
    Blue As Single
End Type
Dim Shared ColorSet(10) As ColorSeed, ColorSetIndex As Long
Dim Shared pR, pG, pB, pN, pStart, pMode$
Dim Shared TG(1 To N_Cols, 1 To N_Rows) As Long
Screen _NewImage(Xmax, Ymax, 32)
_Delay .25
_ScreenMove _Middle
Dim As Long i, row, Col, nstars, back, cc
Dim horizon, r, land
Dim l$, o$, b$, k$
' setup some color seeds in ColorSet user can change out with Shift + digit key
For i = 0 To 9 ' 10 random color seeds
    resetPlasma
    ColorSet(i).Red = pR: ColorSet(i).Green = pG: ColorSet(i).Blue = pB
Next

'Stringing the lights on tree, adjusted to fit mostly on the tree   2*N - 1 Pryramid
For row = 1 To 10
    l$ = xStr$(2 * row - 1, "X")
    o$ = xStr$(10 - row, "O")
    b$ = o$ + l$ + o$
    For Col = 1 To N_Cols
        If Mid$(b$, Col, 1) = "O" Then TG(Col, row) = 0 Else TG(Col, row) = -1
    Next
    Print b$
Next

' making the stars
horizon = Ymax - 4 * r
nstars = 100
Dim xstar(100), ystar(100), rstar(100)
For i = 1 To 100
    xstar(i) = Rnd * (Xmax): ystar(i) = Rnd * horizon:
    If i < 75 Then
        rstar(i) = 0
    ElseIf i < 95 Then
        rstar(i) = 1
    Else
        rstar(i) = 2
    End If
Next
Cls
' make a circle tree and align circles to tree with spacers and offsets with new Pyramid Scheme
'Pinetree 25, 30, 650, 600
'FOR row = 1 TO N_Rows
'    FOR col = 1 TO N_Cols
'        IF TG(col, row) THEN CIRCLE (col * X_Spacer + X_Offset, row * Y_Spacer), 10
'    NEXT
'NEXT

' making the background
back = _NewImage(_Width, _Height, 32)
Cls
horizon = Ymax - 100
For i = 0 To horizon
    Line (0, i)-(Xmax, i), _RGB32(i / horizon * 70, i / horizon * 22, 60 * (i) / horizon)
Next
land = Ymax - horizon
For i = horizon To Ymax
    cc = 128 + (i - horizon) / land * 127
    Line (0, i)-(Xmax, i), _RGB32(cc, cc, cc)
Next
For i = 1 To 100
    fcirc xstar(i), ystar(i), rstar(i), &HFFEEEEFF
Next
_PutImage , 0, back

ColorSetIndex = 1: pMode$ = "h"
show ' avoid the pause for key checking
Do
    k$ = InKey$
    If Len(k$) Then
        If InStr("0123456789", k$) > 0 Then
            ColorSetIndex = Val(k$)
        ElseIf InStr("vhde", k$) > 0 Then
            pMode$ = k$
        End If
    End If
    _PutImage , back, 0
    show
    _Display
    _Limit 10
Loop Until _KeyDown(27)

Sub show
    Dim row, prow, col
    Pinetree 25, 30, 650, 600
    _Title "Programmable Tree Lights (0-9) Color Set: " + TS$(ColorSetIndex) + "  (v, h, d, e) Mode: " + pMode$
    pR = ColorSet(ColorSetIndex).Red: pG = ColorSet(ColorSetIndex).Green: pB = ColorSet(ColorSetIndex).Blue
    pStart = pStart + 1
    Select Case pMode$
        Case "h"
            For row = 1 To N_Rows
                prow = pStart + row
                For col = 1 To N_Cols
                    pN = prow
                    If TG(col, row) Then Lite col * X_Spacer + X_Offset, row * Y_Spacer, Plasma~&
                Next
            Next
        Case "v"
            For row = 1 To N_Rows
                For col = 1 To N_Cols
                    pN = pStart + col
                    If TG(col, row) Then Lite col * X_Spacer + X_Offset, row * Y_Spacer, Plasma~&
                Next
            Next
        Case "d"
            For row = 1 To N_Rows
                For col = 1 To N_Cols
                    pN = pStart + col - row
                    If TG(col, row) Then Lite col * X_Spacer + X_Offset, row * Y_Spacer, Plasma~&
                Next
            Next
        Case "e"
            For row = 1 To N_Rows
                For col = 1 To N_Cols
                    pN = pStart + row + col
                    If TG(col, row) Then Lite col * X_Spacer + X_Offset, row * Y_Spacer, Plasma~&
                Next
            Next

    End Select
End Sub

Sub Lite (x, y, c As _Unsigned Long)
    Dim cR, cG, cB, cA, r
    cAnalysis c, cR, cG, cB, cA
    For r = 35 To 0 Step -2
        fcirc x, y, r, _RGB32(cR, cG, cB, 1)
    Next
    fcirc x, y, 4, c
End Sub

Sub Pinetree (treeX, treeY, wide, high)
    Dim bpx, bpy, tpx, bpxx, bpyy, aa, ra, tpy, ht, xs, xsh, rs, tpxx, tpyy, fra, x1, x2, y1, y2, wf, hf
    'tannen baum by PeterMaria W  orig 440x460
    'fits here  LINE (0, 0)-(440, 410), , B
    Static t&
    If t& = 0 Then
        t& = _NewImage(440, 410, 32)
        _Dest t&
        bpx = 220: bpy = 410
        tpx = bpx
        For aa = -4 To 4
            bpxx = bpx + aa
            bpyy = bpy - 390
            Line (bpxx, bpy)-(bpx, bpyy), _RGB32(30, 30, 0)
        Next
        ra = 160
        tpy = bpy - 40
        For ht = 1 To 40
            For xs = -100 To 100 Step 40
                xsh = xs / 100
                rs = Rnd * 4 / 10
                tpxx = tpx + (xsh * ra)
                tpyy = tpy - rs * ra
                Line (tpx, tpy)-(tpxx, tpyy), _RGB32(50, 40, 20)
                For aa = 1 To 30
                    fra = Rnd * 10 / 10 * ra
                    x1 = tpx + (xsh * fra)
                    y1 = tpy - rs * fra
                    x2 = tpx + xsh * (fra + ra / 5)
                    y2 = tpy - rs * fra + (-rs + (Rnd * 8) / 10 - 0.4) * (ra / 5)
                    Line (x1, y1)-(x2, y2), _RGB32(Rnd * 80, Rnd * 70 + 40, Rnd * 60)
                Next
            Next
            ra = ra - 4
            tpy = tpy - 9
        Next
        _Dest 0
    End If
    wf = wide / 440: hf = high / 410
    _PutImage (treeX, treeY)-Step(440 * wf, 410 * hf), t&, 0
End Sub

Sub cAnalysis (c As _Unsigned Long, outRed, outGrn, outBlu, outAlp)
    outRed = _Red32(c): outGrn = _Green32(c): outBlu = _Blue32(c): outAlp = _Alpha32(c)
End Sub

Function Plasma~& ()
    pN = pN + 1 'dim shared cN as _Integer64, pR as integer, pG as integer, pB as integer
    Plasma~& = _RGB32(127 + 127 * Sin(pR * pN), 127 + 127 * Sin(pG * pN), 127 + 127 * Sin(pB * pN))
End Function

Sub resetPlasma ()
    pR = Rnd ^ 2: pG = Rnd ^ 2: pB = Rnd ^ 2: pN = 0
End Sub

Function xStr$ (x, strng$)
    Dim i, rtn$
    For i = 1 To x
        rtn$ = rtn$ + strng$
    Next
    xStr$ = rtn$
End Function

Function TS$ (n As Integer)
    TS$ = _Trim$(Str$(n))
End Function

'from Steve Gold standard
Sub fcirc (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
    Dim Radius As Integer, RadiusError As Integer
    Dim X As Integer, Y As Integer
    Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
    If Radius = 0 Then PSet (CX, CY), C: Exit Sub
    Line (CX - X, CY)-(CX + X, CY), C, BF
    While X > Y
        RadiusError = RadiusError + Y * 2 + 1
        If RadiusError >= 0 Then
            If X <> Y + 1 Then
                Line (CX - Y, CY - X)-(CX + Y, CY - X), C
                Line (CX - Y, CY + X)-(CX + Y, CY + X), C
            End If
            X = X - 1
            RadiusError = RadiusError - X * 2
        End If
        Y = Y + 1
        Line (CX - X, CY - Y)-(CX + X, CY - Y), C
        Line (CX - X, CY + Y)-(CX + X, CY + Y), C
    Wend
End Sub

   
   
   
   

Print this item

  Merry Christmas Banner
Posted by: bplus - 12-18-2022, 07:58 PM - Forum: Christmas Code - No Replies

Since someone took down the code that had nice trees and snow fall...

Code: (Select All)
'$INCLUDE:'SaveImage.BI'

Const SaveTextAs256Color = 0 'Flag to Save as 256 color file or 32-bit color file, when converting SCREEN 0 to an image
'                             Set to TRUE (any non-zero value) to save text screens in 256 color mode.
'                             Set to FALSE (zero) to save text screens in 32-bit color mode.

_Title "Winter Christmas Theme Banner 11, space to take snap, escape for new tree layout" ' b+ 2022-11-07 Banner 5 with better and Rnd  Pine Trees
'started from Snowjob code

Const XMAX = 1235
Const YMAX = 256
Screen _NewImage(XMAX, YMAX, 32)
_ScreenMove 0, 100

'snow making machine
Type PARTICLE
    x As Single
    y As Single
    dx As Single
    dy As Single
    size As Single
    density As Single
    angle As Single
    dir As Single
    maxy As Single
End Type

Const nTrees = 70
Dim As Long logo, santa, fnt, wallpaper, t
ReDim savefile As String
savefile = "Merry Christmas Banner 2022.png"
'logo = _LoadImage("peLogo.png")
'santa = _LoadImage("Kindpng_301203.png")
'_ClearColor &HFFFFFFFF, santa
fnt = _LoadFont("FROSW___.ttf", 100)

restart: ' new wallpaper background
If wallpaper <= -1 Then _FreeImage wallpaper ' avoid memory leak
wallpaper = _NewImage(XMAX, YMAX, 32)
_Font fnt, wallpaper
_PrintMode _KeepBackground , wallpaper
_Dest wallpaper
drawLandscape
For t = 1 To nTrees
    NewTree wallpaper
Next
'_PutImage (25, 18)-Step(220, 220), logo, wallpaper
_Dest wallpaper
'_PutImage (1207, 127)-Step(50, 87), santa, wallpaper
Color _RGB32(200, 0, 0)
_PrintString (10, 120), "Merry Christmas 2022", wallpaper
_Dest 0

Dim As Long nLayers, flakes, layer, flake
Dim horizon
nLayers = 15
flakes = 2 ^ (nLayers + 1) - 1
ReDim snow(flakes) As PARTICLE
horizon = .5 * YMAX
For layer = nLayers To 1 Step -1
    For flake = 0 To 2 ^ layer
        snow(flake).x = Rnd * 2 * XMAX - .5 * XMAX
        snow(flake).y = Rnd * 2 * YMAX - YMAX ' <<<<<<<<<<<<<< fix clear clearing when first start by spreading over 2 screens
        snow(flake).dx = .1 * (nLayers + 1 - layer) * Cos(Rnd * _Pi(.6666) + _Pi(.0833))
        If snow(flake).dx < -.2 Then snow(flake).dx = -snow(flake).dx '              <<<<<<<<<<<<< add a little wind
        snow(flake).dy = .1 * (nLayers + 1 - layer) * Sin(Rnd * _Pi(.6666) + _Pi(.0833))
        If snow(flake).dy < .2 Then snow(flake).dy = .2 '                       <<<<<<<<<<<<<< make sure everything is falling
        snow(flake).size = .5 * (nLayers - layer)
        snow(flake).density = 2.3 + Rnd * .5
        snow(flake).angle = Rnd * _Pi
        If Rnd < .5 Then snow(flake).dir = -1 Else snow(flake).dir = 1
        snow(flake).maxy = horizon + (nLayers + 1 - layer) * 30
    Next
Next

Dim k$
Dim result
While _KeyDown(27) = 0 ' <<<<<<<<<<<<< allow escape from full screen
    _PutImage , wallpaper&, 0

    k$ = InKey$
    For flake = flakes To 0 Step -1
        If Rnd < .2 Then
            snow(flake).x = snow(flake).x + snow(flake).dx + Rnd * 2 - 1
            snow(flake).y = snow(flake).y + snow(flake).dy + Rnd * 2 - 1
        Else
            snow(flake).x = snow(flake).x + snow(flake).dx
            snow(flake).y = snow(flake).y + snow(flake).dy
        End If
        If snow(flake).size <= 1 Then
            PSet (snow(flake).x, snow(flake).y), _RGBA32(255, 255, 255, 80)
        ElseIf snow(flake).size <= 2 Then
            Circle (snow(flake).x, snow(flake).y), 1, _RGBA32(255, 255, 255, 100)
        Else
            snow(flake).angle = snow(flake).angle + snow(flake).dir * _Pi(1 / 100) ' <<<<<< turn flakes more
            rFlake snow(flake).x, snow(flake).y, snow(flake).size, snow(flake).density, snow(flake).angle
        End If
        If snow(flake).y > snow(flake).maxy Or snow(flake).x < -.5 * XMAX Or snow(flake).x > 1.5 * XMAX Then
            snow(flake).x = Rnd * 2 * XMAX - .5 * XMAX
            snow(flake).y = Rnd * YMAX - 1.1 * YMAX
        End If
    Next
    _Display
    If k$ = " " Then
        result = SaveImage(savefile, 0, 0, 0, _Width - 1, _Height - 1)
        If result = 1 Then 'file already found on drive
            Kill savefile 'delete the old file
            result = SaveImage(savefile, 0, 0, 0, _Width - 1, _Height - 1) 'save the new one again
        End If
        If result >= 0 Then Cls: Print "Save Failed": Beep: End ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<  beep = failed
    End If
    _Limit 60
Wend
GoTo restart

Sub rFlake (x, y, r, DV, rAng)
    'DV = flake density
    Dim As Long a
    Dim armX, armY
    Color _RGBA32(225, 225, 245, r ^ 2 * 30)
    For a = 0 To 5
        armX = x + r * Cos(a * _Pi(1 / 3) + rAng)
        armY = y + r * Sin(a * _Pi(1 / 3) + rAng)
        Line (x, y)-(armX, armY)
        If r > 2.5 Then rFlake armX, armY, r / DV, DV, rAng
    Next
End Sub

Sub midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
    Color _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
End Sub

Function rand% (lo%, hi%)
    rand% = Int(Rnd * (hi% - lo% + 1)) + lo%
End Function

Sub drawLandscape
    'needs midInk, rand
    'the sky
    Dim As Long i, rgb, mountain
    Dim startH, updown, range, lastX, Xright, y, x
    For i = 0 To .33 * YMAX
        midInk 120, 50, 100, 255, 255, 150, i / (.3 * YMAX) '<<<<<<<<<<<<  dark on top lighter redder lower
        Line (0, i)-(XMAX, i)
    Next
    'the land
    startH = .2 * YMAX
    rgb = 195 ' <<<<<<<<<<<<<<<<<<<<<< less white
    For mountain = 1 To 6
        Xright = 0
        y = startH
        While Xright < XMAX
            ' upDown = local up / down over range, change along Y
            ' range = how far up / down, along X
            updown = (Rnd * .8 - .35) / (mountain * 2)
            range = Xright + rand%(15, 35) * 3.5 / mountain
            lastX = Xright - 1
            Color _RGB32(rgb + 10 * mountain, rgb + 8 * mountain, rgb + 10 * mountain)
            For x = Xright To range
                y = y + updown
                Line (lastX, y)-(x, YMAX), , BF 'just lines weren't filling right
                lastX = x
            Next
            Xright = range
        Wend
        '_DELAY 1
        rgb = rand%(rgb, rgb + 20)
        startH = startH + rand%(5, 20)
    Next
End Sub

Sub NewTree (d&)
    Dim h, w
    horz = _Height - 135 - 60
    h = Rnd * 100 + 25
    w = h / 2 + Rnd * h / 8 - h / 16
    Pinetree _Width * Rnd, horz - .5 * h, w, h, d&
End Sub

Sub cAnalysis (c As _Unsigned Long, outRed, outGrn, outBlu, outAlp)
    outRed = _Red32(c): outGrn = _Green32(c): outBlu = _Blue32(c): outAlp = _Alpha32(c)
End Sub

Function Ink~& (c1 As _Unsigned Long, c2 As _Unsigned Long, fr##)
    Dim R1, G1, B1, A1, R2, G2, B2, A2
    cAnalysis c1, R1, G1, B1, A1
    cAnalysis c2, R2, G2, B2, A2
    Ink~& = _RGB32(R1 + (R2 - R1) * fr##, G1 + (G2 - G1) * fr##, B1 + (B2 - B1) * fr##, A1 + (A2 - A1) * fr##)
End Function

Sub Pinetree (treeX, treeY, wide, high, dst&)
    'tannen baum by PeterMaria W  orig 440x460
    'fits here  LINE (0, 0)-(440, 410), , B
    Dim t&, bpx, bpy, tpx, aa, bpxx, bpyy, x, y, ra, tpy, ht, xs, xsh, rs, tpxx, tpyy, fra, x1, x2, y1, y2, wf, hf
    t& = _NewImage(440, 410, 32)
    _Dest t&
    bpx = 220: bpy = 410
    tpx = bpx
    For aa = -4 To 4
        bpxx = bpx + aa
        bpyy = bpy - 390
        Line (x + bpxx, y + bpy)-(x + bpx, y + bpyy), _RGB32(30, 30, 0)
    Next
    ra = 160
    tpy = bpy - 40
    For ht = 1 To 40
        For xs = -100 To 100 Step 40
            xsh = xs / 100
            rs = Rnd * 4 / 10
            tpxx = tpx + (xsh * ra)
            tpyy = tpy - rs * ra
            Line (x + tpx, y + tpy)-(x + tpxx, y + tpyy), _RGB32(50, 40, 20)
            For aa = 1 To 30
                fra = Rnd * 10 / 10 * ra
                x1 = tpx + (xsh * fra)
                y1 = tpy - rs * fra
                x2 = tpx + xsh * (fra + ra / 5)
                y2 = tpy - rs * fra + (-rs + (Rnd * 8) / 10 - 0.4) * (ra / 5)
                Line (x + x1, y + y1)-(x + x2, y + y2), _RGB32(Rnd * 120, Rnd * 70 + 70, Rnd * 80)
            Next
        Next
        ra = ra - 4
        tpy = tpy - 9
    Next
    _Source t&
    For i = 1 To 30000
        x = Rnd * 440: y = Rnd * 410
        If Point(x, y) > 0 Then PSet (x, y), &HFFFFFFFF
    Next
    _Dest 0: _Source 0
    wf = wide / 440: hf = high / 410
    _PutImage (treeX, treeY)-Step(440 * wf, 410 * hf), t&, dst&
    _FreeImage t&
End Sub

'$INCLUDE:'SaveImage.BM'
Really nice pine trees! from Peter W code modified by me many a time, eg Tree + lights + options... https://qb64phoenix.com/forum/showthread...7#pid11787

Merry Christmas!
   



Attached Files
.zip   Christmas Banner 2022.zip (Size: 221.95 KB / Downloads: 61)
Print this item

  Merry Marquee
Posted by: James D Jarvis - 12-18-2022, 02:34 PM - Forum: Christmas Code - Replies (3)

A simple Marquee effect to display a horizontally scrolling seasonal message.


Code: (Select All)
'merry marquee
_Title "Merry Marquee"
Screen _NewImage(800, 288, 256)
msg = _NewImage(800, 288, 256)
_Dest msg
Color 8, 0
A$ = "        Have A MERRY CHRISTMAS and a HaPpY NeW YeAr !!!             "
Print A$
_Source msg
_Dest 0
Color 15, 0
pmax = Int((_Width) / 8)
prows = Len(A$) * 8
If prows < pmax Then
    maxp = prows
Else
    maxp = (prows + 1) - pmax
End If

For pstart = 0 To maxp
    _Limit 20
    Cls
    For y = 0 To 16
        x = 1
        Color 15, 0
        If Int(Rnd * 20) < 5 Then _PrintString (Int(Rnd * _Width), Int(Rnd * _Height)), "*"
        Do
            If Point(pstart - 1 + x, y) <> 0 Then
                Color Int(1 + Rnd * 8)
                Locate y + 2, x + 1
                Print Chr$(219)
            End If
            x = x + 1
        Loop Until x = pmax - 8
    Next y
    _Display
Next pstart

Print this item

  DAY 038: _MOUSEWHEEL
Posted by: Pete - 12-18-2022, 10:11 AM - Forum: Keyword of the Day! - No Replies

Pretty simple...

SYNTAX scrollAmount% = _MOUSEWHEEL

Usage: Track the scrolling increments of the mouse wheel.

Example:

Code: (Select All)
DIM x AS INTEGER
DO
    _LIMIT 30
    WHILE _MOUSEINPUT
        x = x + _MOUSEWHEEL ' Must be placed inside WHILE/WEND loop.
    WEND
    lb = _MOUSEBUTTON(1) ' Left mouse button. Better placed outside of WHILE/WEND loop.
    IF lb THEN x = 0 ' reset mousewheel counter.
    LOCATE 1, 1: PRINT x; " ";
LOOP


One thing to keep in mind is unlike most of the other _MOUSE... keywords, _MOUSEWHEEL has to be placed between WHILE _MOUSEINPUT and WEND statements to be read, not after it like the _MOUSEBUTTON statements.

Note: _MOUSEMOVEX and _MOUSEMOVEY is another example of _MOUSE keywords which need to b placed between, not after, the WHILE/WEND _MOUSEINPUT loop.


Now if you only want to know the direction of the mouse wheel, use SGN() as in...

Code: (Select All)
DIM AS INTEGER x, sgnx
DO
    _LIMIT 30
    WHILE _MOUSEINPUT
        x = x + _MOUSEWHEEL
    WEND
    lb = _MOUSEBUTTON(1) ' Left mouse button.
    IF lb THEN x = 0 ' reset mousewheel counter.
    sgnx = SGN(x - oldx): oldx = x
    LOCATE 1, 1: PRINT x; " ";: IF sgnx THEN PRINT sgnx; "  ";: IF sgnx = -1 THEN PRINT "Up  "; ELSE PRINT "Down"; "   ";
LOOP

Pete

Print this item

  program crashes about 20% of the time
Posted by: billythebull - 12-18-2022, 12:55 AM - Forum: Help Me! - Replies (21)


.txt   PITABLE.txt (Size: 44.47 KB / Downloads: 55) This program crashes about 20% of the time. Any help appreciated.

Code: (Select All)
'_FullScreen
Version$ = "Beta Version 0.31"
$ExeIcon:'ultpizza.ico'
_Icon
_Title "ULTIMATE PIZZA POS - POINT OF SALE" + "    " + Version$ + "    " + "© 2006-2016 MasterSoft LLC. All Rights Reserved."
_ScreenMove _Middle
Do '**********************************************************************************************************
    1

    K$ = "frank"
    result$ = _InputBox$("ULTIMATE PIZZA POS PASSWORD", "You must enter your password to run this program. If you forgot your password please see management", "")
    '_ScreenMove _Middle
    'If result$ = "" Then
    '_MessageBox "ENTER PASSWORD", "Password Field can not be empty", "error"
    'GoTo 1
    'Else
    If UCase$(result$) = UCase$(K$) Then
        Exit Do
        'Shell _DontWait "C:\Users\Bradley\Desktop\qb64pe_\ULTPIZZA-COUPONS.exe"
    ElseIf result$ = "" Then
        System
    Else
        _NotifyPopup "ERROR", "INCORRECT PASSWORD ENTERED", "warning"
        GoTo 1
    End If
Loop
'**********************************************************************************************************
_FullScreen
'_MOUSEHIDE
'**************************************************************************************************************
'********************************************** Shared Variables **********************************************
'**************************************************************************************************************
Const CTRL = 100306
Const ALT = 100308
Const F12 = 34304
Dim Shared useprinter
Dim Shared HF
Common Shared BK1
Dim Shared CN
Dim Shared ENDER
Dim Shared printstring3$
Dim Shared fontpath$
Dim Shared phone$
Dim Shared Back$
Dim Shared chkno
Dim Shared PRICE
Dim Shared VOIDS
Dim Shared REFUNDS
Dim Shared COUPCNT$
Dim Shared TOTALSALESCNT$
Dim Shared TOTALSALESCNT
Dim Shared COUPON
Dim Shared COUPCNT
Dim Shared code
Dim Shared Styper$
Dim Shared typer$
Dim Shared SALESTYPE$
Dim Shared taxrate
Dim Shared RECEIPT$
Dim Shared PP$
Dim Shared mask$
Dim Shared line1
Dim Shared row
Dim Shared page
Dim Shared M$
Dim Shared tax
Dim Shared DELCNT

Dim Shared VOIDCOUPDOLLARS
Dim Shared subtotal As _Integer64
ReDim Shared RECEIPT$(1100, 2)
Dim Shared DESCRIPTION$
Dim Shared total As _Integer64
Dim Shared ZSUBTOTAL As _Float
Dim Shared ZTAX As _Float
Dim Shared ZTOTAL As _Float
Dim Shared XSUBTOTAL As _Float
Dim Shared XTAX As _Float
Dim Shared XTOTAL As _Float
Dim Shared XCOUPON As _Float
Dim Shared del As _Integer64
Dim Shared TABLE$(540, 6, 1), PRICE$(4) ' FORMAT$(5), X(5)
Common Shared DESCRIPTION$(), PRICE(), LINES, OFFSET, INSTRUCT$(), F1, delivery, DELTIME, PICKTIME
Common Shared NAME1$, NAME$, STREET1$, STREET$, CITY1$, CITY$, FKEY(), opencode$
Common Shared PHONE1$, PHONE2$, LASTRECORD$, BK, USEMENU, MENU$(), MENULABEL$()
'**************************************************************************************************************
'**************************************** Turn on Screen Resizing *********************************************
'**************************************************************************************************************
$Resize:On
_Resize , _Smooth

'**************************************************************************************************************
'********************************************* Set Font Path **************************************************
'**************************************************************************************************************
fontpath$ = Environ$("SYSTEMROOT") + "\fonts\cour.ttf"
printstring3$ = "    " + "###"
'**************************************************************************************************************
'********************************************* Screen Settings ************************************************
'**************************************************************************************************************
DeskTop& = _ScreenImage ' *** Capture the Desktop image
DT_Width& = _Width(DeskTop&) - 27 ' *** Get the Desktop Width
DT_Height& = _Height(DeskTop&) ' *** Get the Desktop Height
MainScreen~& = _NewImage(DT_Width&, DT_Height&, 32) '1600, 900, 32)
Screen MainScreen~&
_ScreenMove (DT_Width& - _Width(MainScreen~&)) / 2, (DT_Height& - _Height(MainScreen~&)) / 2
_FullScreen

'**************************************************************************************************************
'**************************************** Set Title and Load Splash screen ************************************
'**************************************************************************************************************

i& = _LoadImage("pizzasplash.jpg", 32)
_Icon i&
Screen i&
Sleep 10
Rem $DYNAMIC
Screen 0, 0, 0, 0: Cls
Dim MENU$(1): MENU$(0) = "MENU1": MENU$(1) = "MENU2"
Dim INSTRUCT$(7), FKEY(20, 2), MENULABEL$(20)

Call BEGINNING

'**************************************************************************************************************
'****************************** Open and Read table.dat and load arrays into memory ***************************
'**************************************************************************************************************

Sub MENUCHOICE
    Screen 0, 0, 23, 23
    View Print 1 To 25
    If CsrLin <> 25 Then Print Else flag = 1
    If CsrLin = 25 And flag = 1 Then Locate 25, 1:
    font& = _LoadFont(fontpath$, 20, "MONOSPACE,BOLD")
    _Font font&

    Color 14, 1
    Print Chr$(201) + String$(78, Chr$(205)) + Chr$(187)
    For a = 1 To 2
        Print Chr$(186) + String$(78, Chr$(255)) + Chr$(186)
    Next a
    Print Chr$(204) + String$(50, Chr$(205)) + Chr$(209) + String$(27, Chr$(205)) + Chr$(185)
    For a = 1 To 19
        Print Chr$(186) + String$(50, Chr$(255)) + Chr$(179) + String$(27, Chr$(255)) + Chr$(186)
    Next a
    Print Chr$(200) + String$(50, Chr$(205)) + Chr$(207) + String$(27, Chr$(205)) + Chr$(188)
    Color 15, 12
    Locate 2, 14: Print "              P I Z Z A  O P T I O N S                  "
    Locate 3, 14: Print "                  M A I N  M E N U                      "
    Color 15, 5
    Locate 21, 5: Print "**  PLEASE SEE DESCRIPTION TO THE RIGHT  **"
    Color 15, 13
    Locate 6, 5: Print "PRESS THE F KEY or HIGHLIGHT SELECTION FROM"
    Locate 7, 5: Print "BELOW USING" + " " + Chr$(24) + Chr$(25) + " AND PRESS ENTER TO SELECT.  "
    Color 15, 11
    For a = 8 To 20
        Locate a, 5: Print String$(43, Chr$(255)) ' menu header
    Next a

    Start:
    Option Base 1
    Dim MenuItem(8) As String * 30 'define the menu item array
    Dim ChooseItem As Integer ' currently chossen menu item
    Dim XMenuPosn As Integer 'controls menu x positions
    Dim YMenuPosn As Integer 'controls menu y position
    Dim Count As Integer
    Dim EndMenu As Integer

    ' menu items

    MenuItem$(1) = "F1 - Z READING REPORT    "
    MenuItem$(2) = "F2 - X READING REPORT    "
    MenuItem$(3) = "F3 - VOID/REPRINT CHK    "
    MenuItem$(4) = "F4 - CHECK TICKET STATUS "
    MenuItem$(5) = "F5 - RING UP A SALE      "
    MenuItem$(6) = "F6 - RTN TO MAIN SCREEN  "
    MenuItem$(7) = "F7 - EXIT PIZZA PROGRAM  "
    MenuItem$(8) = "F8 - STOCK TABLE SETTINGS"
    ChooseItem = 1 'Starting point of highlighted menu item
    XMenuPosn = 26 'X starting point of menu
    YMenuPosn = 10 'Y starting point of menu
    GoSub DrawMenu
    Do
        Cmmnd$ = (InKey$)
        If Len(Cmmnd$) = 2 Then Cmmnd$ = Right$(Cmmnd$, 1)

        If Cmmnd$ = "8" Or Cmmnd$ = Chr$(72) Then GoSub MoveUp
        If Cmmnd$ = "2" Or Cmmnd$ = Chr$(80) Then GoSub MoveDown
        If Cmmnd$ = "7" Or Cmmnd$ = Chr$(71) Then ChooseItem = 1
        If Cmmnd$ = "1" Or Cmmnd$ = Chr$(79) Then ChooseItem = UBound(MenuItem)

        If Cmmnd$ = Chr$(13) Then EndMenu = 1
        If Cmmnd$ = Chr$(59) Or Cmmnd$ = Chr$(30) Then
            ChooseItem = 1
            'EndMenu = 1
        End If
        If Cmmnd$ = Chr$(60) Or Cmmnd$ = Chr$(19) Then
            ChooseItem = 2
            'EndMenu = 1
        End If
        If Cmmnd$ = Chr$(61) Or Cmmnd$ = Chr$(50) Then
            ChooseItem = 3
            'EndMenu = 1
        End If
        If Cmmnd$ = Chr$(62) Or Cmmnd$ = Chr$(31) Then
            ChooseItem = 4
            'EndMenu = 1
        End If
        If Cmmnd$ = Chr$(63) Or Cmmnd$ = Chr$(25) Then
            ChooseItem = 5
            'EndMenu = 1
        End If
        If Cmmnd$ = Chr$(64) Or Cmmnd$ = Chr$(32) Then
            ChooseItem = 6
            'EndMenu = 1
        End If
        If Cmmnd$ = Chr$(65) Or Cmmnd$ = Chr$(16) Then
            ChooseItem = 7
            EndMenu = 1
        End If

        If Cmmnd$ = Chr$(66) Or Cmmnd$ = Chr$(16) Then
            ChooseItem = 8
        End If


        If ChooseItem = 1 Then
            Color 15, 1
            GoSub ClearSidePanel
            Locate 6, 53: Print "This Option Displays The  "
            Locate 7, 53: Print "Sales Information Over    "
            Locate 8, 53: Print "The Life Of The Register  "
            Locate 9, 53: Print "And Can Not Be Cleared.    "
            Locate 12, 53: Print "Options Include:          "
            Locate 14, 53: Print "Print Data To the Screen  "
            Locate 16, 53: Print "Print Z-Report On Printer  "
            Color 15, 3
        ElseIf ChooseItem = 2 Then
            Color 15, 1
            GoSub ClearSidePanel
            Locate 6, 53: Print "Display The X-Report Screen"
            Locate 7, 53: Print "And Gives You A Quick snap-"
            Locate 8, 53: Print "Shot Of Cash Drawer Sales  "
            Locate 10, 53: Print "Options Include:          "
            Locate 12, 53: Print "Display report on-screen  "
            Locate 14, 53: Print "Print without Clearing Sale"
            Locate 15, 53: Print "Data File To Zero"
            Locate 17, 53: Print "Print X-Report and Clear  "
            Locate 18, 53: Print "All Sales Data To Zero.    "

            Color 15, 3
        ElseIf ChooseItem = 3 Then
            Color 15, 1
            GoSub ClearSidePanel
            Locate 10, 53: Print "  Void/Reprint Options:  "
            Locate 12, 53: Print "      Void A Sale        "
            Locate 14, 53: Print "    Reprint A Check      "
            Color 15, 3
        ElseIf ChooseItem = 4 Then
            Color 15, 1
            GoSub ClearSidePanel
            Locate 12, 53: Print "  Allows you to check the  "
            Locate 13, 53: Print "  Status of a order ticket "
            Locate 14, 53: Print "  Open, Closed, or Voided  "
            Color 15, 3
        ElseIf ChooseItem = 5 Then
            Color 15, 1
            GoSub ClearSidePanel
            Locate 12, 53: Print " Allows you to ring up a  "
            Locate 13, 53: Print " Customers order when they "
            Locate 14, 53: Print " come to pick it up        "
            Color 15, 3
        ElseIf ChooseItem = 6 Then
            Color 15, 1
            GoSub ClearSidePanel
            Locate 12, 53: Print "Exits Program Execution and"
            Locate 13, 53: Print "Returns Control Over To The"
            Locate 14, 53: Print "Main Program Order Screen. "
            Color 15, 3
        ElseIf ChooseItem = 7 Then
            Color 15, 1
            GoSub ClearSidePanel
            Locate 12, 53: Print "Exits Program Execution and"
            Locate 13, 53: Print "Returns Control Over To The"
            Locate 14, 53: Print "Operating System          "
            Color 15, 3
        End If
        If Len(Cmmnd$) = 2 Then Cmmnd$ = Right$(Cmmnd$, 1)
        GoSub DrawMenu
    Loop Until EndMenu = 1
    If ChooseItem = 1 Then Call GET_ZREPORT
    If ChooseItem = 2 Then Call GET_XREPORT
    If ChooseItem = 3 Then Call VOID
    If ChooseItem = 4 Then Call CHKSTATUS
    If ChooseItem = 5 Then F1 = 0: Call RINGSALE
    If ChooseItem = 6 Then MAIN
    If ChooseItem = 7 Then System
    If ChooseItem = 8 Then Run "NEWSTOCK21"
    MAIN
    Exit Sub

    ClearSidePanel:
    _Limit (10)
    For xx = 5 To 22
        Locate xx, 53: Print "                          "
    Next xx
    Return

    DrawMenu:

    Locate YMenuPosn, XMenuPosn
    For Counts = 1 To UBound(MenuItem$)
        If Counts = ChooseItem Then Color 6 Else Color 15
        Locate , 14: Print MenuItem$(Counts)
        Locate CsrLin, XMenuPosn
    Next Counts
    Return

    MoveUp:
    If ChooseItem = 1 Then
        ChooseItem = UBound(MenuItem$)
    Else
        ChooseItem = ChooseItem - 1
    End If
    Return

    MoveDown:
    If ChooseItem = UBound(MenuItem$) Then
        ChooseItem = 1
    Else
        ChooseItem = ChooseItem + 1
    End If
    Return
    exit1:
    System
End Sub

Sub BEGINNING
    PP$ = "##,###.##"
    a = 1100
    ReDim DESCRIPTION$(a), PRICE(a) ', FKEY(20, 1)
    Open "R", 1, "PITABLE.DB", 60
    Field #1, 24 As DESCRIBE$, 1 As CODE$
    For a = 1 To 4: Field #1, 26 + (a - 1) * 6 As A$, 6 As PRICE$(a): Next
    Field #1, 50 As A$, 2 As MENU$: Field #1, 60 As AA$
    For a = 1 To 360
        Get 1, a
        TABLE$(a, 0, 0) = DESCRIBE$: TABLE$(a, 1, 0) = CODE$
        For B = 1 To 4: TABLE$(a, B + 1, 0) = PRICE$(B): Next B
        TABLE$(a, 6, 0) = MENU$
    Next a
    For a = 1 To 360
        Get 1, a + 360
        TABLE$(a, 0, 1) = DESCRIBE$: TABLE$(a, 1, 1) = CODE$
        For B = 1 To 4: TABLE$(a, B + 1, 1) = PRICE$(B): Next B
        TABLE$(a, 6, 1) = MENU$
    Next a
    F$ = ""
    Get 1, 721
    For B = 0 To 2: For a = 1 To 20: FKEY(a, B) = Sgn(Asc(Mid$(AA$, a + B * 20, 1))): Next a, B
    For a = 1 To 20
        Get 1, a + 721: B$ = A$
        88 G = InStr(B$, Chr$(0)): If G > 0 Then Mid$(B$, G, 1) = " ": GoTo 88
        B$ = LTrim$(RTrim$(B$))
        B$ = Space$(12 - Len(B$) \ 2) + B$
        MENULABEL$(a) = B$
    Next a

    opencode$ = ""
    Get 1, 758: Q$ = Left$(A$, 6): For a = 1 To 6: opencode$ = opencode$ + Chr$(Asc(Mid$(A$, a, 1))): Next a
    For a = 6 To 1 Step -1
        If Mid$(opencode$, a, 1) <> Chr$(0) Then Exit For
    Next
    opencode$ = Left$(opencode$, a)

    useprinter = Sgn(Asc(Mid$(A$, 7, 1))) + 1
    Field #1, 9 As NULL$, 4 As T$: T& = CVL(T$): If T& < 0 Or T& > 99999 Then T& = 0
    taxrate = T& / 100000
    Field #1, 13 As NULL$, 4 As D$: D& = CVL(D$): If D& < 0 Or D& > 9999 Then D& = 0
    delivery = D& / 100
    Get 1, 759
    Field #1, 4 As DELTIME1$, 4 As PICKTIME1$
    DELTIME = CVL(DELTIME1$): If DELTIME < 0 Or DELTIME > 99 Then DELTIME = 0
    PICKTIME = CVL(PICKTIME1$): If PICKTIME < 0 Or PICKTIME > 99 Then PICKTIME = 0

    'pickup time and delivery time in record 759
    Close 1



    '                  ***************************************************************************
    '                  ***        Select Case to control main screen Destination              ***
    '                  ***************************************************************************
    Call MAIN
    1 A$ = "": While A$ = "": A$ = InKey$: Wend
    PP$ = "##,###.##"
    X = _KeyHit

    If A$ = Chr$(9) Then Call SEEMENUS(A$)
    If A$ = Chr$(43) Then Call PICKUP_DEL '        <===> Plus key press to display the Carry-Out Delivery menu
    If A$ = Chr$(0) + Chr$(59) Then Call Fkey_main(1) '  <=========================> F1 key press
    If A$ = Chr$(0) + Chr$(60) Then Call Fkey_main(2) '  <=========================> F2 key press
    If A$ = Chr$(0) + Chr$(61) Then Call Fkey_main(3) '  <=========================> F3 key press
    If A$ = Chr$(0) + Chr$(62) Then Call Fkey_main(4) '  <=========================> F4 key press
    If A$ = Chr$(0) + Chr$(63) Then Call Fkey_main(5) '  <=========================> F5 key press
    If A$ = Chr$(0) + Chr$(64) Then Call Fkey_main(6) '  <=========================> F6 key press
    If A$ = Chr$(0) + Chr$(65) Then Call Fkey_main(7) '  <=========================> F7 key press
    If A$ = Chr$(0) + Chr$(66) Then Call Fkey_main(8) '  <=========================> F8 key press
    If A$ = Chr$(0) + Chr$(67) Then Call Fkey_main(9) '  <=========================> F9 key press
    If A$ = Chr$(0) + Chr$(68) Then Call Fkey_main(10) ' <=========================> F10 key press
    If A$ = Chr$(0) + Chr$(71) Then Call Fkey_main(13) ' <=========================> Home Key press <=============> PAGE 13 = Fkey_13A
    If A$ = Chr$(0) + Chr$(79) Then Call Fkey_main(15) ' <=========================> END Key press  <=============> PAGE 14 = Fkey_14A
    If A$ = Chr$(0) + Chr$(82) Then Call Fkey_main(14) ' <=========================> INSERT Key press <===========> PAGE 15 = Fkey_15A
    If A$ = Chr$(0) + Chr$(83) Then Call Fkey_main(16) ' <=========================> DELETE Key press <===========> PAGE 16 = Fkey_16A
    If UCase$(A$) = "P" Then Call Fkey_main(17) '        <=========================> "P" Key press <===> PAGE 17 = Fkey_17A
    If UCase$(A$) = "L" Then Call Fkey_main(18) '        <=========================> "L" Key press <===> PAGE 18 = Fkey_18A
    If UCase$(A$) = "X" Then Call Fkey_main(19) '        <=========================> "X" Key press <===> PAGE 19 = Fkey_19A
    If UCase$(A$) = "Z" Then Call Fkey_main(20) '        <=========================> "Z" Key press <===> PAGE 20 = Fkey_20A
    If A$ = Chr$(0) + Chr$(133) Then Call Fkey_main(11) '<=========================> F11 key press
    If A$ = Chr$(0) + Chr$(134) Then Call Fkey_main(12) '<=========================> F12 key press
    If A$ = Chr$(0) + Chr$(111) Then Call CUSTINFO '    <=========================> ALT + F8 Combo key press
    If A$ = Chr$(0) + Chr$(112) Then Call TYPEINSTRUCTIONS '        <=========================> ALT + F9 Combo key press
    If UCase$(A$) = "R" And LINES > 0 Then '    <=========================> (R) or (r) key press
        Call REMOVELINE(DESCRIPTION$(), PRICE(), DESCRIPTION$, PRICE, LINES, line1) ' to remove line from sale
    End If
    If A$ = Chr$(0) + Chr$(140) Then
        Call MENUCHOICE
        Call SCROLL(DESCRIPTION$(), PRICE(), LINES, UPDOWN, DESCRIPTION$, PRICE, OFFSET, line1)
    End If
    If A$ = Chr$(0) + Chr$(72) Then '                <=======> Up Arrow Key Press to scroll the main order screen up
        UPDOWN = -1: Call SCROLL(DESCRIPTION$(), PRICE(), LINES, UPDOWN, DESCRIPTION$, PRICE, OFFSET, line1)
    End If
    If A$ = Chr$(0) + Chr$(80) Then '                        <===> Down Arrow Key Press to scroll the main order screen down
        UPDOWN = 1: Call SCROLL(DESCRIPTION$(), PRICE(), LINES, UPDOWN, DESCRIPTION$, PRICE, OFFSET, line1)
    End If
    If A$ = Chr$(0) + Chr$(118) Then System '  <===================> CTRL + Page Down Key Press to exit program
    If _KeyDown(CTRL) And _KeyDown(F12) Then
        Erase RECEIPT$
        ReDim RECEIPT$(1100, 2)
        Erase DESCRIPTION$
        Erase PRICE
        del = 0
        LINES = 0
        DESCRIPTION$ = ""
        COUPON = 0
        COUPCNT = 0
        TOTALSALESCNT = 0
        VOIDCOUPDOLLARS = 0
        PRICE = 0
        line1 = 0
        subtotal = 0
        tax = 0
        total = 0
        NAME1$ = ""
        STREET1$ = ""
        CITY1$ = ""
        PHONE1$ = ""
        typer$ = ""
        ReDim INSTRUCT$(7)
        Call BEGINNING
    End If

    GoTo 1
End Sub

'**************************************************************************************************************
'**************************************** Add Item to the order screen ****************************************
'**************************************************************************************************************
Sub ADDARRAY (RECEIPT$(), DESCRIPTION$, PRICE, line1)
    If LTrim$(DESCRIPTION$) <> "" Then
        line1 = line1 + 1
        RECEIPT$(line1, 1) = DESCRIPTION$
        RECEIPT$(line1, 2) = Str$(PRICE)
    Else
    End If
End Sub

'**************************************************************************************************************
'********************************* Get totals for items in the order screen ***********************************
'**************************************************************************************************************
Sub GETTOTALS
    'taxrate = VAL(TABLE$(540, 2, 0)) / 100
    subtotal = subtotal + PRICE
    del = delivery * 100
    tax = subtotal * taxrate
    If typer$ = "DELIVERY" Then
        total = subtotal + tax + del
    Else
        total = subtotal + tax: del = 0!
    End If
    PRICE = 0
    DESCRIPTION$ = ""
End Sub




Sub Fkey_main (pages)

    If FKEY(pages, 0) = 0 Then Exit Sub
    Color 12, 15
    PCopy 0, 1
    Screen 0, 0, 1, 1
    Color 0, 15
    page = pages
    row = 4
    OFFSET2 = pages * 18 - 27
    Call MENUS
    Color 4: Locate 2, 53: Print MENULABEL$(pages)
    Do
        WW: CHOOSE$ = "": While CHOOSE$ = "": CHOOSE$ = InKey$: Wend
        TablePointer = Asc(UCase$(CHOOSE$)) - 55
        If Asc(CHOOSE$) = 27 Or Asc(CHOOSE$) = 9 Then DESCRIPTION$ = "": Exit Do
        If TablePointer < 10 Or TablePointer > 27 Then GoTo WW
        DESCRIPTION$ = Mid$(TABLE$(OFFSET2 + TablePointer, 0, USEMENU), 1, 24)
        If FKEY(page, 2) = 1 Then
            If TablePointer = 10 Or TablePointer = 11 Or TablePointer = 12 Or TablePointer = 13 Then code = Val(TABLE$(OFFSET2 + TablePointer, 1, USEMENU))
        End If
        PRICETEMP = Val(TABLE$(OFFSET2 + TablePointer, 2, USEMENU))
        If code = 0 Then PRICE = Val(TABLE$(OFFSET2 + TablePointer, 2, USEMENU))
        If code = 1 Then PRICE = Val(TABLE$(OFFSET2 + TablePointer, 2, USEMENU))
        If code = 2 Then PRICE = Val(TABLE$(OFFSET2 + TablePointer, 3, USEMENU))
        If code = 3 Then PRICE = Val(TABLE$(OFFSET2 + TablePointer, 4, USEMENU))
        If code = 4 Then PRICE = Val(TABLE$(OFFSET2 + TablePointer, 5, USEMENU))
        If PRICE < 0 Then COUPCNT = COUPCNT + 1
        If PRICE < 0 Then COUPON = COUPON + PRICE

        If PRICETEMP <> 0 And PRICE = 0 Then PRICE = PRICETEMP
        Call SCROLL(DESCRIPTION$(), PRICE(), LINES, updown, DESCRIPTION$, PRICE, OFFSET, line1)
        Call ADDARRAY(RECEIPT$(), DESCRIPTION$, PRICE, line1)
        GETTOTALS
        PRINTTOTAL: row = 4: Color 0, 15: Call MENUS: Locate 2, 56: Color 4: Print MENULABEL$(pages)
        If FKEY(pages, 1) = 1 Then
            Exit Do
        End If
    Loop
    Screen 0, 0, 0, 0: Call PRINTTOTAL
    If liner <> LINES Then
        Call SCROLL(DESCRIPTION$(), PRICE(), LINES, updown, DESCRIPTION$, PRICE, OFFSET, line1)
        If FKEY(pages, 1) = 1 Then
            Call Fkey_sub(pages)
        End If
    End If
End Sub


Sub Fkey_sub (pages)
    If FKEY(pages, 1) = 1 Then USEMENU = 1
    Color 12, 15
    PCopy 0, 1
    Screen 0, 0, 1, 1
    Color 0, 15
    page = pages
    row = 4
    OFFSET2 = pages * 18 - 27
    Call MENUS
    Color 4: Locate 2, 56: Print MENULABEL$(pages)
    Do
        WW: CHOOSE$ = "": While CHOOSE$ = "": CHOOSE$ = InKey$: Wend
        TablePointer = Asc(UCase$(CHOOSE$)) - 55
        If Asc(CHOOSE$) = 27 Then DESCRIPTION$ = "": Exit Do
        If TablePointer < 10 Or TablePointer > 27 Then GoTo WW
        DESCRIPTION$ = Mid$(TABLE$(OFFSET2 + TablePointer, 0, USEMENU), 1, 24)
        PRICETEMP = Val(TABLE$(OFFSET2 + TablePointer, 2, USEMENU))
        If code = 0 Then PRICE = Val(TABLE$(OFFSET2 + TablePointer, 2, USEMENU))
        If code = 1 Then PRICE = Val(TABLE$(OFFSET2 + TablePointer, 2, USEMENU))
        If code = 2 Then PRICE = Val(TABLE$(OFFSET2 + TablePointer, 3, USEMENU))
        If code = 3 Then PRICE = Val(TABLE$(OFFSET2 + TablePointer, 4, USEMENU))
        If code = 4 Then PRICE = Val(TABLE$(OFFSET2 + TablePointer, 5, USEMENU))
        If PRICETEMP <> 0 And PRICE = 0 Then PRICE = PRICETEMP
        Call SCROLL(DESCRIPTION$(), PRICE(), LINES, updown, DESCRIPTION$, PRICE, OFFSET, line1)
        Call ADDARRAY(RECEIPT$(), DESCRIPTION$, PRICE, line1)
        GETTOTALS
        PRINTTOTAL: row = 4: Color 0, 15: Call MENUS: Locate 2, 56: Color 4: Print MENULABEL$(pages)
        Exit Do
    Loop
    USEMENU = USEMENU - USEMENU
    Screen 0, 0, 0, 0: Call PRINTTOTAL
    If liner <> LINES Then
        Call SCROLL(DESCRIPTION$(), PRICE(), LINES, updown, DESCRIPTION$, PRICE, OFFSET, line1)
    End If
End Sub

'                  ***************************************************************************
'                  ***                      Displays Main Order Screen                    ***
'                  ***************************************************************************
Rem $STATIC
Sub MAIN ()
    Screen 0, 0, 0, 0
    View Print 1 To 25
    If CsrLin = 25 And flag = 1 Then Locate 25, 1:
    If CsrLin <> 25 Then Print Else flag = 1
    font& = _LoadFont(fontpath$, 20, "MONOSPACE,BOLD")
    _Font font&
    Color 15, 1
    Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
    Print "º LINE          DESCRIPTION                PRICE º                          º"
    Print "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹                          º"
    Print "º                                                  º                          º"
    Print "º                                                  º                          º"
    Print "º                                                  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
    Print "º                                                  º    Special Instructions  º"
    Print "º                                                  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
    Print "º                                                  º                          º"
    Print "º                                                  º                          º"
    Print "º                                                  º                          º"
    Print "º                                                  º                          º"
    Print "º                                                  º                          º"
    Print "º                                                  º                          º"
    Print "º                                                  º                          º"
    Print "º                                                  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
    Print "º                                                  º                          º"
    Print "º                                                  º                          º"
    Print "º                                                  º                          º"
    Print "º                                                  º                          º"
    Print "º                                                  º                          º"
    Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
    Color 12, 1
    Print "[R] = REMOVE ITEM - [ALT] + [F9]  = Instructions  -  [ALT + F12] = Menu Options "
    'PRINT " [TAB] Show Menus                                                                            "
    Locate 24, 37: Print "                                                                                "
    If LTrim$(NAME1$ + STREET1$ + CITY1$ + PHONE1$) = "" Then
        Color 10, 6
        Locate 2, 54: Print "                        "
        Locate 3, 54: Print "PRESS [ALT + F8] TO ENTER"
        Locate 4, 54: Print "  CUSTOMER  INFORMATION  "
        Locate 5, 54: Print "                        "
    Else
        Color 15, 1: P$ = "\                      \" '' : ' <-There are 25 spaces between the back slashes
        Locate 2, 53: Print Using P$; NAME1$
        Locate 3, 53: Print Using P$; STREET1$
        Locate 4, 53: Print Using P$; CITY1$
        Call PHONES(mask$, PHONE1$, 1, 53, 5, 15, 1, Back$)
    End If

    Color 14, 1
    PRINTTOTAL
    Locate 17, 53: Print " Subtotal =====> "
    Locate 18, 53: Print "      Tax =====> "
    Locate 19, 53: Print "  Del Fee =====> "
    Locate 20, 71: Print "ÄÄÄÄÄÄÄÄÄ"
    Locate 21, 53: Print "Total Due =====> "
End Sub

'                  ***************************************************************************
'                  ***                  Displays the menus to the screen                  ***
'                  ***************************************************************************
Sub MENUS
    Locate 1, 52: Print Chr$(201) + String$(27, Chr$(205)) + Chr$(187)
    Locate 2, 52: Print Chr$(186) + Spc(27) + Chr$(186)
    Locate 3, 52: Print Chr$(204) + String$(27, Chr$(205)) + Chr$(185)
    For a = page * 18 - 17 To page * 18
        DESCRIPTION$ = Mid$(TABLE$(a, 0, USEMENU), 1, 24)
        M$ = Left$(TABLE$(a, 6, USEMENU), 2)
        If RTrim$(M$) <> "" Then
            Locate row, 52: Print Chr$(186) + Spc(27) + Chr$(186)
            Locate row, 53: row = row + 1
            Color 1,: Print M$ + " ";: Color 0,: Print DESCRIPTION$
        End If
    Next a
    Locate row, 52: Print Chr$(200) + String$(27, Chr$(205)) + Chr$(188)
    'END
End Sub

Rem $DYNAMIC
'                  ***************************************************************************
'                  ***              Displays the Customer information screen              ***
'                  ***************************************************************************
Sub CUSTINFO
    Screen 0, 0, 4, 4
    Color 15, 1: Cls: PCopy 0, 4
    Locate 1, 41: Print "ËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
    Locate 2, 41: Print "º                                      º"
    Locate 3, 41: Print "ÎÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
    Locate 4, 41: Print "º                                      º"
    Locate 5, 41: Print "º                                      º"
    Locate 6, 41: Print "º                                      º"
    Locate 7, 41: Print "º                                      º"
    Locate 8, 41: Print "ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ"
    Locate 9, 41: Print "º                                      º"
    Locate 10, 41: Print "º                                      º"
    Locate 11, 41: Print "º                                      º"
    Locate 12, 41: Print "ÈÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
    Locate 2, 51: Color 10,: Print "Customer Information"
    GoSub SHOWED
    If _FileExists("PIZZA.CST") Then Call OPENER: Get 1, 1: LASTRECORD = CVL(LASTRECORD$): Close 1
    GoSub SHOWED
    Locate 9, 42: Color 2: Print "[F1] = SEARCH  [F2] = GET  [F3] = SAVE"
    Locate 10, 42: Print "      [F4] = CLEAR  [ESC] = QUIT "
    Color 15, 1
    Locate 4, 42: Print "Name: "; NAME1$
    Locate 5, 42: Print "Address: "; STREET1$
    Locate 6, 42: Print "City: "; CITY1$
    Locate 7, 42: Print "Phone: ";
    Call PHONES(mask$, PHONE1$, 1, 48, 7, 15, 1, Back$)
    Do
        FCOLOR = 14: BCOLOR = 5: NUMB = 0
        I:
        77
        T = 0: X = 48: Y = 7
        Call PHONES(mask$, PHONE1$, T, X, Y, 14, 5, Back$)
        GoSub FUNCTIONS
        If T = 72 Then 66
        T = 0

        44 X = 48: Y = 4: LENGTHS = 27: NUMB = 0
        Call INPUTS(X, Y, FCOLOR, BCOLOR, LENGTHS, NUMB, NAME1$, KEYPRESS, 1)
        If KEYPRESS = 72 Then 77
        GoSub FUNCTIONS
        If KEYPRESS <> 13 And KEYPRESS <> 80 Then 44

        55 X = 50: Y = 5: LENGTHS = 27: NUMB = 0
        Call INPUTS(X, Y, FCOLOR, BCOLOR, LENGTHS, NUMB, STREET1$, KEYPRESS, 1)
        If KEYPRESS = 72 Then 44
        GoSub FUNCTIONS
        If KEYPRESS <> 13 And KEYPRESS <> 80 Then 55

        66 X = 48: Y = 6: LENGTHS = 27: NUMB = 0
        Call INPUTS(X, Y, FCOLOR, BCOLOR, LENGTHS, NUMB, CITY1$, KEYPRESS, 1)
        If KEYPRESS = 72 Then 55
        GoSub FUNCTIONS
        If KEYPRESS <> 13 And KEYPRESS <> 80 Then 66

        GoTo I
        FUNCTIONS:
        If KEYPRESS = 27 Or T = 27 Then Exit Do
        If KEYPRESS = 59 Or T = 59 Then
            PCopy 4, 6
            Call CHOICEBOX
            Locate 15, 10: Print "START SEARCH FROM HERE OR BEGINNING"
            Locate 16, 10: Print "[H]  [B]  [ESC] = QUIT"
            If Y = 4 Then SEARCH$ = LTrim$(RTrim$(UCase$(NAME1$)))
            If Y = 5 Then SEARCH$ = LTrim$(RTrim$(UCase$(STREET1$)))
            If Y = 6 Then SEARCH$ = LTrim$(RTrim$(UCase$(CITY1$)))
            If Y = 7 Then SEARCH$ = LTrim$(RTrim$(UCase$(PHONE1$)))
            FOUND = 0
            WW3: Close 1
            A$ = "": While A$ = "": A$ = UCase$(InKey$): Wend
            If Asc(A$) = 27 Then Close 1: GoSub CLEARS: Return
            If A$ <> "H" And A$ <> "B" Then GoTo WW3
            If A$ = "H" Then START = RECORDNUMBER + 1 Else START = 1
            Call OPENER
            For a = START To LASTRECORD
                Call GETTER(a)
                RECORDNUMBER = a: GoSub SHOWED
                If Y = 4 Then B = InStr(NAME1$, SEARCH$): If B Then FOUND = a: Exit For
                If Y = 5 Then B = InStr(STREET1$, SEARCH$): If B Then FOUND = a: Exit For
                If Y = 6 Then B = InStr(CITY1$, SEARCH$): If B Then FOUND = a: Exit For
                If Y = 7 Then B = InStr(PHONE1$, SEARCH$): If B Then FOUND = a: Exit For
            Next
            If FOUND = 0 Then
                RECORDNUMBER = 0
                NAME1$ = "": STREET1$ = "": CITY1$ = "": PHONE1$ = "": GoSub SHOWED
            Else
                Call GETTER(FOUND)
                RECORDNUMBER = FOUND: GoSub SHOWED
            End If
            GoTo WW3
        End If
        If KEYPRESS = 60 Or T = 60 Then

            PCopy 4, 6
            Call CHOICEBOX
            Locate 15, 10: Print "ENTER THE RECORD NUMBER YOU WANT OR"
            Locate 16, 10: Print "[PG UP] [PG DN]  [ESC] = QUIT"
            Call OPENER: N$ = ""
            WW1: Call INPUTS(40, 16, FCOLOR, BCOLOR, 5, 1, N$, KEYPRESS, 1)
            If KEYPRESS = 27 Then Close 1: GoSub CLEARS: Return
            If KEYPRESS = 73 And RECORDNUMBER > 1 Then
                RECORDNUMBER = RECORDNUMBER - 1: Call GETTER(RECORDNUMBER)
                GoSub SHOWED: GoTo WW1
            End If
            If KEYPRESS = 81 And RECORDNUMBER < LASTRECORD Then
                RECORDNUMBER = RECORDNUMBER + 1: Call GETTER(RECORDNUMBER)
                GoSub SHOWED: GoTo WW1
            End If
            If KEYPRESS = 13 Then
                N = Val(N$)
                If N > 0 And N < LASTRECORD + 1 Then
                    RECORDNUMBER = N: Call GETTER(RECORDNUMBER)
                    GoSub SHOWED: N$ = "": GoTo WW1
                End If
            End If
            GoTo WW1
        End If
        If KEYPRESS = 61 Or T = 61 Then
            If RECORDNUMBER <> 0 Then
                Call CHOICEBOX
                PCopy 4, 6
                Locate 15, 10: Print "SAVE AS CURRENT RECORD OR LAST RECORD"
                Locate 16, 10: Print "[C] [L]  [ESC] = QUIT              "
                WW: A$ = "": While A$ = "": A$ = UCase$(InKey$): Wend
                If A$ = Chr$(27) Then GoSub CLEARS: Return
                If A$ = "C" Then
                    Call OPENER: Call PUTTER(RECORDNUMBER): Close 1: GoSub CLEARS: Return
                End If
                If A$ <> "L" Then GoTo WW
            End If
            Call OPENER: LASTRECORD = LASTRECORD + 1: RECORDNUMBER = LASTRECORD
            Call PUTTER(RECORDNUMBER): LSet LASTRECORD$ = MKL$(RECORDNUMBER): Put 1, 1
            Close 1: GoSub CLEARS: GoSub SHOWED: Return
        End If
        If KEYPRESS = 62 Or T = 62 Then
            RECORDNUMBER = 0
            NAME1$ = "": STREET1$ = "": CITY1$ = "": PHONE1$ = "": GoSub SHOWED
        End If
        Return
        CLEARS: For a = 18 To 19: Locate a, 5: Print Space$(40);: Next: Return
        SHOWED: P$ = "\                          \"
        Locate 11, 42: Print "RECORD NUMBER: ";: Print Using "#####"; RECORDNUMBER;
        Locate 4, 48: Print Using P$; NAME1$
        Locate 5, 50: Print Using P$; STREET1$
        Locate 6, 48: Print Using P$; CITY1$
        Call PHONES(mask$, PHONE1$, 1, 48, 7, 15, 1, Back$)
        Return
    Loop
    Screen 0, 0, 0, 0: Cls
    Call MAIN
    For a = 2 To 5: Locate a, 54: Print Space$(25): Next
    Locate 2, 53: Print NAME1$
    Locate 3, 53: Print STREET1$
    Locate 4, 53: Print CITY1$
    Locate 5, 53: Print Back$
    Call SCROLL(DESCRIPTION$(), PRICE(), LINES, UPDOWN, DESCRIPTION$, PRICE, OFFSET, line1)
End Sub


'                  ***************************************************************************
'                  ***                  Retreve Customer information Record                ***
'                  ***************************************************************************
Sub GETTER (RECORDNUMBER)
    Get 1, RECORDNUMBER + 1
    NAME1$ = NAME$: STREET1$ = STREET$: CITY1$ = CITY$: PHONE1$ = PHONE2$
End Sub

'                  ***************************************************************************
'                  ***                    Dale Harris' INPUTS SUB                        ***
'                  ***************************************************************************
Sub INPUTS (X, Y, FCOLOR, BCOLOR, LENGTHS, NUMB, INPUTER$, KEYPRESS, CAPS)
    SC = Screen(Y, X, 1): FFCOLOR = Int(SC / 16): BBCOLOR = SC Mod 16: 'CURRENT COLOR
    P = 1: INPUTER$ = Left$(INPUTER$ + Space$(LENGTHS), LENGTHS): GoSub SHOW
    II: A$ = "": While A$ = "": A$ = InKey$: Wend: If CAPS Then A$ = UCase$(A$)
    If Len(A$) = 1 Then
        a = Asc(A$)
        If NUMB And ((a > 31 And a < 48) Or a > 57) Then
            If a > 31 Then GoTo II Else GoTo III
        End If
        If a > 31 And P <= LENGTHS Then
            If INSERTS Then
                INPUTER$ = Left$(Left$(INPUTER$, P - 1) + A$ + Mid$(INPUTER$, P, LENGTHS), LENGTHS)
                P = P + 1: GoSub SHOW: GoTo II
            Else
                Mid$(INPUTER$, P, 1) = A$
                P = P + 1: GoSub SHOW: GoTo II
            End If
        Else
            If a > 31 And P <= LENGTHS Then
                Mid$(INPUTER$, P, 1) = A$: P = P + 1
                GoSub SHOW: GoTo II
            Else
                III: If a = 27 Or a = 13 Then GoTo LEAVE: '[ESC]  [ENTER]
                '[BACKSPACE]
                If a = 8 And P > 1 Then
                    INPUTER$ = Left$(Left$(INPUTER$, P - 2) + Mid$(INPUTER$, P, LENGTHS) + " ", LENGTHS)
                    P = P - 1: GoSub SHOW
                End If
            End If
        End If
    End If
    a = Asc(Right$(A$, 1))
    If a = 71 Then P = 1: GoSub SHOW: '[HOME]
    If a = 75 And P > 1 Then P = P - 1: GoSub SHOW: '[LEFT]
    If a = 77 And P < LENGTHS Then P = P + 1: GoSub SHOW: '[RIGHT]
    If a = 79 Then P = Len(RTrim$(INPUTER$)): GoSub SHOW: '[END]
    If a = 82 Then INSERTS = Abs(INSERTS - 1): '[INSERT]
    If a = 83 Then
        '[DELETE]
        INPUTER$ = Left$(Left$(INPUTER$, P - 1) + Mid$(INPUTER$, P + 1, LENGTHS) + " ", LENGTHS)
        GoSub SHOW
    End If
    If a > 58 And a < 69 Then GoTo LEAVE: '[F?]
    If a = 73 Or a = 81 Then GoTo LEAVE: '[PG UP] [PG DN]
    If a = 72 Or a = 80 Then GoTo LEAVE: '[PG UP] [PG DN]
    GoTo II
    SHOW: If P < 1 Then P = 1
    Color FCOLOR, BCOLOR
    Locate Y, X: Print INPUTER$: Locate Y, X + P - 1
    Return
    LEAVE: KEYPRESS = a: CAPS = 0
    Color BBCOLOR, FFCOLOR: Locate Y, X: Print INPUTER$
    INPUTER$ = RTrim$(INPUTER$)
End Sub

'                  ***************************************************************************
'                  ***                    Opens The customer Database                      ***
'                  ***************************************************************************
Sub OPENER
    Open "R", 1, "PIZZA.CST", 120
    Field #1, 27 As NAME$, 27 As STREET$, 27 As CITY$, 15 As PHONE2$
    Field #1, 4 As LASTRECORD$
End Sub


'                  ***************************************************************************
'                  ***                    Phone Sub Mask - Dale Harris                    ***
'                  ***************************************************************************
Sub PHONES (MASK$, PHONE$, T, X, Y, FCOLOR, BCOLOR, BACK$)
    'T = 0=INPUT  1=DISPLAY ONLY  2=SEND BACK$ ONLY
    SC = Screen(Y, X, 1): FFCOLOR = Int(SC / 16): BBCOLOR = SC Mod 16: 'CURRENT COLOR
    MASK$ = "(###) ###-#### ex.#####": TT = T
    For a = 1 To Len(MASK$): If Mid$(MASK$, a, 1) = "#" Then B = B + 1
    Next: BW = 1
    If BW Then Color FCOLOR, BCOLOR Else Color 0, 7
    PHONE$ = Left$(PHONE$ + Space$(B), B): Locate , , 1, 7, 9
    C = 1: GoSub DISPLAY: If T Then T = 0: GoTo ENDER
    19 T# = Timer: A$ = ""
    While A$ = "": A$ = InKey$: Wend
    If Len(A$) = 2 Then E = Asc(Right$(A$, 1)) Else E = 0
    If A$ = Chr$(27) Then T = 27: Locate , , , 7, 8: GoTo ENDER
    If A$ = Chr$(9) Then T = 9: Locate , , , 8, 8: GoTo ENDER
    If A$ = Chr$(13) Or E = 80 Then T = 80: Locate , , , 8, 8: GoTo ENDER
    If E > 58 And E < 68 Then T = E:: Locate , , , 7, 8: GoTo ENDER
    If E = 72 Then T = 72: Locate , , , 7, 8: GoTo ENDER
    If E = 75 And C > 1 Then C = C - 1: INS = 0: Locate , , , 7, 8
    If E = 77 And C < B Then C = C + 1: INS = 0: Locate , , , 7, 8
    If E = 82 Then INS = Abs(INS - 1): If INS Then Locate , , , 5, 8 Else Locate , , , 7, 9
    If E = 83 Then PHONE$ = Left$(PHONE$, C - 1) + Mid$(PHONE$, C + 1, B) + " "
    If Asc(A$) = 8 And C > 1 Then PHONE$ = Left$(PHONE$, C - 2) + Mid$(PHONE$, C, B) + " ": C = C - 1
    If E = 71 Then C = 1
    If E = 79 Then
        For C = B To 1 Step -1: If Mid$(PHONE$, C, 1) <> " " Then Exit For
        Next: C = C + 1: If C > B Then C = B
    End If
    If InStr(" 0123456789", A$) Then
        If INS Then
            PHONE$ = Left$(Left$(PHONE$, C - 1) + A$ + Mid$(PHONE$, C, 50), B): C = C + 1
        Else
            Mid$(PHONE$, C, 1) = A$: C = C + 1: If C > B Then C = B
        End If
    End If
    GoSub DISPLAY
    GoTo 19
    DISPLAY: BACK$ = ""
    If T < 2 Then Locate Y, X
    P = 0: PP = 1: P1 = 0
    MASK$ = "(###) ###-#### ex.#####"
    For a = 1 To Len(MASK$)
        If Mid$(MASK$, a, 1) = "#" Then
            P = P + 1: P1 = P1 + 1
            If P <= Len(PHONE$) Then
                BACK$ = BACK$ + Mid$(PHONE$, P, 1)
            Else
                BACK$ = BACK$ + " "
            End If
        Else
            BACK$ = BACK$ + Mid$(MASK$, a, 1)
        End If
        If P1 < C Then PP = PP + 1
    Next
    If T < 2 Then Locate Y, X: Print BACK$;: Locate Y, X + PP - 1
    Return
    ENDER:
    If TT <> 2 Then Color BBCOLOR, FFCOLOR: Locate Y, X: Print BACK$
End Sub

'                  ***************************************************************************
'                  ***                Put Customer information into Database              ***
'                  ***************************************************************************
Sub PUTTER (RECORDNUMBER)
    LSet NAME$ = NAME1$: LSet STREET$ = STREET1$:
    LSet CITY$ = CITY1$: LSet PHONE2$ = PHONE1$
    Put 1, RECORDNUMBER + 1
End Sub

'                  ***************************************************************************
'                  ***                  Print totals to the order screen                  ***
'                  ***************************************************************************
Rem $STATIC

Sub PRINTTOTAL
    Color 14, 1
    Locate 17, 71: Print Using PP$; subtotal / 100
    Locate 18, 71: Print Using PP$; tax / 100
    Locate 19, 71: Print Using PP$; del / 100
    Locate 21, 71: Print Using PP$; total / 100
End Sub

'                  ***************************************************************************
'                  ***                  Scroll the lines on the order screen              ***
'                  ***************************************************************************
Rem $DYNAMIC
Sub SCROLL (DESCRIPTION$(), PRICE(), LINES, UPDOWN, DESCRIPTION$, PRICE, OFFSET, line1)
    Color 15, 1
    5 X = 2: Y = 3: 'UPPER LEFT CORNER OF SCROLL BOX
    PRINTSTRING$ = "####    \                              \ ####.## ": WIDTHS = Len(PRINTSTRING$)
    printstring2$ = "####    \                                  \" + "    ": WIDTHS = Len(printstring2$)
    'THE WITH OF PRINTSTRING$ SETS THE WIDTH OF THE SCROLL BOX
    HEIGHT = 18: 'NUMBER OF LINES IN THE SCROLL BOX
    'LINES IS THE NUMBER OF THE BOTTOM LINE TO RECEIVE DATA IN THE SCROLL BOX
    'OFFSET IS THE NUMER OF LINES BETWEEN THE BOTTOM LINE DISPLAYED AND "LINES"
    'UPDOWN = EITHER +1 OR -1 TO MOVE THE TEXT EITHER UP OR DOWN 0 = NO MOVE
    'DESCRIPTION$ IS THE NEW DESCRIPTION YOU WANT TO SEND TO THE SCROLL BOX
    'PRICE IS THE NEW PRICE YOU WANT TO SEND TO THE SCROLL BOX
    'DESCRIPTION$() HOLDS THE DESCRIPTIONS AND MUST BE RESET FOR A NEW SALE
    'PRICE() HOLDS THE PRICES AND MUST BE RESET FOR A NEW SALE
    If UPDOWN = 10 Then
        ReDim PRICE$(1100), DESCRIPTION$(1100)
        LINES = 0: UPDOWN = 0: DESCRIPTION$ = "": PRICE = 0: OFFSET = 0
    End If
    If RTrim$(DESCRIPTION$) <> "" Then

        LINES = LINES + 1: DESCRIPTION$(LINES) = DESCRIPTION$: PRICE(LINES) = PRICE
    End If
    If UPDOWN <> 0 Then
        OFFSET = OFFSET + UPDOWN * -1
        If OFFSET = LINES * -1 Then OFFSET = OFFSET + 1
        If OFFSET > 0 Then OFFSET = 0
    End If
    For a = 0 To HEIGHT - 1
        B = a - HEIGHT + LINES + 1 + OFFSET
        Locate a + Y + 1, X
        If B < 1 Then
            Print Spc(WIDTHS);
        Else
            If PRICE(B) = 0 Then
                Print Using printstring2$; B; DESCRIPTION$(B);
            Else
                Print Using PRINTSTRING$; B; DESCRIPTION$(B); PRICE(B) / 100;
            End If
        End If
    Next
End Sub

Sub PICKUP_DEL
    Color 12, 15
    PCopy 0, 1
    Screen 0, 0, 1, 1
    Color 0, 15
    Locate 1, 52: Print Chr$(201) + String$(27, Chr$(205)) + Chr$(187)
    Locate 2, 52: Print Chr$(186) + Spc(27) + Chr$(186)
    Locate 3, 52: Print Chr$(204) + String$(27, Chr$(205)) + Chr$(185)
    row = 4
    'CALL MENUS
    liner = LINES
    Color 4: Locate 2, 56: Print "    PRINT CHECK"
    Color 12, 15: Color 0, 15
    For linespace = 4 To 7
        Locate linespace, 52: Print Chr$(186) + Spc(27) + Chr$(186)
    Next linespace
    Color 1, 15
    Locate 4, 53: Print "A)"
    Locate 5, 53: Print "B)"
    Locate 6, 53: Print "C)"
    Locate 7, 53: Print "D)"
    Color 12, 15: Color 0, 15
    Locate 4, 56: Print "PICK UP"
    Locate 5, 56: Print "CARRY OUT"
    Locate 6, 56: Print "DELIVERY"
    Locate 7, 56: Print "OPEN TILL - NS"
    Locate 8, 52: Print Chr$(200) + String$(27, Chr$(205)) + Chr$(188)

    WERT: Do
        choose$ = "": While choose$ = "": choose$ = UCase$(InKey$): Wend:
        If Asc(choose$) = 27 Then Exit Do: Exit Sub
        Select Case choose$
            Case "A"
                typer$ = " PICK UP "
                Call PRINTRECEIPT(RECEIPT$(), DESCRIPTION$, PRICE, line1)
            Case "B"
                typer$ = "CARRY OUT"
                Call PRINTRECEIPT(RECEIPT$(), DESCRIPTION$, PRICE, line1)
            Case "C"
                DESCRIPTION$ = ""
                typer$ = "DELIVERY"
                DELCNT = 1
                Call ADDARRAY(RECEIPT$(), DESCRIPTION$, PRICE, line1)
                Call SCROLL(DESCRIPTION$(), PRICE(), LINES, updown, DESCRIPTION$, PRICE, OFFSET, line1)
                GETTOTALS
                Call PRINTRECEIPT(RECEIPT$(), DESCRIPTION$, PRICE, line1)
            Case Chr$(68), Chr$(100)
                Open "lpt1" For Output As 2
                Print #2, opencode$;
                Close 2
                Sound 696, 20
                Exit Do
            Case Else
                GoTo WERT
        End Select
    Loop

    Screen 0, 0, 0, 0
    If liner = LINES Then DESCRIPTION$ = ""
    Call SCROLL(DESCRIPTION$(), PRICE(), LINES, updown, DESCRIPTION$, PRICE, OFFSET, line1)
End Sub

Sub CHECKFORFILE
    If Not _FileExists("checknofile\CHKNO.NO") Then FLAG = 1
    Open "checknofile\CHKNO.NO" For Random As #3 Len = 1000
    Field #3, 1000 As A$
    If FLAG = 1 Then LSet A$ = String$(1000, ""): Put 3, 1
    Close #3
End Sub

Sub RINGSALE
    Screen 0, 0, 2, 2: BK = 0
    Color 15, 1: Cls
    '******************************************************************************************************************************
    '                        THIS SECTION WAS ADDED TO KEEP FROM CREATING A BLANK CHKNO.NO FILE
    '******************************************************************************************************************************
    Call CHECKFORFILE
    '******************************************************************************************************************************
    '                                                  END ADDED SECTION
    '******************************************************************************************************************************

    Call CHECKOUT
    FCOLOR = 14: BCOLOR = 5: DECIMAL$ = "000.00": X = 30: Y = 8
    NUMBER = 0
    Locate 13, 53: Print " Subtotal =====> "
    Locate 14, 53: Print "      Tax =====> "
    Locate 15, 53: Print "  Del Fee =====> "
    Locate 16, 71: Print "ÄÄÄÄÄÄÄÄÄ"
    Locate 17, 53: Print "Total Due =====> "
    Color 1, 15
    Call GETTER2(NAME1$, STREET1$, CITY1$, Back$, total$, tax$, subtotal$, Desc$, price$, CN, booboo, COUPON$)
    If Styper$ = "D" Then DELCNT = 1 Else DELCNT = 0
    If booboo = 1 Then booboo = 0: GoTo 78
    For a = 2 To 5: Locate a, 54: Print Space$(25): Next
    Locate 2, 53: Print NAME1$
    Locate 3, 53: Print STREET1$
    Locate 4, 53: Print CITY1$
    Locate 5, 53: Print Back$
    Locate 19, 53: Print "                          "
    Locate 19, 53: Print "Amt Tendered: "
    redo: Call NUMBERS(67, 19, FCOLOR, BCOLOR, DECIMAL$, NUMBER, KEYPRESS)
    If KEYPRESS = 27 Then
        Open "checknofile\CHKNO.NO" For Random As #3 Len = 1000
        Field #3, 1000 As A$
        Get 3, 1: B$ = A$: Mid$(B$, CN, 1) = "A": LSet A$ = B$: Put 3, 1: Close 3
        GoTo 78
    End If
    If KEYPRESS = 59 Then
        For a = 1 To LINES
            DESCRIPTION$(a) = RECEIPT$(a, 1): PRICE(a) = Val(RECEIPT$(a, 2))
        Next
        If del <> 0 Then total = total - del: del = 0 '<== Deletes the Delivery Charge, if still a delivery when Choosen will add the del back on
        Open "checknofile\CHKNO.NO" For Random As #3 Len = 1000
        Field #3, 1000 As A$
        Get 3, 1: B$ = A$: Mid$(B$, CN, 1) = "A": LSet A$ = B$: Put 3, 1: Close 3
        BK = CN: BK1 = 1: F1 = 1
        Exit Sub
    End If
IF NUMBER < total THEN sound 554,20 : LOCATE 21, 53: COLOR 26,: _
                      PRINT "Tender less then Total Due": COLOR 15 ,: LOCATE 22,53: PRINT "RE-ENTER AMOUNT TENDERED": _
                        NUMBER = .00:SLEEP: LOCATE 21,53: PRINT "                          ": _
                      LOCATE 22,53: PRINT "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ": GOTO redo
    If NUMBER = 0 Then
        chgdue = 0
    Else
        chgdue = NUMBER - total
    End If
    Locate 21, 53: Print "                          "
    Locate 21, 53: Print "  Change Due: ";
    TOTALSALESCNT = 1
    'CALL BIG(chgdue)
    Locate 21, 67: Print Using PP$; chgdue / 100
    Color 15, 3
    Locate 14, 3: Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
    Locate 15, 3: Print "º                                              º"
    Locate 16, 3: Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
    Locate 15, 3: Print Chr$(186) + Space$(23 - Len("PRESS ANY KEY TO RETURN TO MAIN SCREEN") / 2); "PRESS ANY KEY TO RETURN TO MAIN SCREEN"
    Beep
    Open "lpt1" For Output As 2
    Print #2, opencode$;
    Close 2
    Color 15, 1
    Open "checknofile\CHKNO.NO" For Random As #3 Len = 1000
    Field #3, 1000 As A$
    Get 3, 1: B$ = A$
    Mid$(B$, CN, 1) = "B"
    LSet A$ = B$
    Put 3, 1
    Close 3
    CHKNO$ = LTrim$(Str$(CN)) + ".TRN"
    Call SAVE_ZREPORT
    Call SAVE_XREPORT
    Sleep
    78 subtotal = 0
    NAME1$ = ""
    STREET1$ = ""
    CITY1$ = ""
    PHONE1$ = ""
    tax = 0
    COUPCNT = 0
    TOTALSALESCNT = 0
    total = 0
    del = 0
    COUPON = 0
    LINES = 0
    line1 = 0
    Call PRINTTOTAL
End Sub

Sub SAVER (name1$, street1$, City1$, back$, total$, tax$, subtotal$, Desc$, price$)

    If BK = 0 Then
        Call CHECKFORFILE
        Open "checknofile\CHKNO.NO" For Random As #3 Len = 1000
        Field #3, 1000 As A$
        Get 3, 1: B$ = A$
        '''FOR A = 1 TO 50: PRINT ASC(MID$(B$, A, 1));: NEXT
        For a = 1 To 1000
            N = Asc(Mid$(B$, a, 1))
            If N <> 65 And N <> 66 And N <> 86 Then Mid$(B$, a, 1) = "A": Exit For
        Next
        LSet A$ = B$
        Put 3, 1
        Close 3
        chkno = a
    Else
        chkno = BK: BK = 0
    End If
    If Not _DirExists("checknofile") Then
        Shell _Hide ("mkdir checknofile")
    End If
    CHKNO$ = "checknofile\" + LTrim$(Str$(chkno)) + ".TRN"
    Open CHKNO$ For Random As #3 Len = 80
    Field #3, 80 As A$
FIELD #3, 4 AS subtotal$, 4 AS tax$, 4 AS DEL$, 4 AS total$, 4 AS LINE1$, 1 AS SALESTYPE$, 4 AS COUPON$, 2 AS COUPCNT$, 4 AS XVOIDCOUPDOLLARS$, _
          2 as TOTALSALESCNT$, 8 as ORDERTIME$
    LSet subtotal$ = MKL$(subtotal): LSet tax$ = MKL$(tax): LSet COUPON$ = MKL$(COUPON): LSet COUPCNT$ = MKI$(COUPCNT)
    LSet XVOIDCOUPDOLLARS$ = MKL$(VOIDCOUPDOLLARS): LSet TOTALSALESCNT$ = MKI$(TOTALSALESCNT)
    LSet DEL$ = MKL$(del): LSet total$ = MKL$(total): LSet LINE1$ = MKL$(line1): LSet SALESTYPE$ = LTrim$(typer$): RSet ORDERTIME$ = Right$(CLOCK$, 7)
    Put 3, 1
    LSet A$ = name1$: Put 3, 2
    LSet A$ = street1$: Put 3, 3
    LSet A$ = City1$: Put 3, 4
    LSet A$ = back$: Put 3, 5
    Field #3, 30 As Desc$, 10 As price$
    For a = 1 To line1
        LSet Desc$ = RECEIPT$(a, 1): LSet price$ = RECEIPT$(a, 2)
        Put 3, a + 5
    Next a
    For a = 1 To 7: LSet A$ = INSTRUCT$(a): Put 3: Next a
    Close 3
End Sub

Sub CHKSTATUS
    Screen 0, 0, 22, 22
    Color 15, 1: Cls
    Locate 7, 25: Print "Choose Option to display...": Print
    Locate 10, 30: Print "1. Open sales"
    Locate 11, 30: Print "2. Completed sales"
    Locate 12, 30: Print "3. Voided sales"
    Locate 13, 30: Print "4. All sales"
    Locate 14, 30: Print "5. Quit"
    1 A$ = "": While A$ = "": A$ = InKey$: Wend
    P = Val(A$): If P = 5 Then Exit Sub
    If P = 0 Or P > 4 Then GoTo 1
    If Not _FileExists("checknofile\CHKNO.NO") Then FLAG = 1
    Open "checknofile\CHKNO.NO" For Random As #3 Len = 1000
    Field #3, 1000 As A$
    If FLAG = 1 Then LSet A$ = String$(1000, ""): Put 3, 1
    Close #3
    Open "checknofile\CHKNO.NO" For Random As #3 Len = 1000
    Field #3, 1000 As A$
    Get 3, 1: B$ = A$: Close 3
    If _FileExists("OPENSCRL.DAT") Then Close #4: Kill "OPENSCRL.DAT"
    Open "OPENSCRL.DAT" For Random As #4 Len = 80
    Field #4, 80 As RECORD$
    Field #4, 8 As TIMEORDER$, 1 As NULL$, 4 As COUNT$, 4 As NULL$, 28 As NAMER$, 25 As phone$, 5 As OPEN$
    For A = 1 To 1000
        If Mid$(B$, A, 1) = Chr$(15) Then Exit For
        CK$ = Mid$(B$, A, 1)
        If (P = 1 And CK$ = "A") Or (P = 2 And CK$ = "B") Or (P = 3 And CK$ = "V") Or P = 4 Then
            CHKNO$ = LTrim$(Str$(A)) + ".TRN"
            counter = counter + 1
            Open "checknofile\" + CHKNO$ For Random As #3 Len = 80
            Field #3, 80 As A$
FIELD #3, 4 AS subtotal$, 4 AS tax$, 4 AS DEL$, 4 AS total$, 4 AS LINE1$, 1 AS SALESTYPE$, 4 AS COUPON$, 2 AS COUPCNT$, 4 AS XVOIDCOUPDOLLARS$, _
          2 as TOTALSALESCNT$, 8 as ORDERTIME$
            Get #3, 1: LSet TIMEORDER$ = ORDERTIME$
            Get 3, 2: NAME1$ = RTrim$(A$)
            Get 3, 5: Back$ = RTrim$(A$)
            NAME2$ = NAME1$
            BACK1$ = Back$
            Close #3
            STATUS$ = "OPEN": If CK$ = "B" Then STATUS$ = "CLSD" Else If CK$ = "V" Then STATUS$ = "VOID"
            RSet COUNT$ = LTrim$(RTrim$(Str$(A))): LSet NAMER$ = NAME1$: LSet phone$ = Back$: LSet OPEN$ = STATUS$
            Print RECORD$
            Put 4
        End If
    Next
    Close

    Open "OPENSCRL.DAT" For Random As #4 Len = 80
    Field #4, 8 As TIMEORDER$, 1 As NULL$, 4 As COUNT$, 4 As NULL$, 28 As NAMER$, 25 As phone$, 5 As OPEN$
    Field #4, 80 As RECORD$
    RC = LOF(4) \ 80
    Print RC
    Color 15, 1:
    Cls
    Locate 4, 5: Print "Time In  CHK #      Customer                    Phone          Status "
    Locate 5, 4: Print "--------------------------------------------------------------------------"
    5 X = 4: Y = 5: 'UPPER LEFT CORNER OF SCROLL BOX
    WIDTHS = 74: ' WIDTH OF SCROLL BOX
    HEIGHT = 18: 'NUMBER OF LINES IN THE SCROLL BOX
    'LINES IS THE NUMBER OF THE BOTTOM LINE TO RECEIVE DATA IN THE SCROLL BOX
    'OFFSET IS THE NUMER OF LINES BETWEEN THE BOTTOM LINE DISPLAYED AND "LINES"

    OFFSET = 0
    LINE6 = 1
    6
    For A = 0 To HEIGHT - 1
        B = A + LINE6 + OFFSET
        Locate A + Y + 1, X
        Color 15, 1: If B = LINE6 Then Color 15, 3: TRN = Val(COUNT$)
        If LINE6 < 0 Or LINE6 = 0 Then
        Else
            Get 4, B: Print Left$(RECORD$, WIDTHS);
            Locate 1, 70: Print "LINE #"; Using "###"; LINE6
        End If
    Next
    7 A$ = "": While A$ = "": A$ = InKey$: Wend
    IN = Asc(A$):
    If Len(A$) = 2 Then IN2 = Asc(Right$(A$, 1)) Else IN2 = 0
    If IN2 = 72 Then
        LINE6 = LINE6 - 1: If LINE6 = 0 Then LINE6 = 1
        GoTo 6
    End If
    If IN2 = 80 Then
        LINE6 = LINE6 + 1: If LINE6 > RC Then LINE6 = RC
        GoTo 6
    End If
    If IN2 = 73 Then
        LINE6 = LINE6 - HEIGHT: If LINE6 < 1 Then LINE6 = 1
        GoTo 6
    End If
    If IN2 = 81 Then
        LINE6 = LINE6 + HEIGHT: If LINE6 > RC Then LINE6 = RC
        GoTo 6
    End If
    If IN2 = 71 Then
        LINE6 = 1
        GoTo 6
    End If
    If IN2 = 79 Then
        LINE6 = RC
        GoTo 6
    End If
    If IN = 27 Then Exit Sub
    If IN = 13 Then Get 4, LINE6: TRN = Val(COUNT$): Locate 24, 1: Print TRN: Exit Sub
    GoTo 7


End Sub

Sub GETTER2 (name1$, street1$, City1$, back$, total$, tax$, subtotal$, Desc$, price$, CN, booboo, COUPON$)
    Color 15, 1
    Locate 10, 53: Input "CHECK NUMBER"; CN
    chkno = CN
    CHKNO$ = "checknofile\" + LTrim$(Str$(chkno)) + ".TRN"
    'CHKNO$ = LTRIM$(STR$(chkno)) + ".TRN"
    If Not _FileExists(CHKNO$) Then
        Color 15, 1
        Locate 10: Print Space$(25 - Len("SORRY, I COULD NOT FIND A CHECK NUMBER  " + CHKNO$) / 2); "    I COULD NOT FIND A CHECK NUMBER  " + CHKNO$
        Locate 11: Print Space$(25 - Len("CHECK ALREADY PAID  or  CHECK DOES NOT EXIST") / 2); "    CHECK PAID  or  CHECK DOESN'T EXIST"
        Locate 15: Print Space$(25 - Len("PRESS ANY KEY TO CONTINUE") / 2); " PRESS ANY KEY TO CONTINUE"
        Color 15, 1
        Locate 10, 1: Print Chr$(186)
        Locate 11, 1: Print Chr$(186)
        Locate 15, 1: Print Chr$(186)
        Sleep
        booboo = 1: Exit Sub
    End If
    Open "checknofile\CHKNO.NO" For Random As #3 Len = 1000
    Field #3, 1000 As A$
    Get 3, 1: B$ = A$: Close 3
    '''FOR A = 1 TO 50: PRINT ASC(MID$(B$, A, 1));: NEXT
    If Mid$(B$, CN, 1) <> "A" Then
        Color 15, 1
        Locate 10: Print Space$(25 - Len("SORRY, I COULD NOT FIND A CHECK NUMBER  " + CHKNO$) / 2); "    I COULD NOT FIND A CHECK NUMBER  " + CHKNO$
        Locate 11: Print Space$(25 - Len("CHECK ALREADY PAID  or  CHECK DOES NOT EXIST") / 2); "    CHECK PAID  or  CHECK DOESN'T EXIST"
        Locate 15: Print Space$(25 - Len("PRESS ANY KEY TO CONTINUE") / 2); " PRESS ANY KEY TO CONTINUE"
        Color 15, 1
        Locate 10, 1: Print Chr$(186)
        Locate 11, 1: Print Chr$(186)
        Locate 15, 1: Print Chr$(186)
        Sleep
        booboo = 1: Exit Sub
    End If
    Open CHKNO$ For Random As #3 Len = 80
    Field #3, 80 As A$
FIELD #3, 4 AS subtotal$, 4 AS tax$, 4 AS DEL$, 4 AS total$, 4 AS LINE1$, 1 AS SALESTYPE$, 4 AS COUPON$, 2 AS COUPCNT$, 4 AS VOIDCOUPDOLLARS$, _
          2 as TOTALSALESCNT$
    Get 3, 1
    subtotal = CVL(subtotal$): tax = CVL(tax$): VOIDCOUPDOLLARS = CVL(VOIDCOUPDOLLARS$): TOTALSALESCNT = CVI(TOTALSALESCNT$)
    del = CVL(DEL$): total = CVL(total$): line1 = CVL(LINE1$): COUPON = CVL(COUPON$): COUPCNT = CVI(COUPCNT$): Styper$ = SALESTYPE$
    Get 3, 2: name1$ = RTrim$(A$)
    Get 3, 3: street1$ = RTrim$(A$)
    Get 3, 4: City1$ = RTrim$(A$)
    Get 3, 5: back$ = RTrim$(A$)
    Field #3, 30 As Desc$, 10 As price$
    For a = 1 To line1
        Get 3, a + 5
        RECEIPT$(a, 1) = RTrim$(Desc$): RECEIPT$(a, 2) = RTrim$(price$)
    Next a
    For a = 1 To 7
        Get 3
        INSTRUCT$(a) = Left$(A$, 27)
        88 I = InStr(INSTRUCT$(a), Chr$(0))
        If I Then Mid$(INSTRUCT$(a), I, 1) = " ": GoTo 88
    Next
    Close 3
    LINES = line1: GoSub SCROLLER
    PP$ = "###.##"
    Locate 13, 72: Print Using PP$; subtotal / 100
    Locate 14, 72: Print Using PP$; tax / 100
    Locate 15, 72: Print Using PP$; del / 100
    Locate 17, 72: Print Using PP$; total / 100
    LINES = line1: GoSub SCROLLER
    If Len(A$) = 2 Then
        a = Asc(Right$(A$, 1))
        If a = 72 Then UPDOWN = -1: GoSub SCROLLER
        If a = 80 Then UPDOWN = 1: GoSub SCROLLER
    End If
    Exit Sub

    SCROLLER:
    PRINTSTRING$ = "####    \                              \ ####.## ": WIDTHS = Len(PRINTSTRING$)
    printstring2$ = "####    \                                  \" + "    ": WIDTHS = Len(printstring2$)
    X = 2: Y = 3: HEIGHT = 18
    If UPDOWN <> 0 Then
        OFFSET = OFFSET + UPDOWN * -1
        If OFFSET = LINES * -1 Then OFFSET = OFFSET + 1
        If OFFSET > 0 Then OFFSET = 0
    End If
    For a = 0 To HEIGHT - 1
        B = a - HEIGHT + LINES + 1 + OFFSET
        Locate a + Y + 1, X
        If B < 1 Then
            Print Spc(WIDTHS);
        Else
            If Val(RECEIPT$(B, 2)) = 0 Then
                Print Using printstring2$; B; RECEIPT$(B, 1);
            Else
                Print Using PRINTSTRING$; B; RECEIPT$(B, 1); Val(RECEIPT$(B, 2)) / 100;
            End If
        End If
    Next
    Return
End Sub

Sub PRINTHEAD (HF)
    'FOR B = 0 TO 1: FOR a = 1 TO 8:
    '        GET 1, a + B * 8 + 721: HEADER$(B, a) = LEFT$(A$, 39):
    'next a,b

    ReDim HEAD$(2, 8)
    Open "R", 10, "PITABLE.DB", 60
    Field #10, 39 As A$
    For B = 1 To 2
        For a = 1 To 8
            Get 10, a + (B - 1) * 8 + 741: H$ = A$
            888 Q = InStr(H$, Chr$(0)): If Q Then Mid$(H$, Q, 1) = " ": GoTo 888 Else H$ = LTrim$(RTrim$(H$))
            HEAD$(B, a) = Space$(19 - Len(H$) / 2) + H$
        Next a
    Next B
    Close #10

    For a = 8 To 1 Step -1
        If RTrim$(HEAD$(HF, a)) <> "" Then Exit For
    Next a
    For B = 1 To a
        26 NULL = InStr(HEAD$(HF, B), Chr$(0)): If NULL Then Mid$(HEAD$(HF, B), NULL, 1) = " ": GoTo 26
        Print #2, RTrim$(HEAD$(HF, B))
    Next B
    Print #2, Chr$(29)
End Sub

Sub PRINTRECEIPT (RECEIPT$(), DESCRIPTION$, PRICE, line1)
    Call SAVER(NAME1$, STREET1$, CITY1$, Back$, total$, tax$, subtotal$, Desc$, price$)
    If useprinter = 1 Then Open "LPT1" For Output As #2
    If useprinter = 2 Then Open "wlsdfkjn.dry" For Output As #2
    If BK1 = 1 Then
        REPRINT1$ = "*********************************"
        REPRINT2$ = "*** REPRINT  REPRINT  REPRINT ***"
        Print #2, Space$(20 - Len(REPRINT1$) / 2); REPRINT1$
        Print #2, Space$(20 - Len(REPRINT2$) / 2); REPRINT2$
        Print #2, Space$(20 - Len(REPRINT1$) / 2); REPRINT1$
        For i = 1 To 2
            Print #2, ""
        Next i
        BK1 = 0
    End If
    Call PRINTHEAD(1)
    lined$ = "________________________________________"
    Print #2, Space$(20 - Len(lined$) / 2); lined$
    dateline$ = Date$ + Spc(9) + CLOCK$
    Print #2, ""
    Print #2, Space$(20 - Len(dateline$) / 2); dateline$
    Print #2, ""
    Print #2, Space$(20 - Len(DELCLOCK$) / 2); DELCLOCK$
    Print #2, Space$(20 - Len(lined$) / 2); lined$
    Print #2, ""
    Print #2, NAME1$
    Print #2, STREET1$
    Print #2, CITY1$
    Print #2, Back$
    Print #2, Space$(20 - Len(lined$) / 2); lined$
    Print #2, ""
    Star$ = String$(40, "-")

    Print #2, Chr$(29)
    Print #2, Chr$(31); Space$(10 - Len(typer$) / 2); typer$
    Print #2, Chr$(29)
    Print #2, Space$(20 - Len(Star$) / 2); Star$
    Print #2, ""
    Print #2, ""
    PP$ = "##,###.##"
    PR$ = "\                            \##,###.##"
    For count = 1 To line1
        If Val(RECEIPT$(count, 2)) = 0.00 Then
            Print #2, RECEIPT$(count, 1)
        Else
            Print #2, Using PR$; RECEIPT$(count, 1); Val(RECEIPT$(count, 2)) / 100
        End If
    Next count
    If typer$ = " PICK UP " Or typer$ = "CARRY OUT" Then
        For i = 1 To 3
            Print #2, ""
        Next i
        Print #2, Spc(21); "Subtotal "; Using PP$; subtotal / 100
        Print #2, Spc(21); "    Tax "; Using PP$; tax / 100
        Print #2, Spc(32); "-------"
        Print #2, Spc(21); "  Total "; Using PP$; total / 100
    Else
        For i = 1 To 3
            Print #2, ""
        Next i
        Print #2, Spc(21); "Subtotal "; Using PP$; subtotal / 100
        Print #2, Spc(21); "    Tax "; Using PP$; tax / 100
        Print #2, Spc(21); "Delivery "; Using PP$; del / 100
        Print #2, Spc(32); "-------"
        Print #2, Spc(21); "  Total "; Using PP$; total / 100
    End If
    Message2$ = "** GRATUITY NOT INCLUDED **"
    CheckNumber$ = "Chk #"
    For counter = 1 To 5
        Print #2, ""
    Next counter
    KB$ = "INSTRUCTIONS"

    XX3 = 0
    For A = 1 To 7
        If LTrim$(INSTRUCT$(A)) <> "" Then XX3 = 1: Exit For
    Next A
    If XX3 = 1 Then Print #2, Space$(20 - Len(KB$) / 2); KB$: Print #2, lined$
    For A = 1 To 7
        If LTrim$(INSTRUCT$(A)) <> "" Then Print #2, Space$(20 - Len(INSTRUCT$(A)) / 2); INSTRUCT$(A):
    Next A
    If XX3 = 1 Then Print #2, lined$

    For A = 1 To 4
        Print #2, ""
    Next A
    If typer$ = "DELIVERY" Then Print #2, Space$(20 - Len(Message2$) / 2); Message2$: Print #2, "": Print #2, ""
    Call PRINTHEAD(2)
    For counter = 1 To 5
        Print #2, ""
    Next counter
    Print #2, Space$(16 - Len(chkno) / 2); CheckNumber$; " "; chkno
    For counter = 1 To 5
        Print #2, ""
    Next counter
    Call PRINTCOUPONS
    For counter = 1 To 17
        Print #2, " "
    Next counter
    Close #2
    Erase RECEIPT$
    ReDim RECEIPT$(1100, 2)
    Erase DESCRIPTION$
    Erase PRICE

    del = 0
    LINES = 0
    DESCRIPTION$ = ""
    COUPON = 0
    COUPCNT = 0
    TOTALSALESCNT = 0
    VOIDCOUPDOLLARS = 0
    PRICE = 0
    line1 = 0
    subtotal = 0
    tax = 0
    total = 0
    NAME1$ = ""
    STREET1$ = ""
    CITY1$ = ""
    PHONE1$ = ""
    typer$ = ""
    ReDim INSTRUCT$(7)
    Call BEGINNING
End Sub

Sub REMOVELINE (DESCRIPTION$(), PRICE(), DESCRIPTION$, PRICE, LINES, line1)
    Color 15,
    Locate 1, 1: Print Chr$(201) + String$(35, Chr$(205)) + Chr$(203)
    Locate 2, 1: Print Chr$(186)
    Locate 2, 3: Color 15,: Print " Enter"
    Locate 2, 10: Color 26,: Print "Line Number "
    Locate 2, 22: Color 15,: Print "To Remove?" '
    Locate 2, 37: Color 15,: Print Chr$(186)
    Locate 3, 1: Print Chr$(204) + String$(35, Chr$(205)) + Chr$(202)
    Color 15
    Locate 2, 34: Input "", start
    Color 15, 1
    Locate 1, 1: Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍË"
    Locate 2, 1: Print "º LINE          DESCRIPTION                PRICE º"
    Locate 3, 1: Print "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
    REMOVEPRICE = Val(RECEIPT$(start, 2)): subtotal = subtotal - REMOVEPRICE
    If REMOVEPRICE < 0 And CN > 0 Then
        CHKNO$ = "checknofile\" + LTrim$(Str$(chkno)) + ".TRN"
        'CHKNO$ = LTRIM$((STR$(CN))) + ".TRN"
        Open CHKNO$ For Random As #3 Len = 80
        Field #3, 80 As A$
        Field #3, 4 As subtotal$, 4 As tax$, 4 As DEL$, 4 As total$, 4 As LINE1$, 1 As SALESTYPE$, 4 As COUPON$, 2 As COUPCNT$, 4 As VOIDCOUPDOLLARS$
        Field #3, 4 As DELCNT$, 2 As TOTALSALESCNT$, 7 As ORDERTIME$
        COUPON = COUPON - REMOVEPRICE
        COUPCNT = COUPCNT - 1
        LSet subtotal$ = MKL$(subtotal): LSet tax$ = MKL$(tax): LSet COUPON$ = MKL$(COUPON): LSet COUPCNT$ = MKI$(COUPCNT)
        LSet XVOIDCOUPDOLLARS$ = MKL$(VOIDCOUPDOLLARS): LSet DELCNT$ = MKL$(DELCNT): LSet TOTALSALESCNT$ = MKI$(TOTALSALESCNT)
        LSet DEL$ = MKL$(del): LSet total$ = MKL$(total): LSet LINE1$ = MKL$(line1): LSet SALESTYPE$ = LTrim$(typer$)
        If Styper$ = "D" Then DELCNT = DELCNT - 1
        TOTALSALESCNT = TOTALSALESCNT - 1
        Put 3, 1
        Close #3
    End If
    For a = start To LINES: For B = 0 To 2: RECEIPT$(a, B) = RECEIPT$(a + 1, B): Next B, a
    For a = start To LINES: DESCRIPTION$(a) = DESCRIPTION$(a + 1): Next a
    For a = start To LINES: PRICE(a) = PRICE(a + 1): Next a
    LINES = LINES - 1
    line1 = line1 - 1
    Call GETTOTALS
    Call PRINTTOTAL
    Call SCROLL(DESCRIPTION$(), PRICE(), LINES, UPDOWN, DESCRIPTION$, PRICE, OFFSET, line1)
    Exit Sub
End Sub

Function CLOCK$
    hour$ = Left$(Time$, 2): H% = Val(hour$)
    min$ = Mid$(Time$, 3, 3)
    If H% >= 12 Then ampm$ = " PM" Else ampm$ = " AM"
    If H% > 12 Then
        If H% - 12 < 10 Then hour$ = Str$(H% - 12) Else hour$ = LTrim$(Str$(H% - 12))
    ElseIf H% = 0 Then hour$ = "12" ' midnight hour
    Else: If H% < 10 Then hour$ = Str$(H%) ' eliminate leading zeros
    End If
    CLOCK$ = "Time In: " + hour$ + min$ + ampm$
End Function

Function DELCLOCK$
    Cls
    temp$ = Time$
    hour = Val(temp$)
    min = Val(Mid$(temp$, 4, 2))
    If typer$ = " PICK UP " Or typer$ = "CARRY OUT" Then gap = PICKTIME
    If typer$ = "DELIVERY" Then gap = DELTIME
    min = min + gap
    If min > 59 Then min = min - 60: hour = hour + 1
    If hour > 12 Then hour = hour - 12: M$ = "PM" Else M$ = "AM"
    If hour = 12 Then If M$ = "AM" Then M$ = "PM" Else M$ = "AM"
    If hour = 0 Then hour = 12: M$ = "AM"
    If min < 10 Then x$ = "0" Else x$ = ""
    DELCLOCK$ = "Target ETA: " + LTrim$(Str$(hour)) + ":" + x$ + LTrim$(Str$(min)) + M$
    PickUPCLOCK$ = temp$
End Function

Sub CHOICEBOX
    Screen 0, 0, 6, 6
    Color 15, 1
    Locate 14, 3: Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
    Locate 15, 3: Print "º                                              º"
    Locate 16, 3: Print "º                                              º"
    Locate 17, 3: Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
End Sub

Sub CHECKOUT
    Screen 0, 0, 19, 19
    PCopy 0, 19
    Color 15, 1
    Locate 11, 52: Print "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
    Locate 12, 52: Print "º                          º"
    Locate 13, 52: Print "º                          º"
    Locate 14, 52: Print "º                          º"
    Locate 15, 52: Print "º                          º"
    Locate 16, 52: Print "º                          º"
    Locate 17, 52: Print "º                          º"
    Locate 18, 52: Print "º                          º"
    Locate 19, 52: Print "º                          º"
    Locate 20, 52: Print "º                          º"
    Locate 21, 52: Print "º                          º"
    Locate 22, 52: Print "ÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
End Sub

Sub NUMBERS (X, Y, FCOLOR, BCOLOR, DECIMAL$, NUMBER, KEYPRESS)
    SC = Screen(Y, X, 1): FFCOLOR = Int(SC / 16): BBCOLOR = SC Mod 16: 'CURRENT COLOR
    DECIMAL = InStr(DECIMAL$, ".")
    DIGITS = Len(DECIMAL$) - Sgn(DECIMAL)
    GoSub SHOWS
    NII: A$ = "": While A$ = "": A$ = InKey$: Wend
    If Len(A$) = 1 Then
        a = Asc(A$)
        If a > 47 And a < 58 And NUMBER * 10 < 10 ^ DIGITS Then
            NUMBER = NUMBER * 10 + Val(A$): GoSub SHOWS: GoTo NII
        End If
        NIII:
        If a = 27 Or a = 13 Or a = 9 Then GoTo LEAVES: '[ESC]  [ENTER]  [TAB]
        If a = 8 Then NUMBER = NUMBER \ 10: GoSub SHOWS: '[BACKSPACE]
    End If
    a = Asc(Right$(A$, 1))
    If a = 75 Then NUMBER = NUMBER \ 10: GoSub SHOWS '[LEFT]
    If a = 83 Then NUMBER = 0: GoSub SHOWS: '[DELETE]
    If a > 58 And a < 69 Then GoTo LEAVES: '[F?]
    If a = 73 Or a = 81 Then GoTo LEAVES: '[PG UP] [PG DN]
    If a = 72 Or a = 80 Then GoTo LEAVES: '[UP] [DN]
    GoTo NII

    SHOWS:
    N$ = Space$(DIGITS): RSet N$ = LTrim$(Str$(NUMBER))
    If DECIMAL Then
        N$ = Left$(N$, DECIMAL - 1) + "." + Mid$(N$, DECIMAL, 20)
        If Mid$(N$, DECIMAL + 1, 1) = " " Then Mid$(N$, DECIMAL + 1, 1) = "0"
    End If
    If P < 1 Then P = 1
    Color FCOLOR, BCOLOR
    Locate Y, X: Print N$: Locate Y, X + DIGITS + Sgn(DECIMAL) - 1
    Return

    LEAVES: KEYPRESS = a
    Color BBCOLOR, FFCOLOR: Locate Y, X: Print N$
End Sub


Sub GET_ZREPORT
    _Delay 3
    Cls
    Screen 0, 0, 3, 3
    PRINTSTRING$ = "##,###,###.##"
    path$ = Environ$("LocalAppData") + "\WINDOWZ.Dll"
    Open path$ For Random As #1 Len = 200
    Field #1, 200 As A$
    Get 1, 1
    RANDOM$ = A$
    'Get totals from file
    ZSUBTOTAL = CVL(Mid$(RANDOM$, 56, 4)) / 100
    ZTAX = CVL(Mid$(RANDOM$, 89, 4)) / 100
    ZTOTAL = CVL(Mid$(RANDOM$, 122, 4)) / 100
    ZVOIDS = CVL(Mid$(RANDOM$, 150, 4)) / 100
    ZREFUNDS = CVL(Mid$(RANDOM$, 175, 4)) / 100
    ZCOUPON = CVL(Mid$(RANDOM$, 180, 4)) / 100
    ZDELIVERY = CVL(Mid$(RANDOM$, 190, 4)) / 100

    '************************ REPORT FORMATTING ******************************
    Color , 1
    'BUILD BOX AROUND TOTAL DATA
    Locate 4, 2: Print Chr$(201) + String$(76, Chr$(205)) + Chr$(187)
    For i = 5 To 8
        Locate i, 2: Print Chr$(186) + Spc(76) + Chr$(186)
    Next i
    Locate 9, 2: Print Chr$(200) + String$(76, Chr$(205)) + Chr$(188)
    'END BOX BUILD
    Color 15, 0
    Locate 3, 27: Print "Z  R E P O R T  T O T A L S"
    DATAS$ = "PRESS [F1] TO PRINT Z-REPORT"
    Locate 18,: Print Space$(40 - Len(DATAS$) / 2); DATAS$
    Color 15, 1
    Locate 5, 56: Print "SUBTOTAL  "; Using PRINTSTRING$; ZSUBTOTAL
    Locate 6, 56: Print "    TAX  "; Using PRINTSTRING$; ZTAX
    Locate 7, 56: Print "DELIVERY  "; Using PRINTSTRING$; ZDELIVERY
    Locate 8, 56: Print "  TOTAL  "; Using PRINTSTRING$; ZTOTAL
    Locate 5, 8: Print "    VOIDS  "; Using PRINTSTRING$; ZVOIDS
    Locate 6, 8: Print "  REFUNDS  "; Using PRINTSTRING$; ZREFUNDS
    Locate 7, 8: Print "  COUPONS  "; Using PRINTSTRING$; ZCOUPON

    Do Until A$ = Chr$(27)
        _Limit (30)
        A$ = InKey$
        If A$ = Chr$(0) + Chr$(59) Then GoSub PRINTREPORTZ
    Loop
    Close #1
    Exit Sub

    PRINTREPORTZ:
    If useprinter = 1 Then Open "LPT1" For Output As #2
    If useprinter = 2 Then Open "wlsdfkjn.dry" For Output As #2
    Call HEADER
    Print #2, ""
    Print #2, ""
    Print #2, ""
    REPORTHEAD$ = " TOTAL Z - READING REPORT "
    lined$ = "================================="
    Print #2, Space$(20 - Len(REPORTHEAD$) / 2); REPORTHEAD$
    Print #2, Space$(20 - Len(lined$) / 2); lined$
    Print #2, ""
    Print #2, Spc(8) + "  VOIDS"; Using "#,###,###.##"; ZVOIDS
    Print #2, Spc(8) + " REFUNDS"; Using "#,###,###.##"; ZREFUNDS
    Print #2, Spc(8) + " COUPONS"; Using "#,###,###.##"; ZCOUPON
    Print #2, ""
    Print #2, ""
    Print #2, Spc(18) + "SUBTOTAL"; Using "#,###,###.##"; ZSUBTOTAL
    Print #2, Spc(18) + "    TAX"; Using "#,###,###.##"; ZTAX
    Print #2, Spc(18) + "DELIVERY"; Using "#,###,###.##"; ZDELIVERY
    Print #2, Spc(27) + "-----------"
    Print #2, Spc(18) + "  TOTAL"; Using "#,###,###.##"; ZTOTAL
    For i = 1 To 4
        Print #2, ""
    Next i
    Call PRINTHEAD(2)
    For i = 1 To 20
        Print #2, ""
    Next
    Close #2
    Return
End Sub

Sub SAVE_ZREPORT
    Randomize Timer
    random$ = ""
    For a = 1 To 200: random$ = random$ + Chr$(Int(Rnd(a) * (223 + 32))): Next
    path$ = Environ$("LocalAppData") + "\WINDOWZ.Dll"
    Open path$ For Random As #1 Len = 200
    Field #1, 200 As A$
    '*************** PUT AMOUNTS IN FILE ******************************
    If _FileExists(path$) Then
        Get 1, 1
        ZSUBTOTAL = CVL(Mid$(A$, 56, 4)): ZSUBTOTAL = ZSUBTOTAL + subtotal '* 100
        Mid$(random$, 56, 4) = MKL$(ZSUBTOTAL)
        ZTAX = CVL(Mid$(A$, 89, 4)): ZTAX = ZTAX + tax '* 100
        Mid$(random$, 89, 4) = MKL$(ZTAX)
        ZTOTAL = CVL(Mid$(A$, 122, 4)): ZTOTAL = ZTOTAL + total '* 100
        Mid$(random$, 122, 4) = MKL$(ZTOTAL)
        ZVOIDS = CVL(Mid$(A$, 150, 4)): ZVOIDS = ZVOIDS + VOIDS '* 100
        Mid$(random$, 150, 4) = MKL$(ZVOIDS)
        ZREFUNDS = CVL(Mid$(A$, 175, 4)): ZREFUNDS = ZREFUNDS + REFUNDS '* 100
        Mid$(random$, 175, 4) = MKL$(ZREFUNDS)
        ZCOUPON = CVL(Mid$(A$, 180, 4)): ZCOUPON = ZCOUPON + COUPON '* 100
        Mid$(random$, 180, 4) = MKL$(ZCOUPON)
        ZDELIVERY = CVL(Mid$(A$, 190, 4)): ZDELIVERY = ZDELIVERY + del '* 100
        Mid$(random$, 190, 4) = MKL$(ZDELIVERY)
        LSet A$ = random$
        Put 1, 1
        Close 1
    Else
        Mid$(random$, 56, 4) = MKL$(ZSUBTOTAL)
        Mid$(random$, 89, 4) = MKL$(ZTAX)
        Mid$(random$, 122, 4) = MKL$(ZTOTAL)
        Mid$(random$, 150, 4) = MKL$(ZVOIDS)
        Mid$(random$, 175, 4) = MKL$(ZREFUNDS)
        Mid$(random$, 180, 4) = MKL$(ZCOUPON)
        Mid$(random$, 190, 4) = MKL$(ZDELEVERY)
        LSet A$ = random$
        Put 1, 1
        Close 1
    End If
    Exit Sub
End Sub

Sub SAVE_XREPORT
    Randomize Timer
    random$ = ""
    For a = 1 To 300: random$ = random$ + Chr$(Int(Rnd(a) * (223 + 32))): Next
    path$ = Environ$("LocalAppData") + "\WINDOWX.DLL"
    Open path$ For Random As #1 Len = 300
    Field #1, 300 As A$
    '*************** PUT AMOUNTS IN FILE ******************************
    If _FileExists(path$) Then
        Get 1, 1
        XSUBTOTAL = CVL(Mid$(A$, 56, 4)): XSUBTOTAL = XSUBTOTAL + subtotal '* 100
        Mid$(random$, 56, 4) = MKL$(XSUBTOTAL)
        XTAX = CVL(Mid$(A$, 89, 4)): XTAX = XTAX + tax '* 100
        Mid$(random$, 89, 4) = MKL$(XTAX)
        XTOTAL = CVL(Mid$(A$, 122, 4)): XTOTAL = XTOTAL + total '* 100
        Mid$(random$, 122, 4) = MKL$(XTOTAL)
        XVOIDS = CVL(Mid$(A$, 150, 4)): XVOIDS = XVOIDS + VOIDS '* 100
        Mid$(random$, 150, 4) = MKL$(XVOIDS)
        XREFUNDS = CVL(Mid$(A$, 175, 4)): XREFUNDS = XREFUNDS + REFUNDS '* 100
        Mid$(random$, 175, 4) = MKL$(XREFUNDS)
        XCOUPON = CVL(Mid$(A$, 180, 4)): XCOUPON = XCOUPON + COUPON '* 100
        Mid$(random$, 180, 4) = MKL$(XCOUPON)
        XDELIVERY = CVL(Mid$(A$, 190, 4)): XDELIVERY = XDELIVERY + del '* 100
        Mid$(random$, 190, 4) = MKL$(XDELIVERY)
        XCOUPCNT = CVL(Mid$(A$, 215, 4)): XCOUPCNT = XCOUPCNT + COUPCNT '* 100
        Mid$(random$, 215, 4) = MKL$(XCOUPCNT)
        XUNUSED4 = CVL(Mid$(A$, 225, 4)): XUNUSED4 = XUNUSED4 + UNUSED4 'Used for XVOIDCOUPDOLLARS
        Mid$(random$, 225, 4) = MKL$(XUNUSED4) ' USED FOR XVOIDCOUPDOLLARS
        XDELCNT = CVL(Mid$(A$, 235, 4)): XDELCNT = XDELCNT + DELCNT '* 100
        Mid$(random$, 235, 4) = MKL$(XDELCNT)
        XTOTALSALESCNT = CVL(Mid$(A$, 245, 4)): XTOTALSALESCNT = XTOTALSALESCNT + TOTALSALESCNT '* 100
        Mid$(random$, 245, 4) = MKL$(XTOTALSALESCNT)
        XUNUSED7 = CVL(Mid$(A$, 255, 4)): XUNUSED7 = XUNUSED7 + UNUSED7 '* 100
        Mid$(random$, 255, 4) = MKL$(XUNUSED7)
        XUNUSED8 = CVL(Mid$(A$, 265, 4)): XUNUSED8 = XUNUSED8 + UNUSED8 '* 100
        Mid$(random$, 265, 4) = MKL$(XUNUSED8)
        XUNUSED9 = CVL(Mid$(A$, 275, 4)): XUNUSED9 = XUNUSED9 + UNUSED9 '* 100
        Mid$(random$, 275, 4) = MKL$(XUNUSED9)
        XUNUSED10 = CVL(Mid$(A$, 285, 4)): XUNUSED10 = XUNUSED10 + UNUSED10 '* 100
        Mid$(random$, 285, 4) = MKL$(XUNUSED10)
        LSet A$ = random$
        Put 1, 1
        Close 1
    Else
        Mid$(random$, 56, 4) = MKL$(XSUBTOTAL)
        Mid$(random$, 89, 4) = MKL$(XTAX)
        Mid$(random$, 122, 4) = MKL$(XTOTAL)
        Mid$(random$, 150, 4) = MKL$(XVOIDS)
        Mid$(random$, 175, 4) = MKL$(XREFUNDS)
        Mid$(random$, 180, 4) = MKL$(XCOUPON)
        Mid$(random$, 190, 4) = MKL$(XDELIVERY)
        Mid$(random$, 215, 4) = MKL$(XCOUPCNT)
        Mid$(random$, 225, 4) = MKL$(XUNUSED4) 'USED FOR XVOIDCOUPDOLLARS
        Mid$(random$, 235, 4) = MKL$(XDELCNT)
        Mid$(random$, 245, 4) = MKL$(TOTALSALESCNT)
        Mid$(random$, 255, 4) = MKL$(XUNUSED7)
        Mid$(random$, 265, 4) = MKL$(XUNUSED8)
        Mid$(random$, 275, 4) = MKL$(XUNUSED9)
        Mid$(random$, 285, 4) = MKL$(XUNUSED10)
        LSet A$ = random$
        Put 1, 1
        Close 1
    End If
    Exit Sub
End Sub



Sub GET_XREPORT
    Cls
    Screen 0, 0, 7, 7
    View Print 1 To 25
    If CsrLin <> 25 Then Print Else flag = 1
    If CsrLin = 25 And flag = 1 Then Locate 25, 1:
    font& = _LoadFont(fontpath$, 20, "MONOSPACE,BOLD")
    _Font font&
    PRINTSTRING$ = "#,###,###.##"
    PRINTSTRING1$ = "###"
    path1$ = Environ$("LocalAppData") + "\WINDOWX.Dll"
    Open path1$ For Random As #1 Len = 300
    Field #1, 300 As A$
    Get 1, 1
    RANDOM$ = A$
    'Get totals from file Location
    XSUBTOTAL = CVL(Mid$(RANDOM$, 56, 4)) / 100
    XTAX = CVL(Mid$(RANDOM$, 89, 4)) / 100
    XTOTAL = CVL(Mid$(RANDOM$, 122, 4)) / 100
    XVOIDS = CVL(Mid$(RANDOM$, 150, 4)) / 100
    XREFUNDS = CVL(Mid$(RANDOM$, 175, 4)) / 100
    XCOUPON = CVL(Mid$(RANDOM$, 180, 4)) / 100
    XDELIVERY = CVL(Mid$(RANDOM$, 190, 4)) / 100
    XCOUPCNT = CVL(Mid$(RANDOM$, 215, 4))
    XVOIDCOUPDOLLARS = CVL(Mid$(RANDOM$, 225, 4)) / 100
    XDELCNT = CVL(Mid$(RANDOM$, 235, 4))
    XTOTALSALESCNT = CVL(Mid$(RANDOM$, 245, 4))
    XUNUSED7 = CVL(Mid$(RANDOM$, 255, 4)) / 100
    XUNUSED8 = CVL(Mid$(RANDOM$, 265, 4)) / 100
    XUNUSED9 = CVL(Mid$(RANDOM$, 275, 4)) / 100
    XUNUSED10 = CVL(Mid$(RANDOM$, 285, 4)) / 100

    '************************ REPORT FORMATTING ******************************
    Color , 1
    'LOCATE 1, 1
    Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
    Print "º                                                                              º"
    Print "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
    Print "º                                      º                                      º"
    Print "ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ×ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ"
    Print "º                                      º                                      º"
    Print "º                                      º                                      º"
    Print "º                                      º                                      º"
    Print "º                                      º                                      º"
    Print "º                                      º                                      º"
    Print "º                                      º                                      º"
    Print "º                                      º                                      º"
    Print "º                                      º                                      º"
    Print "º                                      º                                      º"
    Print "ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ                                      º"
    Print "º                                      º                                      º"
    Print "ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ                                      º"
    Print "º                                      º                                      º"
    Print "º                                      ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
    Print "º                                      º                                      º"
    Print "º                                      º                                      º"
    Print "º                                      º                                      º"
    Print "º                                      º                                      º"
    Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"

    Dim XREAD(3, 9)
    Open "R", 6, "CHECKNOFILE\CHKNO.NO", 1000: Field #6, 1000 As A$: Get 6, 1
    For A = 1 To 1000
        B$ = Mid$(A$, A, 1): If B$ <> "A" And B$ <> "B" And B$ <> "V" Then Exit For
    Next A: A = A - 1: B$ = Left$(A$, A): Close 6
    For B = 1 To A
        LEVEL = Asc(Mid$(B$, B, 1)) - 64
        If LEVEL < 3 Then
            CHKNO$ = "checknofile\" + LTrim$(Str$(B)) + ".TRN"
            Open CHKNO$ For Random As #3 Len = 80: Field #3, 80 As A$
    FIELD #3, 4 AS subtotal$, 4 AS tax$, 4 AS DEL$, 4 AS total$, 4 AS LINE1$, 1 AS SALESTYPE$, 4 AS COUPON$, 2 AS COUPCNT$, 4 AS XVOIDCOUPDOLLARS$, _
              2 as TOTALSALESCNT$, 8 as ORDERTIME$
            Get 3, 1
            XREAD(LEVEL, 1) = XREAD(LEVEL, 1) + CVL(subtotal$): XREAD(LEVEL, 2) = XREAD(LEVEL, 2) + CVL(tax$)
            XREAD(LEVEL, 3) = XREAD(LEVEL, 3) + CVL(DEL$): XREAD(LEVEL, 4) = XREAD(LEVEL, 4) + CVL(total$)
            XREAD(LEVEL, 5) = XREAD(LEVEL, 5) + CVL(COUPON$): XREAD(LEVEL, 7) = XREAD(LEVEL, 7) + 1
            XREAD(LEVEL, 8) = XREAD(LEVEL, 8) + CVI(COUPCNT$): If CVI(DEL$) > 0 Then XREAD(LEVEL, 6) = XREAD(LEVEL, 6) + 1
        End If
        Close 3
    Next B
    For B = 1 To 8: XREAD(3, B) = XREAD(1, B) + XREAD(2, B): Next B
    Locate 19, 40: Print "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
    'END BOX BUILD
    Color 12, 1
    Header0$ = "COMPLETED + PENDING SALES TOTALS"
    Header1$ = "DAILY SALES REPORT TOTALS  - [X-REPORT]"
    Header2$ = "COMPLETED SALES TOTALS"
    Header3$ = "PENDING SALES TOTALS"
    Locate 2, 2: Print Space$(40 - Len(Header1$) / 2); Header1$
    Color 2,
    Locate 16, 2: Print Space$(18 - Len(Header0$) / 2); Header0$
    Locate 4, 2: Print Space$(18 - Len(Header2$) / 2); Header2$
    Locate 4, 41: Print Space$(18 - Len(Header3$) / 2); Header3$
    Color 7, 4
    Locate 20, 41: Print "  [F1] = Print X-Report                "
    Locate 21, 41: Print "  [F2] = Print X-Report & Clear Totals "
    Locate 22, 41: Print " [Esc] = EXIT                          "
    Color 15, 1

    '**************************************************************************************************
    '*                        COMPLETED SALES LINES FOR DISPLAY X-REPORT                            *
    '**************************************************************************************************
    Locate 6, 2: Print "    SUB SALES"; Using PRINTSTRING$; XREAD(2, 1) / 100 'XSUBTOTAL
    Locate 7, 2: Print "          TAX"; Using PRINTSTRING$; XREAD(2, 2) / 100 'XTAX
    Locate 8, 2: Print "    DELIVERY"; Using PRINTSTRING$; XREAD(2, 3) / 100 'XDELIVERY
    Locate 9, 2: Print "TOTAL COUPONS"; Using PRINTSTRING$; XREAD(2, 5) / 100 'XCOUPON
    Locate 10, 2: Print "  TOTAL SALES"; Using PRINTSTRING$; XREAD(2, 4) / 100 'XTOTAL
    Locate 11, 2: Print " VOID COUPONS"; Using PRINTSTRING$; XVOIDCOUPDOLLARS
    Locate 12, 2: Print "  TOTAL VOID"; Using PRINTSTRING$; XTOTALVOID
    Locate 13, 2: Print "    SUB VOIDS"; Using PRINTSTRING$; XVOIDS
    Locate 14, 2: Print "      REFUNDS"; Using PRINTSTRING$; XREFUNDS
    Locate 8, 27: Print ""; Using PRINTSTRING1$; XDELCNT
    Locate 9, 27: Print ""; Using PRINTSTRING1$; XCOUPCNT
    Locate 10, 27: Print ""; Using PRINTSTRING1$; XTOTALSALESCNT

    '**************************************************************************************************
    '*                        PENDING SALES LINES FOR DISPLAY X-REPORT                              *
    '**************************************************************************************************
    Locate 6, 42: Print "PENDING-SUB SALES"; Using PRINTSTRING$; XREAD(1, 1) / 100
    Locate 7, 42: Print "      PENDING-TAX"; Using PRINTSTRING$; XREAD(1, 2) / 100
    Locate 8, 42: Print " PENDING-DELIVERY"; Using PRINTSTRING$; XREAD(1, 3) / 100
    Locate 8, 73: Print ""; Using PRINTSTRING1$; XREAD(1, 6)
    Locate 9, 42: Print " PENDING-COUPON $"; Using PRINTSTRING$; XREAD(1, 5) / 100
    Locate 9, 73: Print ""; Using PRINTSTRING1$; XREAD(1, 8)
    Locate 10, 42: Print "PENDING-TOT SALES"; Using PRINTSTRING$; XREAD(1, 4) / 100
    Locate 10, 73: Print ""; Using PRINTSTRING1$; XREAD(1, 7)

    '**************************************************************************************************
    '*                    COMPLETED and PENDING SALES LINES FOR DISPLAY X-REPORT                      *
    '**************************************************************************************************
    Locate 18, 2: Print "  SUB SALES"; Using PRINTSTRING$; XREAD(3, 1) / 100
    Locate 19, 2: Print "        TAX"; Using PRINTSTRING$; XREAD(3, 2) / 100
    Locate 20, 2: Print "    DELIVERY"; Using PRINTSTRING$; XREAD(3, 3) / 100
    Locate 20, 27: Print Using PRINTSTRING1$; XREAD(3, 6)
    Locate 21, 2: Print "    COUPON $"; Using PRINTSTRING$; XREAD(3, 5) / 100
    Locate 21, 27: Print Using PRINTSTRING1$; XREAD(3, 8)
    Locate 22, 2: Print " TOTAL SALES"; Using PRINTSTRING$; XREAD(3, 4) / 100
    Locate 22, 27: Print Using PRINTSTRING1$; XREAD(3, 7)
    '**************************** END COMPLETED & PENDING LINES ****************************************
    'file$ = "checknofile\"
    'DO UNTIL A$ = CHR$(27)
    'A$ = INKEY$
    'IF A$ = CHR$(0) + CHR$(59) THEN GOSUB PRINTREPORTX: CLOSE #1
    'IF A$ = CHR$(0) + CHR$(60) THEN GOSUB PRINTREPORTX: CLOSE #1
    'IF NOT _DIREXISTS(file$ + DATE$) THEN
    'SHELL _HIDE "mkdir checknofile\" + DATE$
    'SHELL _HIDE "copy checknofile\*.*  checknofile\" + DATE$
    'CLOSE: KILL "CHECKNOFILE\*.TRN": KILL "CHECKNOFILE\*.NO"
    'KILL ENVIRON$("LocalAppData") + "\WINDOWX.Dll": COLOR 15, 0
    'ELSE
    'SHELL _HIDE "copy checknofile\*.*  checknofile\" + DATE$
    'CLOSE: KILL "CHECKNOFILE\*.TRN": KILL "CHECKNOFILE\*.NO"
    'KILL ENVIRON$("LocalAppData") + "\WINDOWX.Dll": COLOR 15, 0
    'END IF

    'CALL GET_XREPORT: A$ = CHR$(27)
    'LOOP
    'CLOSE #1
    'CALL MENUCHOICE

    file$ = "checknofile\"
    RANDOMLINELABEL:
    A$ = "": While A$ = "": A$ = InKey$: Wend
    If A$ = Chr$(0) + Chr$(59) Then GoSub PRINTREPORTX
    If A$ = Chr$(0) + Chr$(60) Then GoSub PRINTREPORTX: Close #1: GoTo KILLFILES
    If A$ = Chr$(27) Then Close 1: Exit Sub
    GoTo RANDOMLINELABEL
    KILLFILES:
    If Not _DirExists(file$ + Date$) Then
        Shell _Hide "mkdir checknofile\" + Date$
        Shell _Hide "move checknofile\*.*  checknofile\" + Date$
        Kill Environ$("LocalAppData") + "\WINDOWX.Dll": Color 15, 0
    Else
        Shell _Hide "move checknofile\*.*  checknofile\" + Date$
        Close:
        Kill Environ$("LocalAppData") + "\WINDOWX.Dll": Color 15, 0
    End If
    Exit Sub








    PRINTREPORTX:
    If useprinter = 1 Then Open "LPT1" For Output As #2
    If useprinter = 2 Then Open "wlsdfkjn.dry" For Output As #2
    Call PRINTHEAD(1)
    Print #2, ""
    Print #2, ""
    Print #2, ""
    REPORTHEAD$ = " X - READING DAILY REPORT "
    lined$ = "================================="
    lined1$ = "________________________________________"
    Print #2, Space$(20 - Len(REPORTHEAD$) / 2); REPORTHEAD$
    Print #2, Space$(20 - Len(lined$) / 2); lined$
    Print #2, ""
    Print #2, Space$(20 - Len(lined1$) / 2); lined1$
    Print #2, ""
    dateline$ = Date$ + Spc(9) + CLOCK$
    Print #2, Space$(20 - Len(dateline$) / 2); dateline$
    Print #2, Space$(20 - Len(lined1$) / 2); lined1$
    Print #2, ""
    Print #2, ""
    Print #2, Spc(8) + "  VOIDS"; Using "#,###,###.##"; XVOIDS
    Print #2, Spc(8) + " REFUNDS"; Using "#,###,###.##"; XREFUNDS
    Print #2, Spc(8) + "  VENDOR"; Using "#,###,###.##"; XVENDOR
    Print #2, Spc(8) + " COUPONS"; Using "#,###,###.##"; XCOUPON
    Print #2, ""
    Print #2, ""
    Print #2, Spc(20) + "SUBTOTAL"; Using "#,###,###.##"; XSUBTOTAL
    Print #2, Spc(20) + "    TAX"; Using "#,###,###.##"; XTAX
    Print #2, Spc(20) + "DELIVERY"; Using "#,###,###.##"; XDELIVERY
    Print #2, Spc(29) + "-----------"
    Print #2, Spc(20) + "  TOTAL"; Using "#,###,###.##"; XTOTAL
    For i = 1 To 8
        Print #2, ""
    Next
    Call PRINTHEAD(2)
    For i = 1 To 20
        Print #2, ""
    Next
    Close #2
    Return
End Sub

Sub PASSWORD
    Screen 0, 0, 12, 12
    Color 15, 1
    Locate 14, 3: Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
    Locate 15, 3: Print "º                            º"
    Locate 16, 3: Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
    Locate 15, 4: Print "PASSORD:"
End Sub

Sub VOID
    del = delivery * 100
    refresh:
    '******************************************************************************************************************************
    '                        THIS SECTION WAS ADDED TO KEEP FROM CREATING A BLANK CHKNO.NO FILE
    '******************************************************************************************************************************
    Call CHECKFORFILE
    '******************************************************************************************************************************
    '                                                  END ADDED SECTION
    '******************************************************************************************************************************
    Open "checknofile\CHKNO.NO" For Random As #3 Len = 1000
    Field #3, 1000 As A$
    Get 3, 1: B$ = A$: Close 3
    For A = 1 To 1000
        If Mid$(B$, A, 1) = Chr$(15) Then Exit For
    Next

    ENDER = A - 1
    RR$ = "\                            \  ###.##"
    SS$ = "###.##"
    SSI$ = "-###.##"
    Screen 0, 0, 17, 17
    Color 15, 1
    Cls
    GoSub CreateScreen
    If ENDER = 0 Then
        Color 15, 4
        Locate 10, 10: Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
        Locate 11, 10: Print "º  NO SALES HAS BEEN RECORDED YET º"
        Locate 12, 10: Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
        Locate 13, 10: Print "                                  "
        Locate 14, 10: Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
        Locate 15, 10: Print "º    PRESS ANY KEY TO CONTINUE  º"
        Locate 16, 10: Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
        Sleep
        Exit Sub
    End If

    X = 66: Y = 7: FCOLOR = 15: BCOLOR = 3: DECIMAL$ = "####": NUMB = 1: NUMBER = CN

    'CALL NUMBERS(X, Y, FCOLOR, BCOLOR, DECIMAL$, NUMBER, KEYPRESS)
    CN = 1
    BB7: chkno = CN: COUPON = 0
    Open "checknofile\CHKNO.NO" For Random As #3 Len = 1000
    Field #3, 1000 As A$
    Get 3, 1: B$ = A$: Close 3
    If Mid$(B$, CN, 1) = Chr$(65) Then Color , 2: Locate 7, 73: Print " OPEN "
    If Mid$(B$, CN, 1) = Chr$(66) Then Color , 6: Locate 7, 73: Print "CLOSED"
    If Mid$(B$, CN, 1) = Chr$(86) Then Color , 4: Locate 7, 73: Print " VOID "
    Color 15, 1
    CHKNO$ = "checknofile\" + LTrim$(Str$(chkno)) + ".TRN"
    'CHKNO$ = LTRIM$(STR$(chkno)) + ".TRN"
    For Y = 2 To 5: Locate Y, 53: Print Space$(27);: Next
    If Not _FileExists(CHKNO$) Then
        Color 15, 1
        Cls
        Locate 4, 2: Print Space$(38 - Len("SORRY, I COULD NOT FIND A CHECK NUMBER  " + CHKNO$) / 2); "    I COULD NOT FIND A CHECK NUMBER  " + CHKNO$
        Locate 11, 2: Print Space$(38 - Len("CHECK ALREADY PAID  or  CHECK DOESN'T EXIST") / 2); "    CHECK PAID  or  CHECK DOESN'T EXIST"
        Locate 15, 2: Print Space$(38 - Len("PRESS ANY KEY TO CONTINUE") / 2); " PRESS ANY KEY TO CONTINUE"
        Color 15, 1
        GoSub ResetTotals
        Sleep
        Call BEGINNING
    End If
    line1 = 0
    Open CHKNO$ For Random As #3 Len = 80
    Field #3, 80 As A$
FIELD #3, 4 AS subtotal$, 4 AS tax$, 4 AS DEL$, 4 AS total$, 4 AS LINE1$, 1 AS SALESTYPE$, 4 AS COUPON$, 2 AS COUPCNT$, 4 AS VOIDCOUPDOLLARS$, _
          2 as TOTALSALESCNT$
    Get 3, 1
    subtotal = CVL(subtotal$): tax = CVL(tax$): COUPON = CVL(COUPON$): COUPCNT = CVI(COUPCNT$): VOIDCOUPDOLLARS = CVL(VOIDCOUPDOLLARS$)
    del = CVL(DEL$): total = CVL(total$): line1 = CVL(LINE1$): Styper$ = SALESTYPE$: TOTALSALESCNT = CVI(TOTALSALESCNT$)
    If Styper$ = "D" Then DELCNT = 1 Else DELCNT = 0
    Get 3, 2: NAME1$ = RTrim$(A$)
    Get 3, 3: STREET1$ = RTrim$(A$)
    Get 3, 4: CITY1$ = RTrim$(A$)
    Get 3, 5: Back$ = RTrim$(A$)
    Field #3, 30 As Desc$, 10 As price$
    For A = 1 To line1
        Get 3, A + 5
        RECEIPT$(A, 1) = RTrim$(Desc$): RECEIPT$(A, 2) = RTrim$(price$)
    Next A
    For A = 1 To 7
        Get 3
        INSTRUCT$(A) = Left$(A$, 27)
        88 I = InStr(INSTRUCT$(A), Chr$(0))
        If I Then Mid$(INSTRUCT$(A), I, 1) = " ": GoTo 88

    Next

    Close
    LINES = line1: OFFSET = 0: updown = 0
    GoSub SCROLLER
    Locate 18, 53: Print " Subtotal =====> "
    Locate 19, 53: Print "      Tax =====> "
    Locate 20, 53: Print "  Del Fee =====> "
    Locate 21, 73: Print "ÄÄÄÄÄÄ"
    Locate 22, 53: Print "Total Due =====> "
    Locate 18, 73: Print Using SS$; subtotal / 100
    Locate 19, 73: Print Using SS$; tax / 100
    Locate 20, 73: Print Using SS$; del / 100
    Locate 22, 73: Print Using SS$; total / 100
    Locate 2, 53: Print NAME1$
    Locate 3, 53: Print STREET1$
    Locate 4, 53: Print CITY1$
    Locate 5, 53: Print Back$
    LINES = line1: GoSub SCROLLER
    BB8: X = 66: Y = 7: FCOLOR = 15: BCOLOR = 3: DECIMAL$ = "####": NUMB = 1: NUMBER = CN
    Call NUMBERS(X, Y, FCOLOR, BCOLOR, DECIMAL$, NUMBER, KEYPRESS)
    If KEYPRESS = 27 Then
        GoSub ResetTotals
        Exit Sub
    End If
    If KEYPRESS = 13 Then CN = NUMBER: GoTo BB7
    If KEYPRESS = 72 Then updown = -1: GoSub SCROLLER: GoTo BB8
    If KEYPRESS = 80 Then updown = 1: GoSub SCROLLER: GoTo BB8
    If KEYPRESS = 73 Then
        CN = CN - 1: If CN = 0 Then CN = ENDER
        GoTo BB7
    End If
    If KEYPRESS = 81 Then
        CN = CN + 1: If CN > ENDER Then CN = 1
        GoTo BB7
    End If
    If KEYPRESS = 59 Then GoTo 2
    If KEYPRESS = 63 Then
        'PRINTSTRING$ = "##,###,###.##"
        path$ = Environ$("LocalAppData") + "\WINDOWX.Dll"
        If Mid$(B$, CN, 1) <> "V" Then
            If Mid$(B$, CN, 1) = "A" Then GoTo TT
            Open path$ For Random As #1 Len = 300
            Field #1, 300 As A$
            Get 1, 1
            RANDOM$ = A$
            'Get totals from file Location
            XSUBTOTAL = CVL(Mid$(RANDOM$, 56, 4))
            XTAX = CVL(Mid$(RANDOM$, 89, 4))
            XTOTAL = CVL(Mid$(RANDOM$, 122, 4))
            XVOIDS = CVL(Mid$(RANDOM$, 150, 4))
            XREFUNDS = CVL(Mid$(RANDOM$, 175, 4))
            XCOUPON = CVL(Mid$(RANDOM$, 180, 4))
            XDELIVERY = CVL(Mid$(RANDOM$, 190, 4))
            XCOUPCNT = CVL(Mid$(RANDOM$, 215, 4))
            XVOIDCOUPDOLLARS = CVL(Mid$(RANDOM$, 225, 4))
            XDELCNT = CVL(Mid$(RANDOM$, 235, 4))
            XTOTALSALESCNT = CVL(Mid$(RANDOM$, 245, 4))
            'IF del <> 0 THEN XDELCNT = XDELCNT - 1
            XSUBTOTAL = XSUBTOTAL - subtotal
            XTAX = XTAX - tax
            XTOTAL = XTOTAL - total
            XCOUPON = XCOUPON - COUPON
            XDELCNT = XDELCNT - DELCNT
            XVOIDS = XVOIDS - subtotal
            XDELIVERY = XDELIVERY - del
            XCOUPCNT = XCOUPCNT - COUPCNT
            XTOTALSALESCNT = XTOTALSALESCNT - 1
            XVOIDCOUPDOLLARS = XVOIDCOUPDOLLARS + COUPON
            Mid$(RANDOM$, 56, 4) = MKL$(XSUBTOTAL)
            Mid$(RANDOM$, 89, 4) = MKL$(XTAX)
            Mid$(RANDOM$, 122, 4) = MKL$(XTOTAL)
            Mid$(RANDOM$, 150, 4) = MKL$(XVOIDS)
            Mid$(RANDOM$, 175, 4) = MKL$(XREFUNDS)
            Mid$(RANDOM$, 180, 4) = MKL$(XCOUPON)
            Mid$(RANDOM$, 190, 4) = MKL$(XDELIVERY)
            Mid$(RANDOM$, 215, 4) = MKL$(XCOUPCNT)
            Mid$(RANDOM$, 225, 4) = MKL$(XVOIDCOUPDOLLARS)
            Mid$(RANDOM$, 235, 4) = MKL$(XDELCNT)
            Mid$(RANDOM$, 245, 4) = MKL$(XTOTALSALESCNT)
            LSet A$ = RANDOM$
            Put 1, 1
            Close #1
            path$ = Environ$("LocalAppData") + "\WINDOWZ.Dll"
            Open path$ For Random As #1 Len = 200
            Field #1, 200 As A$
            Get 1, 1
            RANDOM$ = A$
            'Get totals from file
            ZSUBTOTAL = CVL(Mid$(RANDOM$, 56, 4))
            ZTAX = CVL(Mid$(RANDOM$, 89, 4))
            ZTOTAL = CVL(Mid$(RANDOM$, 122, 4))
            ZVOIDS = CVL(Mid$(RANDOM$, 150, 4))
            ZREFUNDS = CVL(Mid$(RANDOM$, 175, 4))
            ZCOUPON = CVL(Mid$(RANDOM$, 180, 4))
            ZDELIVERY = CVL(Mid$(RANDOM$, 190, 4))

            ZSUBTOTAL = ZSUBTOTAL - subtotal
            ZTAX = ZTAX - tax
            ZTOTAL = ZTOTAL - total
            ZCOUPON = ZCOUPON - COUPON
            ZVOIDS = ZVOIDS - subtotal
            ZDELIVERY = ZDELIVERY - del

            Mid$(RANDOM$, 56, 4) = MKL$(ZSUBTOTAL)
            Mid$(RANDOM$, 89, 4) = MKL$(ZTAX)
            Mid$(RANDOM$, 122, 4) = MKL$(ZTOTAL)
            Mid$(RANDOM$, 150, 4) = MKL$(ZVOIDS)
            Mid$(RANDOM$, 175, 4) = MKL$(ZREFUNDS)
            Mid$(RANDOM$, 180, 4) = MKL$(ZCOUPON)
            Mid$(RANDOM$, 190, 4) = MKL$(ZDELIVERY)
            LSet A$ = RANDOM$
            Put 1, 1
            Close #1
            TT: Open "checknofile\CHKNO.NO" For Random As #3 Len = 1000
            Field #3, 1000 As A$
            Get 3, 1: B$ = A$
            Mid$(B$, CN, 1) = "V"
            LSet A$ = B$
            Put 3, 1
            Close 3
            GoTo 6
        Else
            1 If Mid$(B$, CN, 1) = "V" Then
                Color 15, 4
                Locate 17, 5: Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
                Locate 18, 5: Print "º This Check Is Already Void. You may reprint this check only º"
                Locate 19, 5: Print "º            PRESS [F1] TO REPRINT THIS CHECK                º"
                Locate 20, 5: Print "º    PRESS [ENTER] TO RETURN TO THE VOID/REPRINT SCREEN      º"
                Locate 21, 5: Print "º        PRESS [Esc] TO RETURN TO THE MAIN SCREEN            º"
                Locate 22, 5: Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
                Sleep
                Call NUMBERS(X, Y, FCOLOR, BCOLOR, DECIMAL$, NUMBER, KEYPRESS)
                If KEYPRESS = 13 Then
                    GoSub CreateScreen
                    GoTo BB7
                ElseIf KEYPRESS = 27 Then
                    GoSub ResetTotals
                    Exit Sub
                ElseIf KEYPRESS = 59 Then
                    GoTo 2
                Else
                    GoTo 1
                End If
            End If
        End If
    End If
    GoTo refresh
    2 If KEYPRESS = 59 Then
        6 REPRINT1$ = "*********************************"
        REPRINT2$ = "*** REPRINT  REPRINT  REPRINT ***"
        REPRINT3$ = "*** THIS CHECK HAS BEEN VOIDED **"
        If useprinter = 1 Then Open "LPT1:" For Output As #2
        If useprinter = 2 Then Open "wlsdfkjn.dry" For Output As #2
        Print #2, Space$(20 - Len(REPRINT1$) / 2); REPRINT1$
        Print #2, Space$(20 - Len(REPRINT2$) / 2); REPRINT2$
        Print #2, Space$(20 - Len(REPRINT1$) / 2); REPRINT1$
        If Mid$(B$, CN, 1) = "V" Then
            Print #2, Space$(20 - Len(REPRINT1$) / 2); REPRINT1$
            Print #2, Space$(20 - Len(REPRINT3$) / 2); REPRINT3$
            Print #2, Space$(20 - Len(REPRINT1$) / 2); REPRINT1$
        End If
        For I = 1 To 2
            Print #2, ""
        Next I
        Call PRINTHEAD(1)
        lined$ = "________________________________________"
        Print #2, Space$(20 - Len(lined$) / 2); lined$
        dateline$ = Date$ + Spc(9) + CLOCK$
        Print #2, ""
        Print #2, Space$(20 - Len(dateline$) / 2); dateline$
        Print #2, ""
        Print #2, Space$(20 - Len(DELCLOCK$) / 2); DELCLOCK$
        Print #2, Space$(20 - Len(lined$) / 2); lined$
        Print #2, ""
        Print #2, NAME1$
        Print #2, STREET1$
        Print #2, CITY1$
        Print #2, Back$
        Print #2, Space$(20 - Len(lined$) / 2); lined$
        Print #2, ""
        If Styper$ = "C" Then Styper$ = "CARRYOUT"
        If Styper$ = "P" Then Styper$ = "PICKUP"
        If Styper$ = "D" Then Styper$ = "DELIVERY"
        Print #2, Chr$(29)
        Star$ = String$(40, "-")
        Print #2, Chr$(31); Space$(10 - Len(Styper$) / 2); Styper$
        Print #2, Chr$(29)
        Print #2, Space$(20 - Len(Star$) / 2); Star$
        Print #2, ""
        Print #2, ""
        For count = 1 To line1
            If Val(RECEIPT$(count, 2)) = 0.00 Then
                Print #2, RECEIPT$(count, 1)
            Else
                Print #2, Using RR$; RECEIPT$(count, 1); Val(RECEIPT$(count, 2)) / 100
            End If
        Next count
        If typer$ = " PICK UP " Or typer$ = "CARRY OUT" Then
            For I = 1 To 3
                Print #2, ""
            Next I
            Print #2, Spc(25); "Subtotal "; Using SS$; subtotal / 100
            Print #2, Spc(25); "    Tax "; Using SS$; tax / 100
            Print #2, Spc(36); "-------"
            Print #2, Spc(25); "  Total "; Using SS$; total / 100

        Else
            For I = 1 To 3
                Print #2, ""
            Next I
            Print #2, Spc(25); "Subtotal "; Using SS$; subtotal / 100
            Print #2, Spc(25); "    Tax "; Using SS$; tax / 100
            Print #2, Spc(25); "Delivery "; Using SS$; del / 100
            Print #2, Spc(33); "-------"
            Print #2, Spc(25); "  Total "; Using SS$; total / 100
        End If
        CheckNumber$ = "Check-> "
        For counter = 1 To 5
            Print #2, ""
        Next counter
        If Styper$ = "DELIVERY" Then Print #2, Space$(20 - Len(Message2$) / 2); Message2$: Print #2, "": Print #2, ""
        Call PRINTHEAD(2)
        For counter = 1 To 5
            Print #2, ""
        Next counter
        Print #2, Space$(20 - Len(chkno) / 2); CheckNumber$; " "; chkno
        For counter = 1 To 17
            Print #2, ""
        Next counter
        Close #2
        GoSub ResetTotals
        'CALL MENUCHOICE
        Exit Sub
    End If
    GoTo BB8

    ResetTotals:
    del = 0: LINES = 0: DESCRIPTION$ = "": PRICE = 0: line1 = 0: subtotal = 0: tax = 0
    total = 0: NAME1$ = "": STREET1$ = "": CITY1$ = "": phone$ = "": Back$ = "": typer$ = ""
    COUPON = 0: ReDim INSTRUCTION$(7)
    If COUPCNT <> 0 Then COUPCNT = COUPCNT - 1
    Return

    CreateScreen:
    Color 15, 1
    Print Chr$(201) + String$(50, Chr$(205)) + Chr$(203) + String$(27, Chr$(205)) + Chr$(187)
    Print Chr$(186) + Spc(50) + Chr$(186) + Spc(27) + Chr$(186)
    Print Chr$(204) + String$(50, Chr$(205)) + Chr$(185) + Spc(27) + Chr$(186)
    For I = 1 To 2
        Print Chr$(186) + String$(50, Chr$(255)) + Chr$(186) + Spc(27) + Chr$(186)
    Next I
    Print Chr$(186) + String$(50, Chr$(255)) + Chr$(204) + String$(27, Chr$(205)) + Chr$(185)
    Print Chr$(186) + String$(50, Chr$(255)) + Chr$(186) + Spc(27) + Chr$(186)
    Print Chr$(186) + String$(50, Chr$(255)) + Chr$(204) + String$(27, Chr$(205)) + Chr$(185)
    For I = 1 To 8
        Print Chr$(186) + String$(50, Chr$(255)) + Chr$(186) + Spc(27) + Chr$(186)
    Next I
    Print Chr$(186) + String$(50, Chr$(255)) + Chr$(204) + String$(27, Chr$(205)) + Chr$(185)
    For I = 1 To 5
        Print Chr$(186) + String$(50, Chr$(255)) + Chr$(186) + Spc(27) + Chr$(186)
    Next I
    Print Chr$(200) + String$(50, Chr$(205)) + Chr$(202) + String$(27, Chr$(205)) + Chr$(188)
    Title$ = "VOID/REPRINT CHECK"
    Color 12, 1: Locate 2,: Print Space$(25 - Len(Title$) / 2); Title$: Color 15, 1
    Locate 2, 1: Print Chr$(186)
    Locate 7, 53: Print "CHECK NUMBER"
    Locate 9, 56: Color 13: Print "[ESC] = EXIT"
    Locate 10, 56: Print "[" + Chr$(24) + Chr$(25) + "]" + "  = SCROLL ORDER"
    Locate 11, 56: Print "[F1]  = REPRINT CHECK"
    Locate 12, 56: Print "[F5]  = VOID CHECK"
    Locate 16, 53: Print "[PGUP] = PREV" + " " + "[PGDN] = NEXT": Color 15, 1
    Return

    SCROLLER:
    PRINTSTRING$ = "####    \                              \ ####.## ": WIDTHS = Len(PRINTSTRING$)
    printstring2$ = "####    \                                  \" + "    ": WIDTHS = Len(printstring2$)
    X = 2: Y = 3: HEIGHT = 19
    If updown <> 0 Then
        OFFSET = OFFSET + updown * -1
        If OFFSET = LINES * -1 Then OFFSET = OFFSET + 1
        If OFFSET > 0 Then OFFSET = 0
    End If
    For A = 0 To HEIGHT - 1
        B = A - HEIGHT + LINES + 1 + OFFSET
        Locate A + Y + 1, X
        If B < 1 Then
            Print Spc(WIDTHS);
        Else
            If Val(RECEIPT$(B, 2)) = 0 Then
                Print Using printstring2$; B; RECEIPT$(B, 1);
            Else
                Print Using PRINTSTRING$; B; RECEIPT$(B, 1); Val(RECEIPT$(B, 2)) / 100;
            End If
        End If
    Next
    Return
End Sub

Sub HEADER
    Call PRINTHEAD(1)
    lined$ = "________________________________________"
    Print #2, Space$(20 - Len(lined$) / 2); lined$
    dateline$ = Date$ + Spc(9) + CLOCK$
    Print #2, ""
    Print #2, Space$(20 - Len(dateline$) / 2); dateline$
    Print #2, Space$(20 - Len(lined$) / 2); lined$
    Print #2, ""
End Sub


Sub TYPEINSTRUCTIONS
    Color 15, 3
    For A = 1 To 7
        Locate A + 8, 53: Print Using "\" + Space$(25) + "\"; INSTRUCT$(A)
    Next
    Y = 1
    55 INPUTER$ = INSTRUCT$(Y)
    Call INPUTS(53, Y + 8, 15, 5, 27, 0, INPUTER$, KEYPRESS, 0)
    INSTRUCT$(Y) = INPUTER$
    If KEYPRESS = 13 Or KEYPRESS = 80 Then Y = Y + 1: If Y = 8 Then Y = 1
    If KEYPRESS = 72 Then Y = Y - 1: If Y = 0 Then Y = 7
    If KEYPRESS <> 27 Then GoTo 55
    Color 15, 1
    For A = 1 To 7
        Locate A + 8, 53: Print Using "\" + Space$(25) + "\"; INSTRUCT$(A)
    Next
End Sub

Sub PRINTCOUPONS
    Dim COUPON$(11, 6), COUPON(3, 6), EVEN$(1), SETS$(1), RNDM!(60000)
    If _FileExists("COUPONS.DAT") Then
        Open "R", 15, "COUPONS.DAT", 40: Field #15, 39 As A$
        For B = 1 To 6: For A = 1 To 10
                Get 15: COUPON$(A, B) = A$: If InStr(COUPON$(A, B), Chr$(0)) Then COUPON$(A, B) = Space$(39)
        Next A, B
        For A = 1 To 6
            For B = 10 To 1 Step -1
                If RTrim$(COUPON$(B, A)) <> "" Then Exit For
            Next B
            COUPON(3, A) = B
        Next A

        Get 15, 61: For B = 1 To 6: For A = 1 To 2: COUPON(A, B) = CVI(Mid$(A$, (B - 1) * 4 + A * 2 - 1, 2)): Next A, B
        SETTING = Asc(Mid$(A$, 27, 1))
        COUPONCOUNT = CVI(Mid$(A$, 25, 2))
        COUPONCOUNT = COUPONCOUNT + 1: If COUPONCOUNT > 30000 Then COUPONCOUNT = 0
        '    COUPONCOUNT = 0
        B$ = A$: Mid$(B$, 25, 2) = MKI$(COUPONCOUNT): LSet A$ = B$: Put 15, 61
        Close 15
    Else
        A = A
        'CLS: PRINT "NO COUPON FILE EXISTS": END
    End If
    Randomize Timer
    If SETTING = 1 Then
        For A = 1 To 6
            X = COUPON(1, A)
            If COUPON(1, A) > 0 And COUPON(3, A) > 0 Then
                If COUPON(2, X) = 0 Then
                    If COUPONCOUNT / X = COUPONCOUNT \ X Then GoSub PRINTCOUPON
                Else
                    If Int(Rnd(1) * X) = 0 Then GoSub PRINTCOUPON
                End If
            End If
        Next A
    Else
        C = 0
        For A = 1 To 6
            If COUPON(1, A) > 0 And COUPON(3, A) > 0 Then
                For B = 1 To COUPON(1, A): RNDM!(B + C) = A: Next B
                C = B + C - 1
            End If
        Next A
        If C > 0 Then J = Int(Rnd(1) * (C)) + 1: A = RNDM!(J): GoSub PRINTCOUPON
        'J = INT(RND(1) * (C)) + 1: A = RNDM!(J): GOSUB PRINTCOUPON
    End If
    Exit Sub

    PRINTCOUPON:


    Print #2, "****************COUPON****************"
    For B = 1 To COUPON(3, A): Print #2, COUPON$(B, A): Next
    Print #2, String$(39, "*")
    Print #2, ""
    Return
End Sub

'SHOWCOUPONS:
'LPRINT "COUNT = "; COUNT
'LPRINT "SETTING = "; SETTING
'FOR A = 1 TO 6
'LPRINT "***************************"
'FOR B = 1 TO 3: LPRINT COUPON(B, A),: NEXT B: LPRINT
'FOR B = 1 TO COUPON(3, A): LPRINT COUPON$(B, A): NEXT B
'NEXT A
'RETURN



Sub SEEMENUS (a$)
    999 Data [F1],[F2],[F3],[F4],[F5],[F6],[F7],[F8],[F9],[F10],[F11],[F12],[HOME],[INSERT],[END],[DELETE],[P],[L],[X],[Z]
    Screen , , 1, 1
    Color 15, 1: Cls: Restore 999: B$ = "    ": Locate 1, 35: Print "Choose menu": Print
    For A = 1 To 20
        Read a$: RSet B$ = a$
        If FKEY(A, 0) Then Locate , 30: Print B$; " "; LTrim$(MENULABEL$(A))
    Next A: 'PRINT: PRINT TAB(35); "[ESC] Quit"
    a$ = "": While a$ = "": a$ = InKey$: Wend
    Screen 0, 0, 0, 0
End Sub
you have to rename the database file from PITABLE.txt to PITABLE.DB

Print this item

  CHAT for QB64
Posted by: MasterGy - 12-17-2022, 11:03 PM - Forum: MasterGy - Replies (3)

I would like to meet in a QB64 3D world one day. On a beach...or anywhere Smile

I started learning this TCP/IP thing. It worked and I was very happy. That's when I realized that if the clients don't send coordinates, but text, then we actually get a chat program.

The engine is running. I rented a server and we can talk to each other through it!
Try it !

Code: (Select All)
Randomize Timer



'profile data -----------------------------------------------------------------------------------------

my_name$ = "user" 'your nickname
my_info$ = "i am ...." 'short introduction
my_color&& = _RGB32(55 + 200 * Rnd, 55 + 200 * Rnd, 55 + 200 * Rnd, 255) 'your color
'----------------------------------------------------------------------------------------------------------

Const fc$ = "sudlikam"

connect_ip$ = "95.138.193.62"
connect_port$ = "60000"
mess_c = 20


my_name$ = my_name$ + "_" + LTrim$(Str$(Int(100 * Rnd(1))))

bg&& = _RGB32(30, 10, 10): _Title "client - " + my_name$
max_client = 100: Dim c$(max_client - 1, 9), active(max_client - 1), cpic(max_client - 1, 1), mess$(mess_c - 1), v(max_client - 1, 1)
monx = 1000: mony = 550: mon = _NewImage(monx, mony, 32): Screen mon

'connection
Dim Shared connection&, dat$, mess$
Do: _Limit 10: If InKey$ = Chr$(27) Then System
    connection& = _OpenClient("TCP/IP:" + connect_port$ + ":" + connect_ip$)
    If connection& = 0 Then Print "no connection"
Loop Until connection&



send "0nam" + my_name$: send "1inf" + my_info$
send "4col" + Right$("00" + Hex$(_Red(my_color&&)), 2) + Right$("00" + Hex$(_Green(my_color&&)), 2) + Right$("00" + Hex$(_Blue(my_color&&)), 2) + Right$("00" + Hex$(_Alpha(my_color&&)), 2)


Do: _Limit 20

    If Abs(Timer - sign_timer) > 2 Then send "sign": sign_timer = Timer

    Do
        s$ = get2$
        If Len(s$) Then
            Select Case Mid$(s$, 5, 4)
                Case "5pos", "0nam", "1inf", "3msg", "4col"
                    c$(Val(Left$(s$, 4)), Val(Mid$(s$, 5, 1))) = Mid$(s$, 9)
                Case "addc": active(Val(Left$(s$, 4))) = 1: Sound 2000, .2
                Case "delc": active(Val(Left$(s$, 4))) = 0
                    If cpic(Val(Left$(s$, 4)), 1) Then _FreeImage cpic(Val(Left$(s$, 4)), 0)
                    cpic(Val(Left$(s$, 4)), 1) = 0
                Case "cmsg": mess$(cm) = Mid$(s$, 9): cm = (cm + 1) Mod mess_c
                Case "srok": srok = Timer
            End Select
        End If
    Loop While Len(s$)





    'show header
    While _MouseInput: Wend


    Color my_color&&: Print my_name$; "- client   ",
    If Abs(srok - Timer) > 5 Then
        Color _RGB32(255, 0, 0): Print "Server no answer"
    Else
        Color _RGB32(0, 255, 0): Print "Server is OK ! "
    End If

    Color _RGB32(150, 150, 150): Print String$(monx / 8 - 1, "-"): Print "connected : ";

    startx = 14 * 8: starty = 2 * 16: show_info = -1
    For c = 0 To max_client - 1: If active(c) = 0 Then _Continue
        If c$(c, 4) = "" Then
            Color _RGB32(150, 150, 150)
        Else
            For t = 0 To 3: co(t) = Val("&h" + Mid$(c$(c, 4), t * 2 + 1, 2)): Next t
            Color _RGB32(0, 0, 0), _RGB32(co(0), co(1), co(2), co(3))
        End If
        If Len(c$(c, 0)) * 8 + startx > monx - 10 Then startx = 0: starty = starty + 16
        _PrintString (startx, starty), c$(c, 0)
        If _MouseX > startx And _MouseX < startx + Len(c$(c, 0)) * 8 And _MouseY > starty And _MouseY < starty + 16 Then show_info = c
        startx = startx + (Len(c$(c, 0)) + 2) * 8
    Next c

    If show_info <> -1 Then
        Color _RGB32(100, 100, 100), _RGB32(255, 255, 255): startx = _MouseX
        If startx + Len(c$(show_info, 1)) * 8 > monx - 10 Then startx = monx - 10 - Len(c$(show_info, 1)) * 8
        _PrintString (startx, _MouseY + 16), c$(show_info, 1)
    End If


    Color , bg&&

    'show message my type
    Color my_color&&: If Int(Timer * 10) And 1 Then cr$ = "_" Else cr$ = " "
    Locate mony / 16 - 2, 1: Print mess$; cr$;

    'show messages
    For t = 0 To mess_c - 1
        y = mony / 16 - 2 - mess_c: Locate y + t, 1: s$ = mess$((cm + t) Mod mess_c)
        Color _RGBA32(Val("&h" + Mid$(s$, 1, 2)), Val("&h" + Mid$(s$, 3, 2)), Val("&h" + Mid$(s$, 5, 2)), Val("&h" + Mid$(s$, 7, 2)))
    Print Mid$(s$, 19): Next t

    _Display: Color , _RGB32(0, 0, 0): Cls


    Line (0, mony - (mess_c + 4) * 16)-(monx, mony), bg&&, BF

    'type message
    k$ = InKey$
    If Len(k$) Then
        a = Asc(k$)
        If a = 27 Then System
        If a = 13 And Len(mess$) Then send "3msg" + mess$: mess$ = ""
        If a = 8 Then mess$ = Left$(mess$, Len(mess$) - 1)
        felt = (a > 31 And a < 91) Or (a > 96 And a < 123)
        If felt Then mess$ = mess$ + k$
    End If

Loop


err1: hiba = 1: Resume Next

Sub send (s$): s2$ = s$ + fc$: Put connection&, , s2$: End Sub
Function get2$
    If Len(dat$) = 0 Then Get connection&, , st$: dat$ = dat$ + st$
    If Len(dat$) = 0 Then Exit Function
    ok = -1: For t = 1 To Len(dat$)
        If Mid$(dat$, t, Len(fc$)) = fc$ Then ok = t: Exit For
    Next t
    If ok = -1 Then Exit Function
    get2$ = Left$(dat$, ok - 1): dat$ = Mid$(dat$, ok + Len(fc$))
End Function

Print this item

  QBJS - Web Chat
Posted by: dbox - 12-17-2022, 06:38 PM - Forum: QBJS, BAM, and Other BASICs - Replies (7)

You guys inspired me.  I saw all of the recent chat server posts and wondered how hard it would be to create a web chat client in QBJS.  For anyone interested you can try out the end result here:

QB Web Chat

The server is written in QB64.  I used luke's simple HTTP server as a starting point and modified it to be an HTTP chat server.  Here is the server code in case you want to play around with it:

Code: (Select All)
' QB Chat Server
' Author: dbox*
' *This originally started as luke's simple HTTP server.
' It has been modified to serve as an HTTP chat server.
' Here is the original source attribution:
' -------------------------------------------------------------------------------------
' HTTP 1.1 Compliant Web Server
' Author: luke
' Source: https://www.qb64.org/forum/index.php?topic=2052.0
' This program is made available for you to use, modify and distribute it as you wish,
' all under the condition you do not claim original authorship.
' -------------------------------------------------------------------------------------
$Console:Only
Option _Explicit
DefLng A-Z

Const MAX_CONNECTIONS = 8
Dim PORT As Integer: PORT = 8080
If _CommandCount > 0 Then
    PORT = Val(Command$(1))
End If

Const FALSE = 0
Const TRUE = -1
Dim Shared CRLF As String
CRLF = Chr$(13) + Chr$(10)
Const HTTP_10 = 1
Const HTTP_11 = 11
Const HTTP_GET = 1
Const HTTP_HEAD = 2
Const HTTP_POST = 3
Type connection_t
    handle As Long
    read_buf As String
    http_version As Integer
    method As Integer
    request_uri As String
    content_length As Integer
End Type

Type http_error_t
    code As Integer
    message As String
    connection As Integer
End Type

Type file_error_t
    failed As Integer
    code As Integer
End Type

Dim i
Dim num_active_connections
Dim server_handle
Dim Shared Connections(1 To MAX_CONNECTIONS) As connection_t
Dim Shared Http_error_info As http_error_t
Dim Shared File_error_info As file_error_t

'---------------------------------------------------------------------
' Chat server-specific initialization
'---------------------------------------------------------------------
Type Message
    sender As String
    message As String
    time As String
End Type

Const MAX_MESSAGE = 100
Dim Shared messages(MAX_MESSAGE) As Message
Dim Shared cmsg As _Unsigned Long
cmsg = 0

Open "chatlog.txt" For Append As #1
'---------------------------------------------------------------------

On Error GoTo error_handler

server_handle = _OpenHost("TCP/IP:" + LTrim$(Str$(PORT)))
Print "Listening on port:" + Str$(PORT)
Do
    If num_active_connections < MAX_CONNECTIONS Then
        Dim new_connection
        new_connection = _OpenConnection(server_handle)
        If new_connection Then
            num_active_connections = num_active_connections + 1
            For i = 1 To MAX_CONNECTIONS
                If Connections(i).handle = 0 Then
                    Dim empty_connection As connection_t
                    Connections(i) = empty_connection
                    Connections(i).handle = new_connection
                    num_active_connections = num_active_connections - 1
                    Exit For
                End If
            Next i
        End If
    End If

    For i = 1 To MAX_CONNECTIONS
        If Connections(i).handle Then
            Dim buf$
            Get #Connections(i).handle, , buf$
            If buf$ <> "" Then
                ' This is a bit of a hack workaround.
                ' We have no gaurantee that the sent message will not be fragmented.
                ' So there's a chance the full message will not be sent all at once.
                ' Unfortunately, there's no way I know of to tell from the connection
                ' if there is more to read.
                ' Hence, we sleep for .05 seconds and try to read from the connection again.
                ' We'll repeat this as long as we keep reading content.
                ' Will this ensure we read the entire body content?
                ' No, but it seems to work for most cases.
                While buf$ <> ""
                    Connections(i).read_buf = Connections(i).read_buf + buf$
                    _Delay .05
                    Get #Connections(i).handle, , buf$
                Wend
                process_request i
                http_error_complete:
            End If
        End If
    Next i
    _Limit 240
Loop



error_handler:
If Err = 100 Then 'HTTP error
    'Print "HTTP error"; Http_error_info.code; Http_error_info.message; " for connection"; Http_error_info.connection
    Resume http_error_complete
End If
'Print "error"; Err; "on line"; _ErrorLine
End

file_error_handleyour:
File_error_info.failed = TRUE
File_error_info.code = Err
Resume Next

Sub http_send_status (c, code, message As String)
    Dim s$
    s$ = "HTTP/1.1" + Str$(code) + " " + message + CRLF
    Put #Connections(c).handle, , s$
End Sub

Sub http_send_header (c, header As String, value As String)
    Dim s$
    s$ = header + ": " + value + CRLF
    Put #Connections(c).handle, , s$
End Sub

Sub http_end_headers (c)
    Put #Connections(c).handle, , CRLF
End Sub

Sub http_send_body (c, body As String)
    Put #Connections(c).handle, , body
End Sub

Sub http_do_get (c)
    http_do_post c
End Sub

Sub http_do_head (c)
    Dim s$
    s$ = "HTTP/1.1 200 OK" + CRLF + CRLF
    Put #Connections(c).handle, , s$
End Sub

Sub http_do_post (c)
    Dim As String action, body
    action = Connections(c).request_uri
    body = Connections(c).read_buf

    Dim response As String

    Select Case action
        Case "/connect": response = HandleConnect(body)
        Case "/disconnect": response = HandleDisconnect(body)
        Case "/get": response = HandleGet(body)
        Case "/send": response = HandleSend(body)
    End Select

    http_send_status c, 200, "OK"
    http_send_header c, "Content-Type", "text/plain"
    http_send_header c, "Content-Length", LTrim$(Str$(Len(response)))
    http_send_header c, "Access-Control-Allow-Origin", "*"
    http_send_header c, "Connection", "close"
    http_end_headers c
    http_send_body c, response

    close_connection c
End Sub

Function HandleConnect$ (body As String)
    AddMessage "system", body + " has entered the chat"
    HandleConnect$ = Str$(cmsg - 1)
End Function

Function HandleDisconnect$ (body As String)
    AddMessage "system", body + " has left the chat"
    HandleDisconnect$ = Str$(cmsg - 1)
End Function

Function HandleGet$ (body As String)
    Dim fmsg As Integer
    Dim response As String
    fmsg = Val(_Trim$(body))
    response = "["
    Dim As Integer i, idx
    For i = fmsg + 1 To cmsg
        idx = (i - 1) Mod MAX_MESSAGE + 1
        response = response + CRLF + "{ " + _
                   Q$("from") + ":" + Q$(messages(idx).sender) +  ", " + _
                   Q$("msg") + ":" + Q$(messages(idx).message) + ", " + _
                   Q$("time") + ":" + Q$(messages(idx).time) + " }"
        If i < cmsg Then response = response + ","
    Next i
    response = response + CRLF + "]"
    HandleGet$ = response
End Function

Function HandleSend$ (body As String)
    Print "send: ["; body; "]"
    Dim sender As String
    sender = "Unknown"

    Dim idx As Integer
    idx = InStr(body, ":")
    If idx > 0 Then
        sender = Mid$(body, 1, idx - 1)
        body = Mid$(body, idx + 1)
    End If
    AddMessage sender, _Trim$(body)
    HandleSend$ = Str$(cmsg)
End Function

Sub AddMessage (sender As String, message As String)
    Dim idx As Integer
    cmsg = cmsg + 1
    idx = (cmsg - 1) Mod MAX_MESSAGE + 1
    messages(idx).sender = JSONString(sender)
    messages(idx).message = JSONString(message)
    messages(idx).time = Date$ + " " + Time$

    LogMessage messages(idx)
End Sub

Function JSONString$ (s As String)
    s = Replace(_Trim$(s), Chr$(13) + Chr$(10), "\n")
    s = Replace(s, Chr$(10), "\n")
    s = Replace(s, Chr$(34), "\" + Chr$(34))
    JSONString$ = s
End Function

Sub LogMessage (msg As Message)
    Print #1, msg.time; " - "; msg.sender
    Print #1, msg.message
End Sub

Function Replace$ (s As String, searchString As String, newString As String)
    Dim ns As String
    Dim i As Integer

    Dim slen As Integer
    slen = Len(searchString)

    For i = 1 To Len(s) '- slen + 1
        If Mid$(s, i, slen) = searchString Then
            ns = ns + newString
            i = i + slen - 1
        Else
            ns = ns + Mid$(s, i, 1)
        End If
    Next i

    Replace = ns
End Function


Function Q$ (value As String)
    Q$ = Chr$(34) + value + Chr$(34)
End Function


Sub close_connection (c)
    Close #Connections(c).handle
    Connections(c).handle = 0
End Sub


Sub process_request (c)
    Dim eol
    Dim l As String
    Do
        eol = InStr(Connections(c).read_buf, CRLF)
        If eol = 0 Then Exit Sub
        l = Left$(Connections(c).read_buf, eol - 1)
        Connections(c).read_buf = Mid$(Connections(c).read_buf, eol + 2)
        If Connections(c).http_version = 0 Then 'First line not yet read
            process_start_line c, l
        Else
            If l = "" Then
                'headers complete; act upon request now
                Select Case Connections(c).method
                    Case HTTP_GET
                        http_do_get c
                    Case HTTP_POST
                        http_do_post c
                    Case HTTP_HEAD
                        http_do_head c
                End Select
                Exit Sub
            Else
                process_header c, l
            End If
        End If
    Loop
End Sub

Sub process_start_line (c, l As String)
    '7230 3.1.1
    'METHOD uri HTTP/x.y
    Dim sp1, sp2
    sp1 = InStr(l, " ")
    If sp1 = 0 Then http_error 400, "Bad Request", c

    '7231 4.3
    Select Case Left$(l, sp1 - 1)
        Case "GET"
            Connections(c).method = HTTP_GET
        Case "HEAD"
            Connections(c).method = HTTP_HEAD
        Case "POST"
            Connections(c).method = HTTP_POST
        Case Else
            http_error 501, "Not Implemented", c
    End Select

    sp2 = InStr(sp1 + 1, l, " ")
    If sp2 = 0 Or sp2 - sp1 = 1 Then http_error 400, "Bad Request", c
    Connections(c).request_uri = Mid$(l, sp1 + 1, sp2 - sp1 - 1)

    '7230 2.6
    If Mid$(l, sp2 + 1, 5) <> "HTTP/" Then
        http_error 400, "Bad Request", c
    End If
    Select Case Mid$(l, sp2 + 6)
        Case "1.0"
            Connections(c).http_version = HTTP_10
        Case "1.1"
            Connections(c).http_version = HTTP_11
        Case Else
            http_error 505, "HTTP Version Not Supported", c
    End Select
End Sub

Sub process_header (c, l As String)
    ' ignoring headers for now
End Sub

Sub http_error (code, message As String, connection)
    http_send_status connection, code, message
    http_send_header connection, "Content-Length", "0"
    http_send_header connection, "Connection", "close"
    http_end_headers connection
    close_connection connection
    Http_error_info.code = code
    Http_error_info.message = message
    Http_error_info.connection = connection
    Error 100
End Sub

If you want to connect to your own server just change the address at the top of the chat window to http://localhost:8080 (or whatever port you decide to use).

It was definitely an interesting exercise and gave me a number of ideas about new web functionality that I might want to add to QBJS's standard libraries.

Here is the client code in case you want to hot rod that side:
Code: (Select All)
Import Dom From "lib/web/dom.bas"

Dim Shared As Object txtAddress, txtUsername, btnConnect, textbox, msgPanel
Dim Shared lastMsg As Integer
Dim Shared username As String
Dim Shared connected As Integer
Dim Shared refreshing As Integer
Dim Shared sending As Integer
Dim Shared sndMsg As Integer

_Title "QB Chat"
sndMsg = _SndOpen("https://raw.githubusercontent.com/boxgaming/qbjs/main/samples/apps/new-message.ogg")

InitUI

SetTimeout sub_Refresh, 1000

' HTTP Event Handlers
' ---------------------------------------------------------------
Sub OnConnect (response)
    If Not connected Then
        lastMsg = Val(response)
        connected = -1
        txtAddress.disabled = true
        txtUsername.disabled = true
        btnConnect.innerText = "Disconnect"
    Else
        connected = 0
        txtAddress.disabled = false
        txtUsername.disabled = false
        btnConnect.innerText = "Connect"
    End If
End Sub

Sub OnSend (response)
    sending = 0
End Sub

Sub Refresh
    If connected And Not refreshing Then
        refreshing = -1
        HttpSend txtAddress.value + "/get", "POST", lastMsg, sub_OnRefresh
    End If
    SetTimeout sub_Refresh, 1000
End Sub

Sub OnRefresh (response)
    Dim playSound As Integer
    Dim res As Object
    res = JSON.parse(response)
    Dim i as Integer
    For i = 0 To res.length-1
        AddMessage res[i]
        If res[i].from <> username Then
            playSound = -1
        End If
    Next i
    lastMsg = lastMsg + res.length
    msgPanel.scrollTop = msgPanel.scrollHeight;
    If playSound Then _SndPlay sndMsg
    refreshing = 0
End Sub

Sub OnRefresError
    refreshing = 0
End Sub


' UI Event Handlers
' ----------------------------------------------------------
Sub OnClickConnect
    If txtUsername.value = "" Then
        Dom.Alert "Enter a username"
        Exit Sub
    End If
   
    If Not connected Then
        username = txtUsername.value
        Print "Setting username: [" + username + "]"
        HttpSend txtAddress.value + "/connect", "POST", username, sub_OnConnect
    Else
        HttpSend txtAddress.value + "/disconnect", "POST", username, sub_OnConnect
    End If   
End Sub

Function OnKeyPress (event)
    If event.keyCode = 13 Then
        'Print textbox.value
        Dim msg as String
        msg = _Trim$(textbox.value)
        If msg <> "" Then SendMessage msg
        OnKeyPress = false
    End If
End Function

Sub SendMessage (msg As String)
    Dim timeout As Integer
    While sending And timeout < 1000
        _Delay .01
        timeout = timeout + 1
    Wend
    sending = -1
    Dim body As String
    body = username + ":" + _Trim$(textbox.value)
    'Print "sending: [ " + body + " ]"
    HttpSend txtAddress.value + "/send", "POST", body, sub_OnSend
    textbox.value = ""
End Sub

Sub OnResize
    'msgPanel.height = Dom.Container().height - 100
    msgPanel.style.height = (_ResizeHeight - 200) + "px"
End Sub

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

Sub InitUI
    Dim As Object container, panel, btnSend, apanel
   
    Dom.GetImage(0).style.display = "none"
   
    container = Dom.Container
    container.style.letterSpacing = "normal"
    container.style.backgroundColor = "#333"
    Dom.Event window, "resize", sub_OnResize
   
    ' Create the login panel
    apanel = Dom.Create("div")
    apanel.style.display = "grid"
    apanel.style.margin = "auto 15%"
    apanel.style.textAlign = "left"
    apanel.style.fontWeight = "bold"
    Dom.Create "div", apanel, "Host"
    Dom.Create "div", apanel, "Username"
    Dom.Create "div", apanel
    apanel.style.gridTemplateColumns = "auto auto auto"
    txtAddress = Dom.Create("input", apanel, "https://chat.boxgaming.co")
    txtUsername = Dom.Create("input", apanel)
    btnConnect = Dom.Create("button", apanel, "Connect")
    Dom.Event btnConnect, "click", sub_OnClickConnect

    ' Create the message window
    msgPanel = Dom.Create("div")
    msgPanel.style.backgroundColor = "#444"
    msgPanel.style.overflowY = "auto"
    msgPanel.style.height = "300px"
    msgPanel.style.margin = "auto 15%"
    msgPanel.style.textAlign = "left"
    msgPanel.style.padding = "10px"

    ' Create send message control
    Dim sendLabel As Object
    panel = Dom.Create("div")
    panel.style.margin = "auto 15%"
    sendLabel = Dom.Create("div", panel, "Send Message")
    sendLabel.style.textAlign = "left"
    sendLabel.style.fontWeight = "bold"
    sendLabel.style.backgroundColor = "#666"
    sendLabel.style.padding = "4px"
    sendLabel.style.color = "#ccc"
    textbox = Dom.Create("textarea", panel)
    textbox.style.width = "100%"
    textbox.style.height = "100px"
    Dom.Event textbox, "keydown", func_OnKeyPress
   
    OnResize
End Sub

Sub AddMessage (msg As Object)
    Dim As Object mc, s, t, m

    mc = Dom.Create("div", msgPanel)
    mc.style.marginBottom = "10px"

    s = Dom.Create("div", mc)
    If msg.from = "system" Then
        s.style.color = "#00f4af"
    Else
        s.style.color = "#00aff4"
    End If
    s.style.fontWeight = "bold"
    s.innerHTML = msg.from

    t = Dom.Create("span", s)
    t.style.color = "#999"
    t.style.fontWeight = "normal"
    t.style.marginLeft = "8px"
    t.style.fontSize = ".8em"
    t.innerHTML = msg.time

    m = Dom.Create("div", mc)
    m.style.color = "#efefef"
    m.style.whiteSpace = "pre"
    m.innerHTML = msg.msg
   
End Sub


Sub HttpSend(url, method, message, callbackFn, errorCallbackFn)
$If Javascript Then
    const client = new XMLHttpRequest();
    client.open(method, url);
    client.setRequestHeader("Content-Length", message.length);
    client.send(message);
    client.onreadystatechange = function() {
        if (this.readyState == 4) {
            if (this.status == 200) {
                if (callbackFn) {
                    callbackFn(this.responseText);
                }
            }
            else { // assume any other status is an error
                if (errorCallbackFn) {
                    errorCallbackFn(this.responseText);
                }
            }
        }
    };
$End If
End Sub

Sub SetTimeout(callbackFn, millis)
$If Javascript Then
    setTimeout(callbackFn, millis);
$End If
End Sub

[Image: screenshot.png]

Print this item

  DAY 037: FREEFILE
Posted by: Pete - 12-17-2022, 12:30 PM - Forum: Keyword of the Day! - Replies (8)

We interrupt your regularly scheduled program for this brief commercial message!

Tired of spending your hard earned money on an overly-priced file? Well now you can avoid those high fees with this tried and true QB Keyword of the Day, FREEFILE!

SYNTAX filenum& = FREEFILE

Usage: Retrieves the next available open file handle.

So what's the benefit?

Well, for most small apps, we just code...

Code: (Select All)
OPEN "myfile.dat" FOR INPUT AS #1
'De Foo Foo Foo De blah, blah, blah...
CLOSE #1

However, let's say we make a big app, that uses 30 files, and some of them, depending on operations being called, stay opened!

Hmm, now keeping track of all those file numbers would require considerable thought. In fact, the only way to not to get into trouble, by using a file number which is still opened, would be to assign a unique number to each file operation, or... do it the easy way by letting the system figure it out for us. Well, that's exactly what FREEFILE does!

But first, please note: Even though we can assign a variable to FREEFILE before we OPEN the file, "You actually have to Open the file to trigger a value." Thanks, Dimster. So
please make sure you use good coding practice and associate each FREEFILE statement with each corresponding OPEN statement.

Code: (Select All)
DEFLNG f
ON Rob GOSUB ThePolice

ThePolice:
filenum1 = FREEFILE
OPEN "myfile-abc.dat" FOR INPUT AS filenum1
'De Foo Foo Foo De blah, blah, blah...

filenum2 = FREEFILE
OPEN "myfile-def.dat" FOR INPUT AS filenum2
'Is all I will output to you...

IF mydata$ = "EOF" THEN CLOSE #filenum1

filenum3 = FREEFILE
OPEN "myfile-ghi.dat" FOR INPUT AS filenum3
'De Foo Foo Foo De blah, blah, blah...

filenum4 = FREEFILE
OPEN "myfile-jkl.dat" FOR INPUT AS filenum4
' And now this FREEFILE demo's through.
CLOSE #filenum1, #filenum2, #filenum3, #filenum4
RETURN

So in the code example above, FREEFILE will assign the file handles either as 1, 2, 3, and 4 or, if mydata$ = "EOF" and the first file gets closed... 1, 2, 1, 3. Remember, FREEFILE is tracking your file use, and depending on conditional statements, like in our above example, your file numbering results will vary. Also, always remember to use good coding practices. Don't have a list of pre-assigned FREEFILE assignments, at the top of your program, without each corresponding file actually being opened. You will get duplicate file handles.

Oh, and if you forget to add the # symbol, don't worry; it's optional. I just like using it as a search marker. What;s that? You don't need no stinkin' search marker. Alrighty then, save yourself some typing by omitting it. Like I always say to my wife, "It takes a big man to omit when he's wrong!" Okay Steve, enough with the "big man" jokes, already...

And now back to your regularly scheduled program, DEEP Thoughts, by jack handy...

Do woke coders OPEN files as non-BINARY?

Pete

Print this item

  Snowman screen saver playing 17 MIDI Christmas songs
Posted by: Dav - 12-17-2022, 12:23 PM - Forum: Christmas Code - Replies (11)

I updated my old Snowman screen saver to test the experimental (and $UNSTABLE) MIDI playback feature of QB64PE.  This is a simple looping animation that plays 17 different Christmas songs continuously.  It's just something nice to have on the screen whenever you need a snowy atmosphere.  

It sure is nice to have MIDI playback in QB64PE, the only negative is that it takes a rather long time to open a MIDI file.  Loading these 17 MIDI files takes a couple minutes on my PC.  I found that MIDI feature is most stable when opening MIDI files at the beginning and leaving them open throughout the program.  Opening/Closing them over and over in the program caused hangups, so I ended up just loading them all at startup and doing a _SNDSTOP when changing to a start new song.

I'll post the code here for the curious, but you will need to download the archive to run it.  You will need QB64PE v3.2 or higher to use the $MIDISOUNDFONT metacommand.  I haven't tested this in Linux yet, but I guess it will work if the Linux version also supports the new MIDI metacommand.

- Dav


.zip   snowman-v103.zip (Size: 710.24 KB / Downloads: 94)

Code: (Select All)
'==========
'SNOWMAN.BAS v1.03
'===========
'Play Snowman animation while playing 17 Christmas songs.
'Coded by Dav for QB64PE, DEC/2022
'ALL MEDIA SOURCES FOUND IN PUBLIC DOMAIN
'
'=======================================================================
'NOTE: THIS PROGRAM REQUIRES QB64-PE v3.2 OR HIGHER TO RUN & USE MIDI
'=======================================================================
'
'CONTROLS:
'           WHILE PLAYING, USE LEFT & RIGHT ARROWS TO SKIP SONGS.
'           ANY OTHER KEY QUITS THE SAVER
'
'The screen saver will start playing a random song.  You an skip up/down
'to different songs using the left/right arrow keys.  Pressing any other
'key will quit the program.
'
'NOTE: It takes a minute or two to load all the MIDI files on startup.
'Please be patient while they load, and enjoythe Christmas screen saver.
'
'=======================================================================

$UNSTABLE:MIDI
PRINT "=============================="
PRINT "SNOWMAN SCREENSAVER FOR QB64PE"
PRINT "(please wait while files load)"
PRINT "=============================="
PRINT
PRINT "Init MIDI soundfont...";
$MIDISOUNDFONT:DEFAULT
PRINT "OK!"

'=== Check the animation file
PRINT "Checking animation file...";
file$ = "snowman.dat"
OPEN file$ FOR BINARY AS #1
IF LOF(1) = 0 THEN
    PRINT "SNOWMAN.DAT NOT FOUND!"
    CLOSE 1: KILL file$
    END
END IF
IF LOF(1) <> 800528 THEN
    PRINT "INVALID SNOWMAN.DAT!"
    CLOSE 1
    END
END IF
PRINT "OK!"

'=== Build the MIDI song list..

trackmax = 17 '17 midi files
DIM song$(1 TO trackmax), songhand&(1 TO trackmax)
'name each one
song$(1) = "frosty.mid"
song$(2) = "hark.mid"
song$(3) = "away.mid"
song$(4) = "angels.mid"
song$(5) = "carol.mid"
song$(6) = "joy.mid"
song$(7) = "deck.mid"
song$(8) = "wethree.mid"
song$(9) = "holynite.mid"
song$(10) = "godrest.mid"
song$(11) = "itcame.mid"
song$(12) = "ohcome.mid"
song$(13) = "noel.mid"
song$(14) = "silent.mid"
song$(15) = "town.mid"
song$(16) = "jingle.mid"
song$(17) = "wewish.mid"

FOR s = 1 TO trackmax
    PRINT "Loading MIDI file"; s; "of"; trackmax; ": "; song$(s); "...";
    songhand&(s) = _SNDOPEN(song$(s), "stream")
    IF songhand&(s) = 0 THEN
        PRINT "Error opening file: "; song$(s)
        END
    END IF
    PRINT "OK!"
NEXT

'=== start playing a random track
RANDOMIZE TIMER
track = INT(RND * trackmax) + 1
_SNDPLAY songhand&(track)


SCREEN 13: _FULLSCREEN _SQUAREPIXELS , _SMOOTH

DO
    SEEK 1, 129
    FOR f% = 1 TO 15
        FF& = SEEK(1): FRM$ = INPUT$(16, 1)
        FrameSize& = CVL(MID$(FRM$, 1, 4))
        chunks% = CVI(MID$(FRM$, 7, 2))
        d$ = INKEY$
        IF d$ <> "" THEN
            SELECT CASE d$
                CASE CHR$(0) + CHR$(77)
                    _SNDSTOP songhand&(track)
                    track = track + 1
                    IF track > trackmax THEN track = 1
                    _SNDPLAY songhand&(track)
                CASE CHR$(0) + CHR$(75)
                    _SNDSTOP songhand&(track)
                    track = track - 1
                    IF track < 1 THEN track = trackmax
                    _SNDPLAY songhand&(track)
                CASE ELSE: EXIT DO
            END SELECT
        END IF
        FOR C% = 1 TO chunks%
            Fpos& = SEEK(1)
            CD$ = INPUT$(6, 1)
            ChunkSize& = CVL(MID$(CD$, 1, 4))
            ChunkType% = CVI(MID$(CD$, 5, 2))
            Fpos& = Fpos& + ChunkSize&
            SELECT CASE ChunkType%
                CASE 11
                    Clr% = 0
                    paks% = ASC(INPUT$(2, 1))
                    FOR d% = 1 TO paks%
                        skip% = ASC(INPUT$(1, 1))
                        change% = ASC(INPUT$(1, 1))
                        IF change% = 0 THEN change% = 256
                        Clr% = Clr% + skip%
                        FOR s% = 1 TO change%
                            OUT &H3C8, Clr%
                            OUT &H3C9, ASC(INPUT$(1, 1))
                            OUT &H3C9, ASC(INPUT$(1, 1))
                            OUT &H3C9, ASC(INPUT$(1, 1))
                            Clr% = Clr% + 1
                        NEXT
                    NEXT
                CASE 12
                    skip% = CVI(INPUT$(2, 1))
                    change% = CVI(INPUT$(2, 1))
                    FOR y% = skip% TO change% + (skip% - 1)
                        ppos& = SEEK(1)
                        C$ = INPUT$(500, 1): m% = 1
                        paks% = ASC(MID$(C$, m%, 1)): m% = m% + 1: x% = 0
                        FOR d% = 1 TO paks%
                            s% = ASC(MID$(C$, m%, 1))
                            p% = ASC(MID$(C$, m% + 1, 1))
                            m% = m% + 2: x% = x% + s%
                            IF p% > 127 THEN
                                p% = (256 - p%)
                                LINE (x%, y%)-STEP(p% - 1, 0), ASC(MID$(C$, m%, 1))
                                x% = x% + p%: m% = m% + 1
                            ELSE
                                Row$ = MID$(C$, m%, p%)
                                m% = m% + p%
                                FOR g% = 0 TO p% - 1
                                    PSET (x% + g%, y%), ASC(MID$(Row$, g% + 1, 1))
                                NEXT
                                x% = x% + p%
                            END IF
                        NEXT
                        SEEK #1, ppos& + m% - 1: C$ = ""
                    NEXT
                CASE 16
                    x% = 0
                    FOR y% = 0 TO 199
                        Row$ = INPUT$(320, 1): p% = 320
                        FOR g% = 0 TO p% - 1
                            PSET (x% + g%, y%), ASC(MID$(Row$, g% + 1, 1))
                        NEXT
                    NEXT
                CASE ELSE: CLOSE 1: EXIT DO
            END SELECT
            SEEK #1, Fpos&
        NEXT
        SEEK 1, FF& + FrameSize&
        _DISPLAY
        _LIMIT 12
    NEXT

    IF NOT _SNDPLAYING(songhand&(track)) THEN
        _SNDSTOP songhand&(track)
        track = track + 1
        IF track > trackmax THEN track = 1
        _SNDPLAY songhand&(track)
    END IF

LOOP

_SNDSTOP songhand&(track)
_SNDCLOSE songhand&(track)

CLOSE 1
SYSTEM

Print this item

  Munching Squares
Posted by: CharlieJV - 12-17-2022, 04:09 AM - Forum: QBJS, BAM, and Other BASICs - Replies (2)

https://basicanywheremachine.neocities.o...ng_squares

Print this item