StPendl
Apr 3, 2009
- "Reverted to Mar 18, 2009 7:23 pm: contents have been replaced by an article"
Rearranging a listbox and repeating butons<span class="wiki_link_new"> </span> =Submit Articles Here for Liberty BASIC Programmer's Encyclopedia= [[home|Liberty BASIC Programmer's Encyclopedia]]The following demo shows two different programming features, the first is a way to rearrange a list boxAnybody can submit articles to theuser's preference,Liberty BASIC Programmer's Encyclopedia. You do notnecessarily alphabetically or in ascending or descending numerical order. The second feature isneed touse repeating buttons to move the items in the listbox upbe a member of Wikispaces ordown.of this site.The repeating buttons are actually two bitmaps available in**License** By adding content to the LibertyBasic 4.03 bmp folder thatBASIC Programmer's Encyclopedia, you areplaced in a graphic box to look similar to a spinner control. Whenbound by theleft mouse is clicked down, it is detected in the graphic box using when LeftButtonDown. Using the MouseX and MouseY commandslicense. If youcan tell if the cursor is on the up or down button and the selected item will move. If the left mouse button is held down, the selected item will continuedo not want tomove. This eliminates the needrelease your work under this license, do not submit articles. [[License|Click HERE torepeatable click an up or down arrow to move an item a long distance. Whenread theLeftButtonUp is detected by the scan in the [moveup] or [movedown] sections, the program will go to [stopmove] and wait.License.]] **Article Guidelines** The Liberty BASIC Programmer's Encyclopedia is a place for full-length technical articles. Authors should make sure that articles are well-structured, that words are spelled correctly, and that all code works properly. [[tech.writing|Click HERE for help on technical writing.]] When you submit an article, be aware this is not the end of your involvement. Few of us get it Just Right the very first time. Expect an LBPE editor to contact you with questions, suggestions, possible edits, etcetera for you to look over and take the proper action.'Rearranging**Adding Articles** # Click the edit button at the top of this page. # Add your article to the [[Submit#list|list at the bottom of this page]] . If you are using the formatted text editor, simply click the link button (a globe with chain links in the foreground) and invoke alistbox contentsdialog to add the link. Type the name of your new page in the "wiki link" area andRepeating buttons democlick the "okay" button.If you are using the plain text editor, do this by typing a name for your page inside of double square brackets. If your article is called "Using Arrays", your link would look like this: ``* [[Using Arrays]] `` Save the editing of this page. # View this page and click on the link you just created. # On the new page, click the edit link and type or paste your article. # Please place your name and the date at the top of your article, along with a descriptive title. # Save your edits. That's all there is to it!nomainwin dim array$(10) 'This fills**Editing Articles** To learn how to use WikiText markup to edit site content, click [[www:wikitext|HERE.]] You don't need to know WikiText, though. When you are editing a page, there is a button near thelistbox array, but it could be filled frombottom to "Use Visual Editor." If you want to try some editing in afile. array$(1)="Pigeon" array$(2)="Donkey" array$(3)="Horse" array$(4)="Rabbit" array$(5)="Dog" array$(6)="Cat" array$(7)="Goat" array$(8)="Mule"safe place where you can do no harm, play in the [[TestArea|Test Area]]. Before finalizing the article, you can click the "Preview" button to see how your article will appear, and make changes as needed.NUMBERRECORDS=8 'Number of records in the array**Additional Files** If your article requires images orthe file 'This demo uses an upother additional files, simply upload them anddown arrow bitmap button from Liberty Basic's bmp folder. 'Theyinclude links in your article. When you are20 x 20 pixels each. loadbmp "upbutton", "C:\Program Files\Liberty Basic v4.03\bmp\MAXBX.bmp" loadbmp "dnbutton", "C:\Program Files\Liberty Basic v4.03\bmp\MINBX.bmp"editing a page there is a link in the upper right for "Images". Click this to view a list of all available files and images.WindowWidth =400 WindowHeight=400 'This graphicbox**Article Placement** One of the organizers of the Liberty BASIC Programmer's Encyclopedia willbe usedtag your article for editing. If the organizers find it toplace both buttons. 'If you usebe adialog window,viable article for thegraphic box shouldencyclopedia, it will beabout 4 pixels wider 'and 4 pixels deeperadded tolook best. graphicbox #main.gb1, 345,160,20,40 listbox #main.lb1, array$(, [selectitem], 10, 30, 305, 300 statictext #main.st1, "", 20, 5, 300, 20 open "Reorganize a List" for window as #mainall the appropriate categories.#main.lb1, "singleclickselect" #main, "trapclose [quit]" currec=0 'Used to contain**Confirmation** Organizers of thecurrent elementLiberty BASIC Programmer's Encyclopedia will make any modifications they feel are needed. Authors may accept or reject these changes before articles are listed in thearray. flag=0 'This flag is used to determine if an item has been moved. 'Put the pen downappropriate categories anddraw the up button at the top of the graphic box. #main.gb1, "down;drawbmp upbutton 0 0" 'Draw the down button in the bottom of the graphis box. #main.gb1, "drawbmp dnbutton 0 20;flush" 'When the left button is depressed in the graphic box. #main.gb1, "when leftButtonDown [leftdown]" 'When the left button is released. #main.gb1, "when leftButtonUp [stopmove]" waitlocked.[selectitem] 'When an item is double clicked for selection**Article Modification in thelistbox #main.lb1, "selection? item$" 'get the nameFuture** One of theitem selected. #main.lb1, "selectionindex? currec" 'Get the current record numberadvantages of this format is that it affords us theselected item. #main.st1, "Moving - "+item$ 'Indicates which item you will move. 'If an item has been movedability to update anda second item selected 'put the first item into the array at the last spot. if flag=1 then array$(lastmove)=origitem$ flag=0 'resetmodify theflag end if origitem$=item$ 'Saveinformation. Organizers reserve thenewly selected item's name. waitright to modify, expand, or delete articles as they determine such actions to be appropriate.[leftdown] 'When the left mouse button is depressed while in the graphic box. 'If the left button was depressed while in the lower 1/2 of the graphicbox. if MouseY > 20 then 'Mouse in lower half of graphic box goto [movedown] else 'Mouse was in the upper half of graphic box. goto [moveup] end if [moveup]'up button loop if currec=0 then wait 'If no item was selected when left button down in graphic box. if currec>1 then 'The current record must**Who Can Edit Articles** Articles can be2 or more or a move can't be done. a$=array$(currec-1) 'Get the item above the currently seleted item. array$(currec-1)=item$ 'Put the currently selected item in the array element above. array$(currec)=a$ 'Put the item from above into the current element. #main.lb1,"reload" 'Reload the array so it shows the move. 'Subtract one from the current record to indicate the current element of the array. currec=currec-1 'Select the new current array element. 'This is the new position of the selected item. #main.lb1,"selectindex ";currec end if 'Set the lastmove = to the current element so that if another item is 'selected, the item being moved will be replaced withedited by the originalname 'in the [selectitem] section above. lastmove=currec 'and set the flag to 1 so it will know a move has been effected. flag=1 'Make this API call as a 300 millisecond delay. 'This avoids an almost instant move to the top of the listbox. calldll #kernel32, "Sleep", 300 as ulong, result as void scan 'This scan is necessary to see when the left button is released 'while in this loop. goto [moveup] 'By looping to the beginning of this section, holding the left button 'down will continue to effect movement. [movedown]'down button loop if currec=0 then wait 'If no item was selected when left button down in graphic box. 'The current record must be less than the number of record or a move can't be done. if currec<NUMBERRECORDS then a$=array$(currec+1) 'Get the item below the currently seleted item. array$(currec+1)=item$ 'Put the currently selected item in the array element below. array$(currec)=a$ 'Put the item from below into the current element. #main.lb1,"reload" 'Reload the array so it shows the move. 'Add one from the current record to indicate the current element of the array. currec=currec+1 'Select the new current array element. 'This is the new position of the selected item. #main.lb1,"selectindex ";currec end if 'Set the lastmove = to the current element so that if another item is 'selected, the item being moved will be replaced with the original name 'in the [selectitem] section above. lastmove=currec flag=1 'and set the flag to 1 to indicate a move has been effected. 'Make this API call as a 300 millisecond delay. 'This avoidsauthors andalmost instant move to the top of the listbox. calldll #kernel32, "Sleep", 300 as ulong, result as void scan 'This scan is necessary to see when the left button is released 'while in this loop. goto [movedown] 'By looping to the beginning of this section, holding the left button 'down will continue to effect movement. [stopmove] 'If the left button is released. 'break out of the loop and wait. wait [quit]'Close or Cancel 'At this point the array can be saved to a file inby thenew order. #main.gb1, "cls" 'Unloadsite organizers. Others should suggest changes via thebitmaps from memory. unloadbmp "dnbutton" unloadbmp "upbutton" close #main endsite's dicussion feature. ---- [[#list]] **LIST ARTICLES HERE** * [[Creating an Image Map]] [[user:marcuslee]] - added to [[graphics|Graphics and Games]] * [[UsingTheFilesStatement|Using the FILES Statement]] [[user:alix]] - added to [[files|Using Files]] * [[GPFiles|Using Files as a General Purpose Interface]] [[user:BillBlack]] - added to [[files|Using Files]] * [[ImageConversion|Image conversion, window and screen dumps for LB4]] - by Mike Bradbury * [[FastFAQ|Fast FAQ: New to Liberty BASIC? Read this!]] - [[user:RodBird]] * [[SerialPortPropeller|Hardware Control with the Serial Port and Propeller]] - [[user:rabaggett]] * [[Hardware Control with the Serial Port and Propeller II]] - [[user:rabaggett]] * [[IntroToFiles|An Introduction to Working with Files]] - [[user:GordonR]] * [[Custom Controls in a Box]] - [[user:lbjoseph]]