|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with Very BASIC programming
Hey guys I need help with a basic programing class and I thought someone can help me out so I can understand how to do the assignment. Compile using TRUEBASIC BRONZE (FREE!) www.truebasic.com....
Here is the code presented to me: ! HW 4B STARTER ! *** FIND ALL INSTANCES of TODO below for instructions on ! how to modify this starter program. ! ----- initialization ----- ! use library module that contains the external procedures ! which do all the detailed work LIBRARY "gui" ! call initialization routines CALL initRoutines ! ----- main loop which checks for events and handles them ------ DO CALL checkMouse(controlNum, mouseState, x, y) ! returns controlNum, mouseState, x, y CALL handleMouse(controlNum, mouseState, x, y) ! uses controlNum, mouseState, x, y LOOP ! loop terminated and program stopped by STOP in sub handle_QuitButton END ! ---- end of main program, library module follows ---------- MODULE gui ! We use a library module so we can have shared variables. ! Shared variables in list are available to all procedures in this library ! Arrays can be dimensioned with SHARE SHARE numControls ! number of GUI controls (buttons here) SHARE controls_array(101,4) ! array which holds x,y coordinates of GUI controls SHARE xpix, ypix ! output window coordinates are set to 1,xpix,1,ypix SHARE origin, boxSize ! origin location and size of boxes in grid (button controls) ! ************************************************** **** ! TODO: SHARE a string variable to hold your icon ! ************************************************** **** ! TODO: SHARE an 1D numeric array "clicks(10)" to hold number of clicks in each ! of the 4 boxes SUB drawIcon ! sub drawIcon is called by sub initRoutines ! ************************************************** ! TODO: draw BOX KEEP your icon in shared string variable ! boxes in grid (button controls) have sides of length boxSize (shared variable) ! and are drawn from x = orgin, y = origin (shared variable) END SUB SUB flasher(controlNum) ! sub flasher is called by sub handle_GridButton ! get x,y coordinates for this control LET xmin = controls_array(controlNum,1) + 2 LET xmax = controls_array(controlNum,2) - 2 LET ymin = controls_array(controlNum,3) + 2 LET ymax = controls_array(controlNum,4) - 2 ! ************************************************** ! TODO: increment (add one to) current value in ! array element clicks(controlNum) ! ************************************************** ! TODO: replace these lines showing blue square ! with lines to BOX SHOW your icon SET COLOR "blue" BOX AREA xmin, xmax, ymin, ymax PAUSE 0.2 BOX CLEAR xmin, xmax, ymin, ymax SET COLOR "black" END SUB SUB handle_MouseOutside(controlNum, mouseState) ! sub handle_MouseOutside is called by sub handleMouse ! mouse is not within a button IF mouseState = 3 then ! mouse button went up if true PRINT "count of clicks in each box:" FOR num = 2 to 5 ! quit button is controlNum = 1 LET xmin = controls_array(num,1) + 2 LET ymin = controls_array(num,3) + 2 ! ************************************** ! TODO: add print out of element number num of the 1D clicks array ! use STR$() and PLOT TEXT NEXT num END IF END SUB ! ---- standard subs ------------------------------- SUB initRoutines ! sub initRoutines is called at top of main program CALL initSharedVariables SET MODE "graphics" ! use output window pixel resolution for x,y coordinates ASK PIXELS xpix, ypix SET WINDOW 1, xpix, 1, ypix SET BACK "white" ! sub rollover requires setting a background color CLEAR ! clear to draw background color CALL drawUserInterfaceControls CALL drawIcon END SUB SUB initSharedVariables ! sub initSharedVariables is called by sub initRoutines LET numControls = 0 ! incremented in sub addControl - required variable END SUB SUB drawUserInterfaceControls ! sub drawUserInterfaceControls is called by sub initRoutines ! The order in which buttons are drawn determines button number & button number affects ! case number in sub handleMouse and name of corresponding sub handle_ ! Buttons drawn later can "cover" buttons drawn earlier. ! The inputs to drawButton are: ! name$, showName, showBorder, color$, xmin, xmax, ymin, ymax ! showName and showBorder values are 1 for true, 0 for false ! create quit button - button #1 CALL drawButton("quit", 1, 1, "transparent",20, 70, 20, 60) ! make n^2 buttons in a nxn grid - buttons # (1 + 1) to (n^2 + 1) ! n currently limited to 10 (n^2 = 100) by first dimension of controls_array set in SHARE below LET n = 2 ! grid is n-by-n boxes LET origin = 100 LET boxSize = round((ypix - 200)/n) FOR y = origin to origin+(n-1)*boxSize step boxSize FOR x = origin to origin+(n-1)*boxSize step boxSize CALL drawButton("box", 0, 1, "transparent",x, x+boxSize, y, y+boxSize) NEXT x NEXT y PRINT "click in boxes several times, then click outside of boxes..." END SUB |
|
#2
|
|||
|
|||
|
SUB drawButton(name$, showName, showBorder, color$, xmin, xmax, ymin, ymax)
! sub drawButton is called by sub drawUserInterfaceControls IF color$ = "transparent" then ! do nothing ELSE SET COLOR color$ BOX AREA xmin, xmax, ymin, ymax END IF SET COLOR "black" IF showName = 1 then PLOT TEXT, AT xmin + 10, ymin + 10: name$ IF showBorder = 1 then BOX LINES xmin, xmax, ymin, ymax ! insert x,y coordinates into control array CALL addControl(xmin, xmax, ymin, ymax) END SUB SUB addControl(xmin, xmax, ymin, ymax) ! sub addControl is called by sub drawButton ! columns 1-4 store the screen coordinates of the button ! could add another column to indicate control type (value 1 = button, 2 = label, etc.) ! if new types of controls are added LET numControls = numControls + 1 LET row = numControls ! add new info in this row number LET controls_array(row,1) = xmin LET controls_array(row,2) = xmax LET controls_array(row,3) = ymin LET controls_array(row,4) = ymax ! PRINT "added control number "; row ! xxx temp print END SUB SUB checkMouse(controlNum, mouseState, x, y) ! sub checkMouse is called in main event loop in main program ! returns number of control mouseUp detected over ! return 0 if no mouseUp detected over a control ! since controlNum is shared and therefore persistent ! we must set it to zero on each call of checkMouse or ! checkMouse stays "latched" on last control LET controlNum = 0 GET MOUSE x,y,mouseState ! search from last control drawn down to first since ! want event to be assigned to control drawn last if it covers ! a control drawn earlier FOR row = numControls to 1 step -1 ! now need to see if x,y of click is within the control boundaries IF x > controls_array(row,1) then IF x < controls_array(row,2) then IF y > controls_array(row,3) then IF y < controls_array(row,4) then ! x,y inside this control LET controlNum = row ! don't need to check others so exit EXIT FOR END IF END IF END IF END IF NEXT row END SUB ! ---- Add a new case to handleMouse for every new control ----- ! ---- and also add a new sub to handle the event. ------------- ! ---- Buttons are to be numbered in the order in which they --- ! ---- are drawn in the main program. -------------------------- SUB handleMouse(controlNum, mouseState, x, y) ! sub handleMouse is called in main event loop in main program SELECT CASE controlNum CASE 0 ! mouse is not over a control (not over Quit or grid buttons) CALL handle_MouseOutside(controlNum, mouseState) CASE 1 ! quit button CALL handle_QuitButton(controlNum, mouseState) CASE else ! buttons in grid CALL handle_GridButton(controlNum, mouseState) END SELECT END SUB SUB handle_QuitButton(controlNum, mouseState) ! sub handle_QuitButton is called by sub handleMouse SELECT CASE mouseState CASE 0 ! button is up CALL rollover(controlNum) CASE 1 ! button is down and dragging CASE 2 ! button went down CASE 3 ! button went up PRINT "PROGRAM HAS BEEN STOPPED" ! PLAY "MB g" STOP END SELECT END SUB SUB rollover(controlNum) ! sub rollover is called by sub handle_QuitButton SET COLOR "blue" ! not background color LET xmin = controls_array(controlNum,1)-2 LET xmax = controls_array(controlNum,2)+2 LET ymin = controls_array(controlNum,3)-2 LET ymax = controls_array(controlNum,4)+2 BOX LINES xmin, xmax, ymin, ymax PAUSE 0.01 ! if too long then miss mouse clicks SET COLOR "background" BOX LINES xmin, xmax, ymin, ymax SET COLOR "black" END SUB SUB handle_GridButton(controlNum, mouseState) ! sub handle_GridButton is called by sub handleMouse SELECT CASE mouseState CASE 0 ! button is up CASE 1 ! button is down and dragging CASE 2 ! button went down CASE 3 ! button went up CALL flasher(controlNum) END SELECT END SUB END MODULE ----------------------------------------------------------- NOW HERE IS WHAT I NEED TO DO: 1) Instead of showing a blue square when when a box is clicked, display a figure that you have created using Basic commands. 2) Dimension a 1D array and use it to keep track of the number of times each box in the grid was clicked. 3) At the end of the program, display inside each box the number of times that box was clicked. NOW I TRIED CREATING A STAR TO BE DISPLAYED IN THE BOX BUT NO GO! IT COMES OUT WHACKED OUT OF PLACE. IF SOMEONE CAN HELP ME WITH GIVING ME A SAMPLE TO LEARN FROM! THANKS! |
|
#3
|
|||
|
|||
|
Isn't truebasic like 80 gazillion years old and for DOS systems?
You can probably guess I have no idea about truebasic code. And please don't post your comments in all CAPS.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Help with Very BASIC programming |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|