8 hours ago
(This post was last modified: 8 hours ago by PhilOfPerth.)
I write mostly text-based programmes, and often need to change the content of one or more lines during run-time, so I wrote these two subs to make it simple to do this.
Nothing Earth-shattering, but they may be useful to someone:
You can also use Tab(n) in lieu of the Space$(n) for positioning the text
Nothing Earth-shattering, but they may be useful to someone:
Code: (Select All)
' This is a demo of two Subs I find useful in text-based progs, where lines of text need to be changed frequently
Screen _NewImage(1120, 768, 32)
Common Shared CPR
CPR = 1120 / _PrintWidth("X") ' chars per row - used for centring text (change 1120 to your NewImage width)
_ScreenMove (_DesktopWidth - 1120) / 2, 100
yellow
WP "XXX", "101213" ' clear rows 10,12,13 and print centred string on each of them
Sleep 1
WP "YYY", "11" ' clear row 11 and print centred string on it
Sleep 1
red
WP "OOO", "11" ' clear row 11 and print centred red string on it
Sleep 1
white
CP "This Text", "15" ' clear row 15 and centre text on it
Sleep 1
red
WP "Finally, this", "1011121315" ' clears row 10 to 15 and centres text on each of them
Sleep 1
WP "", "11"
Sleep 1
yellow
CP Space$(20) + "Change position with Spaces", "16" ' add spaces to change text position
CP "Left or Right" + Space$(20), "17"
Sleep
' ------------------------------------------------------------------------ THESE TWO SUBS ---------------------------------------------------
Sub WP (Txt$, RN$) ' Wipe (clear) row(s) named in RN$ (2-digit line numbers), then centre the string on each
If RN$ = "" Then GoTo Place ' if RN$ is given as empty string, jump to centring
If Len(Txt$) < 1 Then Txt$ = Space$(CPR)
For a = 1 To Len(RN$) - 1 Step 2 ' for each pair of chars in RN$ (change to Step 3 for 3-digit line numbers)
CL = Val(Mid$(RN$, a, 2)) ' line to be cleaned
Locate CL, 1: Print Space$(CPL) ' write row of spaces to the line
Place:
Ctr = Int(CPR / 2 - Len(Txt$) / 2) + 1 ' find centred start position for text string
Locate CL, Ctr
Print Txt$ ' print text string there (if string is empty, line remains cleared)
Next
End Sub
Sub CP (txt$, RN$) ' Centre and Print text
If RN$ = "" Then Exit Sub
Ctr = Int(CPR / 2 - Len(txt$) / 2) + 1
Locate Val(RN$), Ctr
Print txt$
End Sub
' ----------------------------------------------------------------------------------------------------------------------------------------------
Sub white
Color _RGB(255, 255, 255)
End Sub
Sub yellow
Color _RGB(255, 255, 0)
End Sub
Sub red
Color _RGB(255, 0, 0)
End Sub
You can also use Tab(n) in lieu of the Space$(n) for positioning the text
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
Please visit my Website at: http://oldendayskids.blogspot.com/