Code: Select all
' Program: Box
' Target: Windows 10/11 Console
' Draw a box on a Windows console
' Tested with US English Windows 10 and Consolas font
' Subroutine DrawBox Copyright 2022 Donald S Montaine
' Released under the Creative Commons CC-BY license
'=========================================
' SUBROUTINES
'=========================================
sub DrawBox(Byval BoxType as string, _
Byval StartY as integer, _
Byval StartX as integer, _
Byval BoxWidth as integer, _
Byval BoxHeight as integer, _
Byval ForeColor as integer, _
Byval BackColor as integer)
' Line drawing codes ' T codes are unused in this program
' dim LTee as integer 'Left Tee Line Drawing Character
' dim RTee as integer 'Right Tee Line Drawing Character
' dim TTee as integer 'Top Tee Line Drawing Character
' dim BTee as integer 'Bottom Tee Line Drawing Character
dim UpLCnr as integer 'Upper Left Corner Line Drawing Character
dim UpRCnr as integer 'Upper Right Corner Line Drawing Character
dim HorzLn as integer 'Horizontal Line Drawing Character
dim VertLn as integer 'Vertical Line Drawing Character
dim LwLCnr as integer 'Lower Left Corner Line Drawing Character
dim LwRCnr as integer 'Lower Right Corner Line Drawing Character
dim ctr as integer ' loop counter
' Codes for line drawing SL=Single Line DL = Double Line DSD=Double Verticals & Single Horizontals
select case BoxType
case "SL"
UpLCnr = 218 : UpRCnr = 191 : HorzLn = 196 : VertLn = 179 : LwLCnr = 192 : LwRCnr = 217
'LTee = 195 : RTee = 180 : TTee = 194 : BTee = 183
case "DL"
UpLCnr = 201 : UpRCnr = 187 : HorzLn = 205 : VertLn = 186 : LwLCnr = 200 : LwRCnr = 188
'LTee = 195 : RTee = 180 : TTee = 194 : BTee = 183
case "DSD"
UpLCnr = 214 : UpRCnr = 183 : HorzLn = 196 : VertLn = 186 : LwLCnr = 211 : LwRCnr = 189
'LTee = 195 : RTee = 180 : TTee = 194 : BTee = 183
case "SDS"
UpLCnr = 213 : UpRCnr = 184 : HorzLn = 205 : VertLn = 179 : LwLCnr = 212 : LwRCnr = 190
'LTee = 195 : RTee = 180 : TTee = 194 : BTee = 183
case else
return
end select
' Draw the Box
locate StartY, StartX
color ForeColor, BackColor
print chr(UpLCnr) + string(BoxWidth-2,HorzLn) + chr(UpRCnr) ;
for ctr as integer = StartY+1 to StartY+BoxHeight-2
locate ctr,StartX
print chr(VertLn) ;
locate ctr,StartX+BoxWidth-1
print chr(VertLn) ;
next
locate ctr,StartX
print chr(LwLCnr) + string(BoxWidth-2,HorzLn) + chr(LwRCnr) ;
end sub
'========================================
' MAIN PROGRAM
'++++++++++++++++++++++++++++++++++++++++
dim LocY as integer ' column location of upper left corner of box
dim LocX as integer ' row location of upper left corner of box
dim Wid as integer ' width of box
dim Hgt as integer ' height of box
' Colors Enumeration (0 - 15) ie Black = 1, Cyan = 4 etc
Enum
Black : Blue : Green : Cyan : Red : Majenta : Brown : LightGrey : DarkGrey
BrightBlue : BrightGreen : BrightCyan : BrightRed : BrightMajenta : Yellow : White
end enum
width 80,24 ' set width and height of console
DrawBox("DL",2,2,78,22,Black,DarkGrey)
DrawBox("SL",3,4,74,20,Red,Black)
DrawBox("SDS",4,6,70,18,BrightBlue,Black)
DrawBox("DSD",5,8,66,16,Yellow,Black)
locate 24,1
sleep