Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 scrolling
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
the_binary_soul




PostPosted: Mon Dec 08, 2003 3:31 pm   Post subject: scrolling

hello

I need to make a phone book essentially for class...but I need to figure out how to let you scroll through the list that appears after the users tells it to display all. ((I want a keyboard scroll, not mouse))
any help would be greatly appreciated
thanx
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Dec 08, 2003 7:09 pm   Post subject: (No subject)

well what you do is you have a variable that holds from which index to start listing the numbers. Every time you "scroll", the screen is cleared, that value is changed and list is rewriten from the new position in the array.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Andy




PostPosted: Mon Dec 08, 2003 7:36 pm   Post subject: (No subject)

they have one in the turing tutorials
code:
% The "TextFlds" program
% This demonstrates the Text Field widget along with the GUI routines
% that use Text Field widgets. [GetText, SetText, SetSelection, MakeActive,
% CreateTextFieldFull, ProcessEvent]

import GUI in "%oot/support/lib/GUI" % Must be included in a programs using the GPL

View.Set ("graphics:200;150") % Shrink the window to the minimum size

% The Text Field IDs
var nameTextField, addressTextField, ageTextField : int

% The slider to choose people
var scrollBar : int

% The label for record number
var recordLabel : int

% The array of data
var data : array 1 .. 50 of
    record
        name : string
        address : string
        age : string
    end record

var numRecords : int := 1
var currentRecord : int := 1

for i : 1 .. 50
    data (i).name := ""
    data (i).address := ""
    data (i).age := ""
end for

procedure ChooseRecord (recordNumber : int)
    % Save the current data
    data (currentRecord).name := GUI.GetText (nameTextField)
    data (currentRecord).address := GUI.GetText (addressTextField)
    data (currentRecord).age := GUI.GetText (ageTextField)

    % Place the new current record in the text fields
    currentRecord := recordNumber
    GUI.SetText (nameTextField, data (currentRecord).name)
    GUI.SetText (addressTextField, data (currentRecord).address)
    GUI.SetText (ageTextField, data (currentRecord).age)

    % Set the label to indicate the current record
    GUI.SetLabel (recordLabel, "Record " + intstr (recordNumber) + " of " +
        intstr (numRecords))
       
    % Set the selections to cover all the text in each of the text fields
    GUI.SetSelection (nameTextField, -1, -1)
    % Make the name field the active text field
    GUI.SetActive (nameTextField)
    GUI.SetSelection (addressTextField, -1, -1)
    GUI.SetSelection (ageTextField, -1, -1)
end ChooseRecord

procedure AddRecord
    numRecords += 1
    GUI.SetSliderMinMax (scrollBar, 1, numRecords)
    % GUI.SetSliderValue calls ChooseRecord automatically
    GUI.SetSliderValue (scrollBar, numRecords)
end AddRecord

procedure NameEntered (text : string)
    GUI.SetSelection (addressTextField, -1, -1)
    GUI.SetActive (addressTextField)
end NameEntered

procedure AddressEntered (text : string)
    GUI.SetSelection (ageTextField, -1, -1)
    GUI.SetActive (ageTextField)
end AddressEntered

procedure AgeEntered (text : string)
    if currentRecord = numRecords then
        AddRecord
    else
        GUI.SetSliderValue (scrollBar, currentRecord + 1)
        % GUI.SetSliderValue calls ChooseRecord automatically
    end if
end AgeEntered

GUI.SetBackgroundColour (grey)
recordLabel := GUI.CreateLabelFull (50, 130, "Record 1 of 1", 100, 0,
    GUI.CENTER, 0)
nameTextField := GUI.CreateTextFieldFull (50, 100, 100, "", NameEntered,
    GUI.INDENT, 0, 0)
addressTextField := GUI.CreateTextFieldFull (50, 70, 100, "", AddressEntered,
    GUI.INDENT, 0, 0)
ageTextField := GUI.CreateTextFieldFull (50, 40, 100, "", AgeEntered,
    GUI.INDENT, 0, 0)
var nameLabel := GUI.CreateLabelFull (45, 100, "Name", 0, 0, GUI.RIGHT, 0)
var addressLabel := GUI.CreateLabelFull (45, 70, "Address", 0, 0, GUI.RIGHT,
    0)
var ageLabel := GUI.CreateLabelFull (45, 40, "Age", 0, 0, GUI.RIGHT, 0)

var addRecord := GUI.CreateButton (52, 5, 100, "Add Record", AddRecord)

scrollBar := GUI.CreateVerticalScrollBarFull (170, 5, 130, 1, 1, 1,
    ChooseRecord, 1, 5, 0)
GUI.SetSliderReverse (scrollBar)

loop
    exit when GUI.ProcessEvent
end loop

the_binary_soul




PostPosted: Mon Dec 08, 2003 8:52 pm   Post subject: (No subject)

ok, that should help, thanks!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: