Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
Code: (Select All)
'Let's start with the easiest way to print and view multiple screens of data.
'The solution here, is, of course, to simply pause at each screen so you can view it.
For i = 1 To 100
Print i
If i Mod 20 = 0 Then 'here is a simple check to see if the number divided by 20 has a remainder of 0.
Print "Press <ANY KEY> to continue." 'some simple feedback for the user to know what to do.
Sleep 'here's the pause after those 20 items and feedback are printed to the screen
Cls 'and after the user hits a key, we'll clear the screen and print the next 20 items
End If
Next
'Now, with that very simple method out of the way, let's go a step further and make an actual scrollable list.
'For starters, we have to have a list which we can scroll.
'I'll create that here with an array, just like above.
Dim My_List(1 To 100) As String 'an array to hold the list of 100 items.
For i = 100 To 1 Step -1 'a loop to put data into the array.
My_List(101 - i) = Str$(i) + " bottles of beer on the wall, then stuff..." 'my cheesy demo list
Next
'Now that we have a list, let's work on displaying it.
_KeyClear 'clear the keyboard buffer so those SLEEP inputs have no chance of affecting anything
Do 'you'll want a loop so you can have the user feedback for scrolling up or down
Cls 'clear the screen
If start < 1 Then start = 1 'our list starts with a minimum of item #1
If start > 100 Then start = 100 'and goes up to a maximum of item #100
finish = start + 20 'we can display at most 20 items on our screen
If finish > 100 Then finish = 100 'can't display more items than what we have on the screen!
For i = start To finish 'a loop to print the items we've chosen from our starting point to our end point.
Print My_List(i)
Next
Print
Print "Press <U>p or <D>own to scroll the list, or <Q>uit." 'instructions for our user control
User_choice$ = Input$(1) 'Get the user input
Select Case User_choice$ 'decide what to do with the user input
Case "U", "u": start = start - 1 'scroll up an item
Case "D", "d": start = start + 1 'scroll down an item
Case "Q", "q": System 'quite
End Select
Loop 'and we're basically finished with this scrolling loop!
A very simple demo with comments to help explain what everything is doing along the way. If Terry thinks it fits his tutorial, he's more than welcome to make use of it as he sees fit. Feel free to modify, expand, edit, whatever, as you need it.
Posts: 34
Threads: 4
Joined: Apr 2022
Reputation:
0
(04-09-2024, 12:44 AM)SMcNeill Wrote: Code: (Select All)
'Let's start with the easiest way to print and view multiple screens of data.
'The solution here, is, of course, to simply pause at each screen so you can view it.
For i = 1 To 100
Print i
If i Mod 20 = 0 Then 'here is a simple check to see if the number divided by 20 has a remainder of 0.
Print "Press <ANY KEY> to continue." 'some simple feedback for the user to know what to do.
Sleep 'here's the pause after those 20 items and feedback are printed to the screen
Cls 'and after the user hits a key, we'll clear the screen and print the next 20 items
End If
Next
'Now, with that very simple method out of the way, let's go a step further and make an actual scrollable list.
'For starters, we have to have a list which we can scroll.
'I'll create that here with an array, just like above.
Dim My_List(1 To 100) As String 'an array to hold the list of 100 items.
For i = 100 To 1 Step -1 'a loop to put data into the array.
My_List(101 - i) = Str$(i) + " bottles of beer on the wall, then stuff..." 'my cheesy demo list
Next
'Now that we have a list, let's work on displaying it.
_KeyClear 'clear the keyboard buffer so those SLEEP inputs have no chance of affecting anything
Do 'you'll want a loop so you can have the user feedback for scrolling up or down
Cls 'clear the screen
If start < 1 Then start = 1 'our list starts with a minimum of item #1
If start > 100 Then start = 100 'and goes up to a maximum of item #100
finish = start + 20 'we can display at most 20 items on our screen
If finish > 100 Then finish = 100 'can't display more items than what we have on the screen!
For i = start To finish 'a loop to print the items we've chosen from our starting point to our end point.
Print My_List(i)
Next
Print
Print "Press <U>p or <D>own to scroll the list, or <Q>uit." 'instructions for our user control
User_choice$ = Input$(1) 'Get the user input
Select Case User_choice$ 'decide what to do with the user input
Case "U", "u": start = start - 1 'scroll up an item
Case "D", "d": start = start + 1 'scroll down an item
Case "Q", "q": System 'quite
End Select
Loop 'and we're basically finished with this scrolling loop!
A very simple demo with comments to help explain what everything is doing along the way. If Terry thinks it fits his tutorial, he's more than welcome to make use of it as he sees fit. Feel free to modify, expand, edit, whatever, as you need it. That helps functionality. I will have fun playing around with that code! My quest is still to have a "classic" vertical scrollbar -- at least when I want it.
Posts: 732
Threads: 103
Joined: Apr 2022
Reputation:
14
(04-08-2024, 09:28 PM)Tim Wrote: I have been trying to figure out how to do this, scroll program output when it fills more than one screenful , but I have had no luck so far. I am currently working on Lesson 4 of Terry's Tutorial. Some example programs, as well as my own experiments, use a lot more screen length than just one. For example, one of the example programs counts to 100 (from whatever starting point you give it); I would like to be able to see all of the output from it (as well as the results of my own hacks, which I do in order to make sure I can replicate and understand creatively what the lesson(s) teach). I'm not sure if this would help, but here's a simple method I use for displaying long instructions for my QB64 games:
Code: (Select All) Sub ShowInstructions
Dim in$: in$ = GetInstructions$
Dim iLoop As Integer
Dim iCount As Integer: iCount = 0
Dim iRows As Integer: iRows = _Height(0) \ _FontHeight ' GET # OF AVAILABLE TEXT ROWS
ReDim arrLines(-1) As String
Cls
split in$, Chr$(13), arrLines() ' SPLIT OUTPUT INTO LINES
For iLoop = LBound(arrLines) To UBound(arrLines)
' WHEN MAX LINES ARE DISPLAYED, PAUSE AND WAIT FOR USER TO PRESS <ENTER>
If arrLines(iLoop) <> Chr$(10) Then
Print arrLines(iLoop)
iCount = iCount + 1
If iCount > (iRows - 5) Then
Input "PRESS <ENTER> TO CONTINUE"; in$
iCount = 0
End If
Else
' Chr$(10) MEANS PAUSE, WAIT FOR USER, RESET LINE COUNTER
Input "PRESS <ENTER> TO CONTINUE"; in$
iCount = 0
End If
Next iLoop
Input "PRESS <ENTER> TO CONTINUE"; in$
End Sub ' ShowInstructions
' /////////////////////////////////////////////////////////////////////////////
' NOTE: Chr$(10) causes ShowInstructions to pause and wait for the user
' to press <ENTER>.
Function GetInstructions$
Dim in$
in$ = in$ + "my text here" + Chr$(13)
in$ = in$ + " " + Chr$(13)
in$ = in$ + "more text" + Chr$(13)
in$ = in$ + "etc. etc." + Chr$(13)
in$ = in$ + Chr$(10) + Chr$(13)' pause here
in$ = in$ + "another section" + Chr$(13)
in$ = in$ + "etc." + Chr$(13)
GetInstructions$ = in$
End Function ' GetInstructions$
It keeps track of the text rows printed to the screen, and when it exceeds the vertical resolution, it prompts the user to press ENTER to continue, and also lets you designate pauses manually (for example at the end of a given topic).
Good Luck!
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
04-09-2024, 06:46 PM
(This post was last modified: 04-09-2024, 06:53 PM by Kernelpanic.)
(04-08-2024, 09:28 PM)Tim Wrote: For example, one of the example programs counts to 100 (from whatever starting point you give it); I would like to be able to see all of the output from it (as well as the results of my own hacks, which I do in order to make sure I can replicate and understand creatively what the lesson(s) teach). In many cases one do not need to scroll, sleep, etc. You display the output side by side.
My recommendation: Use Option _Explicit right from the start so that variables must be declared. This saves you a lot of trouble searching for " inexplicable" errors.
PS: Change Print in Print Using "###"; count
Code: (Select All)
'Anzeige nebeneinander - 9. April 2024
Screen _NewImage(700, 600, 32)
Option _Explicit
Dim As Integer count, spalte, zeilenAnzahl
Locate 2, 3
Print "This program will count to 100 from the number you supply."
Locate 3, 3
Input "Enter the number to start counting from > ", count
count = 0
spalte = 3 'Row
zeilenAnzahl = 20 'Column
Locate 5, spalte
While count < 100
count = count + 1
Print count
Locate CsrLin, spalte
If count Mod zeilenAnzahl = 0 Then
spalte = spalte + 6
Locate 5, spalte
End If
Wend
End
Posts: 732
Threads: 103
Joined: Apr 2022
Reputation:
14
(04-09-2024, 06:46 PM)Kernelpanic Wrote: In many cases one do not need to scroll, sleep, etc. You display the output side by side.
Yes, for programming tutorials, this format is really helpful.
Posts: 3,964
Threads: 176
Joined: Apr 2022
Reputation:
219
04-09-2024, 07:47 PM
(This post was last modified: 04-09-2024, 07:53 PM by bplus.)
so in summary if you insist on scrolling (both up and down) you probably have to put the stuff in an array for displaying otherWISE use $Console:Only ;-))
AND if you want a scroll bar too, you could use my scrolling List boxes in my VS GUI the later versions but it's really too much for such a simple app as in the OP
it really doesn't get much easier than using $Console:Only
b = b + ...
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
04-10-2024, 04:43 PM
(This post was last modified: 04-10-2024, 04:46 PM by Kernelpanic.)
Example for Tim in C.
As an example, I wrote the program with the formatted output in "C", the vertical output is difficult in "C" because it doesn't know Locate.
Code: (Select All)
//Formatierte Ausgabe, Basic Programm - 10. April 2024
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int eingabe;
system("cls");
printf("\nThis program will count to 100 from the number you supply.");
printf("\nEnter the number to start counting from > ");
scanf("%d", &eingabe);
printf("\n");
for(int i = eingabe; i <= 100; i++)
{
printf("%4d", i);
if((i % 20) == 0)
printf("\n");
}
return(0);
}
If you want to try it yourself:
1. Download and install MinGW; latest 13.2.0
MinGW 13
2. Get editor:
Notepad
3. Compile (File: formatierte-ausgabe.c)
gcc -o formatierte-ausgabe formatierte-ausgabe.c
4. If everything works, enter in Powershell: ./formatierte-ausgabe
(the "./" is not necessary in the command line)
The world belongs to the brave! (Or so )
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
Since I was just writing about C (Aurel), here's the whole stuff also in C++.
Code: (Select All)
//Die formatierte Ausgabe auch noch in C++ - 19. April 2024
//-iomanip- Für setw() und cin.width(int)
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main(void)
{
int eingabe;
system("cls");
cout << "\nThis program will count to 100 from the number you supply.";
cout << "\nEnter the number to start counting from > ";
cin >> eingabe;
cout << "\n";
for(int i = eingabe; i <= 100; i++)
{
//Festpunktzahl - Nachkommastellen - Feldbreite
cout << fixed << setprecision(0) << setw(4) << i;
if((i % 20) == 0)
cout << "\n";
}
//Neue Zeile
cout << endl;
return(0);
}
Compile with:
PS D:\Lab\C++> g++ -o ausgabe-formatiert ausgabe-formatiert.cpp
|