Column Display w/ Multiple Fields, only three on at once
Author |
Message |
haayyeess
|
Posted: Thu Dec 24, 2015 9:52 am Post subject: Column Display w/ Multiple Fields, only three on at once |
|
|
What is it you are trying to achieve?
Hi guys,
I am creating a display routine for a record database. I desire to create a columned display allowing up to three of about 12 fields to be displayed. I want the user to be able to press singular keys in order to add or remove a field from the display. For example, if they press 'a', then I want the first names to be displayed in a column, and if they press 'a' again, I want it to be removed. If 'a' has been pressed and set true, or on, and the user presses 'b' to display last names, I want it to appear in the second column. In the event the user removes the first name selection, i would like to have last names shift into the first column. If the user has three selections, they will be forced to remove one prior to adding a new one. I further desire the user to be able to select a record using a number to pull up a full form view of that record (another display i already have). Also, there will be more records than can show on screen. Can I have the user be able to page up and down through the records on the lower half of the screen?
What is the problem you are having?
I want to be able to handle a large amount of records (greater than what will fit on screen when displayed) without forcing the user to page through all of them.
Describe what you have tried to solve this problem
This is best seen in the code I have attached.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%% DISPLAY TEXT COLUMNS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NOTE: Please see the 'Main Menu' for a detailed menu including build info.
Please be advised that this subprogram uses global consts n vars ..
.. which have been declared in 'Main Menu.t'
"Display Text Columns" is a subprogram which will display the users data in
a columned fashion. In the future, this subprogram will have advanced features.
These advanced features will include the ability for a user to choose the fields
that will be displayed in a columned fashion up to a max when no more will fit
on the screen.
%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*
%*% VARIABLE LIST %*%
%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*
Font1, Font2: Custom fonts, menus/titles, to stand out and improv. user exper.
Person: array containing good record data entered into PERSON_RECORD_DATA
RecordCount: Count watching the amt of data entered (amt of records), nums
Columns: Tracks the # of columns, and prevents exceeding a val to keep nice
Count: Counter to watch the amount of records on screen so it doesnt run off
%NEEEDS TO BE UPDATED
*/
procedure Display_Text_Columns (Person : PERSON_ARRAY, RecordCount : nat1)
%LOCAL VARIABLES
var FirstOn : boolean
var LastOn : boolean
var MidOn : boolean
var TownOn : boolean
var HouseNumOn : boolean
var PostalOn : boolean
var ProvOn : boolean
var CountryOn : boolean
var PhoneNumOn : boolean
var FirstChildOn : boolean
var SecondChildOn : boolean
var HowManyOn : nat1 %Counter to track amount of displays on
var Columns : nat1 % Numeric counter, currently wont exceed 2
var Count : nat1 % Numeric Counter, won't exceed 20 (on screen limit)
var RecordIndex : nat1
var LoopCount : nat1
%LOCAL VARIABLE ASSIGNMENTS
FirstOn := false
LastOn := false
MidOn := false
TownOn := false
HouseNumOn := false
PostalOn := false
ProvOn := false
CountryOn := false
PhoneNumOn := false
FirstChildOn := false
SecondChildOn := false
HowManyOn := 0
Columns := 1
%Count := 1 %moved inside of loop
cls %clear menu
if RecordCount > 0 then
loop
Count := 1
colour (brightpurple)
drawfillbox (5, 365, 635, 270, purple)
drawfillbox (15, 355, 625, 280, black)
%Draw Choices on screen top
Font.Draw ("Please select up to three fields to display",
70, 375, Font1, brightpurple)
Font.Draw ("Please select up to three fields to display",
68, 377, Font1, black)
Font.Draw ("a. First Name", 20, 335, Font2, white)
Font.Draw ("b. Last Name", 20, 320, Font2, white)
Font.Draw ("c. Middle Name", 20, 305, Font2, white)
Font.Draw ("d. Town", 20, 290, Font2, white)
Font.Draw ("e. House Number", 220, 335, Font2, white)
Font.Draw ("f. Postal Code", 220, 320, Font2, white)
Font.Draw ("g. Province", 220, 305, Font2, white)
Font.Draw ("h. Country", 220, 290, Font2, white)
Font.Draw ("i. Phone Number", 420, 335, Font2, white)
Font.Draw ("j. First Child Name", 420, 320, Font2, white)
Font.Draw ("k. Second Child Name", 420, 305, Font2, white)
Font.Draw ("*Press X to exit*", 420, 290, Font2, brightred)
%Get Input
getch (Choice )
%Check for letter vs number, ignore rest
%Letter Check
if Choice > "@" and Choice < "[" or Choice > "`" and Choice < "{" then
%It's a letter
if not (Choice = "X" or Choice = "x") then %Proceed
%Begin toggle if
if HowManyOn < 3 then
if Choice = "a" and not FirstOn then %ON
FirstOn := true
HowManyOn := HowManyOn + 1 %Bump counter for # fields on display
elsif Choice = "a" and FirstOn then %OFF
FirstOn := false
HowManyOn := HowManyOn - 1 %Reduce counter for # fields on display
elsif Choice = "b" and not LastOn then %ON
LastOn := true
HowManyOn := HowManyOn + 1 %Bump counter for # fields on display
elsif Choice = "b" and LastOn then %OFF
LastOn := false
HowManyOn := HowManyOn - 1 %Reduce counter for # fields on display
elsif Choice = "c" and not MidOn then %ON
MidOn := true
HowManyOn := HowManyOn + 1 %Bump counter for # fields on display
elsif Choice = "c" and MidOn then %OFF
MidOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "d" and not TownOn then %ON
TownOn := true
HowManyOn := HowManyOn + 1 %Bump counter for # fields on display
elsif Choice = "d" and TownOn then %OFF
TownOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "e" and not HouseNumOn then %ON
HouseNumOn := true
HowManyOn := HowManyOn + 1 %Bump counter for # fields on display
elsif Choice = "e" and HouseNumOn then %OFF
HouseNumOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "f" and not PostalOn then %ON
PostalOn := true
HowManyOn := HowManyOn + 1 %Bump counter for # fields on display
elsif Choice = "f" and PostalOn then %OFF
PostalOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "g" and not ProvOn then %ON
ProvOn := true
HowManyOn := HowManyOn + 1 %Bump counter for # fields on display
elsif Choice = "g" and ProvOn then %OFF
ProvOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "h" and not CountryOn then %ON
CountryOn := true
HowManyOn := HowManyOn + 1 %Bump counter for # fields on display
elsif Choice = "h" and CountryOn then %OFF
CountryOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "i" and not PhoneNumOn then %ON
PhoneNumOn := true
HowManyOn := HowManyOn + 1 %Bump counter for # fields on display
elsif Choice = "i" and PhoneNumOn then %OFF
PhoneNumOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "j" and not FirstChildOn then %ON
FirstChildOn := true
HowManyOn := HowManyOn + 1 %Bump counter for # fields on display
elsif Choice = "j" and FirstChildOn then %OFF
FirstChildOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "k" and not SecondChildOn then %ON
SecondChildOn := true
HowManyOn := HowManyOn + 1 %Bump counter for # fields on display
elsif Choice = "k" and SecondChildOn then %OFF
SecondChildOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
end if
else %must have max amount of fields loaded
if Choice = "a" and FirstOn then %Turn Off
FirstOn := false
HowManyOn := HowManyOn - 1 %Reduce counter for # fields on display
elsif Choice = "b" and LastOn then %Turn Off
LastOn := false
HowManyOn := HowManyOn - 1 %Reduce counter for # fields on display
elsif Choice = "c" and MidOn then %Turn Off
MidOn := false
HowManyOn := HowManyOn - 1 %Reduce counter for # fields on display
elsif Choice = "d" and TownOn then %OFF
TownOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "e" and HouseNumOn then %OFF
HouseNumOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "f" and PostalOn then %OFF
PostalOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "g" and ProvOn then %OFF
ProvOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "h" and CountryOn then %OFF
CountryOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "i" and PhoneNumOn then %OFF
PhoneNumOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "j" and FirstChildOn then %OFF
FirstChildOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
elsif Choice = "k" and SecondChildOn then %OFF
SecondChildOn := false
HowManyOn := HowManyOn - 1 %Bump counter for # fields on display
else %User needs to remove a field
Font.Draw ("Please remove a field before adding one!", 50, 5, Font1, brightred)
delay (1000)
loop %start loop 2 (Prevents delay time accumulation)
exit when not hasch % Exit when a correct key wasn't entered
getch (Choice )
end loop %end loop 2
end if
end if
end if
elsif Choice > "/" and Choice < ":" then
%It's Numeric
%Call and display full form record
%Wont work for double digits.
if strnat (Choice ) <= RecordCount then
RecordIndex := strnat (Choice ) %assign record index to their choice
Display_Single_Record (RecordIndex, Person, RecordCount )
end if
end if
cls %Initiate redraw
locatexy (0, 250) %re-route text to keep formating
colour (brightgreen)
put "The records you have entered are..."
colour (brightcyan)
put "" : 3 ..
if FirstOn then
put "First Name" : (MAXL + 1) ..
end if
if LastOn then
put "Last Name" : (MAXL + 1) ..
end if
if MidOn then
put "Middle Name" : (MAXL + 1) ..
end if
put ""
put "_______________________________________________________________" ..
put "_________________"
% Font.Draw (FieldOne, 14, 215, Font2, brightcyan)
% Font.Draw (FieldTwo, 244, 215, Font2, brightcyan)
% Font.Draw (FieldThree, 474, 215, Font2, brightcyan)
LoopCount := 0
loop %Display Data Loop
colour (brightcyan)
LoopCount := LoopCount + 1
put LoopCount : 3, ". " .. % Putting the # infront of names
colour (46)
if FirstOn then
put Person (LoopCount ).First : (MAXL + 1) .. %Displaying first name
end if
if LastOn then
put Person (LoopCount ).Last : (MAXL + 1) .. %Displaying last name
end if
if MidOn then
put Person (LoopCount ).Middle : (MAXL + 1) .. %Displaying Middle name
end if
if TownOn then
put Person (LoopCount ).Town : (MAXL + 1) .. %Displaying Town name
end if
if HouseNumOn then
put Person (LoopCount ).HouseNum : (MAXL + 1) .. %Displaying House num
end if
if PostalOn then
put Person (LoopCount ).Postal : (MAXL + 1) .. %Displaying Postal code
end if
if ProvOn then
put Person (LoopCount ).Prov : (MAXL + 1) .. %Displaying Province
end if
if CountryOn then
put Person (LoopCount ).Country : (MAXL + 1) .. %Displaying Country
end if
if PhoneNumOn then
put Person (LoopCount ).Phone : (MAXL + 1) .. %Displaying Phone num
end if
if FirstChildOn then
put Person (LoopCount ).CHILD_NAMES.ChildOne : (MAXL + 1) .. %Displaying child 1
end if
if SecondChildOn then
put Person (LoopCount ).CHILD_NAMES.ChildTwo : (MAXL + 1) .. %Displaying Child 2
end if
Count := Count + 1 % tracking # of records per screen
Columns := Columns + 1 % Currently only allowed first n last
if Columns > 1 then % Every 2 columns, start a new row
put ""
Columns := 1
end if
if Count > 10 then % Pause every 10 lines for reviewal
Count := 1 %reset
put "Press any key to scroll down or 'e' to exit."
% getch (Choice)
locatexy (0, 0)
end if
exit when LoopCount = RecordCount or Choice = "e"
end loop
%RETURN TO MAIN ON X or x.
exit when Choice = "x" or Choice = "X"
end loop
else
Font.Draw ("There are no records to display!", 100, 175, Font1, brightred)
delay (1000)
loop %start loop 2 (Prevents delay time accumulation)
exit when not hasch % Exit when a correct key wasn't entered
getch (Choice )
end loop %end loop 2
end if
end Display_Text_Columns
|
Please specify what version of Turing you are using
<Answer Here>
Description: |
|
Filesize: |
48.98 KB |
Viewed: |
1680 Time(s) |
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Thu Dec 24, 2015 10:30 pm Post subject: RE:Column Display w/ Multiple Fields, only three on at once |
|
|
To add/remove/shift fields in the display, you could use 3 variables (or an array of size 3) to store what field goes into what column. Give every field a unique identifier and store that identifier in the variable that represents the column it is to be drawn to. Say you're using integers. first name = 1, last name = 2, etc. and nothing (empty column) = 0. Our three variables are column(1), column(2), and column(3). To add first names to the view, change one of the columns to 1. To add last names, change one to 2. To delete one, shift everything to the right of that field one space to the left, and change column(3) to 0 (aka empty).
Now, when you draw your table, look at those three column variables. If column(1) = 1, then draw first names in column 1, etc. If it's 0, then don't draw that column.
The important thing is properly updating those three variables when you add or remove fields or you'll end up with a blank column in the middle or a field overwriting another instead of appending to the end of the list.
Making this work might require restructuring your entire draw routing and even how you store your data. I dunno, I haven't seen your code.
As for scrolling, well, implementing a scroll wheel is a pain in the ass, but doing simple page ups/downs isn't too hard. Keep a page counter variable. When the page down button is pressed, increment the page counter. When you draw your records, instead of starting from the first, start from (page counter * max records per page). So if you draw 10 per page, then page 2 starts at 2*10=record #20.
|
|
|
|
|
|
haayyeess
|
Posted: Fri Dec 25, 2015 10:55 pm Post subject: Re: Column Display w/ Multiple Fields, only three on at once |
|
|
Thanks for the reply Insectoid! I solved both issues. Thank you for the support.
|
|
|
|
|
|
|
|