Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 5th, 2006, 02:05 AM
ovadoggvo ovadoggvo is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 42 ovadoggvo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 38 m 22 sec
Reputation Power: 5
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

Reply With Quote
  #2  
Old September 5th, 2006, 02:05 AM
ovadoggvo ovadoggvo is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 42 ovadoggvo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 38 m 22 sec
Reputation Power: 5
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
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!

Reply With Quote
  #3  
Old September 6th, 2006, 08:21 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 57 m 26 sec
Reputation Power: 181
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

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Help with Very BASIC programming


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT