69 lines
2.0 KiB
Plaintext
69 lines
2.0 KiB
Plaintext
Type Printer
|
|
tipo As String
|
|
ink As Integer
|
|
End Type
|
|
|
|
Sub Printer_New(Byref p As Printer, Byval tipo As String, Byval ink As Integer)
|
|
p.tipo = tipo
|
|
p.ink = ink
|
|
End Sub
|
|
|
|
Function Printer_ink(Byref p As Printer) As Integer
|
|
Return p.ink
|
|
End Function
|
|
|
|
Sub Printer_ink_Set(Byref p As Printer, Byval v As Integer)
|
|
p.ink = v
|
|
End Sub
|
|
|
|
Sub Printer_print(Byref p As Printer, Byval text As String)
|
|
Print p.tipo & ": ";
|
|
For i As Integer = 1 To Len(text)
|
|
Print Mid(text, i, 1);
|
|
Next
|
|
Print
|
|
p.ink -= 1
|
|
End Sub
|
|
|
|
Dim Shared As Printer ptrMain, ptrReserve
|
|
Printer_New(ptrMain, "Main ", 5)
|
|
Printer_New(ptrReserve, "Reserve", 5)
|
|
|
|
Dim Shared As String*44 hd(3) = {"Humpty Dumpty sat on a wall.", "Humpty Dumpty had a great fall.", "All the king's horses and all the king's men", "Couldn't put Humpty together again."}
|
|
Dim Shared As String*26 mg(7) = {"Old Mother Goose", "When she wanted to wander,", "Would ride through the air", "On a very fine gander.", "Jack's mother came in,", "And caught the goose soon,", "And mounting its back,", "Flew up to the moon."}
|
|
|
|
Function task(Byval nombre As String) As String
|
|
Dim As Integer i
|
|
Dim As String lines()
|
|
If nombre = "Humpty Dumpty" Then
|
|
Redim lines(Ubound(hd))
|
|
For i = 0 To Ubound(hd) : lines(i) = hd(i)
|
|
Next
|
|
Else
|
|
Redim lines(Ubound(mg))
|
|
For i = 0 To Ubound(mg) : lines(i) = mg(i)
|
|
Next
|
|
End If
|
|
|
|
For i = 0 To Ubound(lines)
|
|
If Printer_ink(ptrMain) > 0 Then
|
|
Printer_print(ptrMain, lines(i))
|
|
Elseif Printer_ink(ptrReserve) > 0 Then
|
|
Printer_print(ptrReserve, lines(i))
|
|
Else
|
|
Return "ERROR : Reserve printer ran out of ink in " & nombre & " task."
|
|
End If
|
|
Next
|
|
Return ""
|
|
End Function
|
|
|
|
Dim As String rhymes(1) = {"Humpty Dumpty", "Mother Goose"}
|
|
Dim As String tasks(1)
|
|
|
|
For i As Integer = 0 To 1
|
|
tasks(i) = task(rhymes(i))
|
|
If tasks(i) <> "" Then Print tasks(i): Exit For
|
|
Next
|
|
|
|
Sleep
|