Professional Documents
Culture Documents
Contents:
Download and run example program 3 Build example program 3 from scratch o The Database Design o The Software Design Download and run example program 4 Build example program 4 from scratch Download and run example program 5
-kay, the steps to follow) 1. .ust sa(e the file to your desktop% 2. Double click the file to open it with win/ip%
2note) you need to extract both files*% -n your desktop, you should now ha(e a folder called 0flexample0 "o in there and double3click 04ro,cet5%(bp0 2%(bp stands for 06isual Basic 4ro,ect0* 7ow, you should get 6B loaded up with that pro,ect, no problem8
9ith that going, you can push the play button 2center of the top tool bar* and see what it looks like% There are a couple of things you can do with it) :ou can add #Ds to the Database by entering some info in the textboxes and pushing the 0$dd This &nfo0 button :ou can select a row from the grid and hit the 0;emo(e Selected0 button to remo(e it permanently from the database
ac! to top""
The Database Design 1. -pen up S $ccess 2Start 3 4rograms 3 icrosoft $ccess* 2. 4ick 0Start a blank database0 from the wi/ard that pops up 3. 4ick a spot to sa(e the mdb file and a name for it 2mine was
0#D#ollection$%mdb0*
4. :ou'll get to the following window, where you double click on 0#reate a table
in design (iew)0
5. 9hen you double click that 0create table in design (iew0 thingie, you get to
this window)
6. :ou want to follow the following steps to get the table & was working with) 1. ake a field called ArtistName whose type is Text 2. ake a field called AlbumTitle whose type is Text 3. ake a field called Tracks whose type is Number 2,ust a long integer is
cool enough*
4. Select the rows in the design (iew 2as pictured abo(e* that ha(e
ArtistName and AlbumTitle 5. ;ight3click on that selection, and pick Primary Key from the menu you get% This will make both fields into primary keys% The idea is that they can be primary because you'll ne(er ha(e identical artist names and album titles 2otherwise what's the point<8*% -nce you'(e got your table built, ,ust close that window% :ou'll be automatically prompted to sa(e changes to the table design and to gi(e the table a name% & picked CDs, how original% )* -nce that's all done, you can either add a couple entries to the database by double clicking the #Ds table from the database design main window and inputting them manually or ,ust mo(e on to) 1xport the database to $ccess '=> 2this is the annoying part of the whole thing* ?ere's what you do) 1. "o to the Tools menu 2. Select Database Utilities 3. Select Convert Database 4. Select To Prior Access Database Version 5. :ou'll get a sa(e file dialog that will let you enter a name for your database% 2& used "CDCollection m!b"* .ust sa(e it in the same folder as your $ccess @AAA (ersion of the file% 9hate(er you call it, make sure you keep track of which database file is which (ersion88
7. 8. 9.
3% $dd the S!lex"rid control to your pro,ect) 1. "o to the Pro$ect menu, pick Com%onents 2. Scroll down the list of components until you find "&icroso"t 'lex(ri! Control ) * +s%,-"% Select that checkbox and hit the -C button to add the control to your pro,ect%
6. $dd two frames to the form using the tool and drawing them on the form% 7. #hange the caption of one to A!! ne# entry and the caption of the other to 8.
.emove /ntry Draw the following controls in the A!! ne# entry frame 2yes, actually in the frame*) 1. $ text box with the (name) txtArtistName 2. $ label abo(e that text box with the caption Artist Name 3. $ text box with the (name) txtAlbumTitle 4. $ label abo(e that text box with the caption Album Title 5. $ text box with the (name) txtTrackCount 6. $ label abo(e that text box with the caption Number o" Tracks 7. $ command button with the (name) cm!A!!/ntry and the caption A!! this in"o
9. 7ow, to the .emove /ntry frame, add the following controls) 1. $ command button with the (name) cm!.emove/ntry and the
caption .emove Selecte! click the button0 &S'lex(ri!1* to do what you want% &t's fairly customi/able, but here's all & did for this example program) 1. the 'llow*serResi+ing property was set to 5 2. the Cols property was set to 3 3. the Data$ource property was set to Data1 (** this is required **) this hooks the data source up to the !lex"rid% 4. the #ixedCols property was set to A while the #ixedRows property was set to 5% 2this is recommended* 5. the #ocusRect property was set to A% 6. the ,igh-ight property was set to 5% 7. the $crollTrac! property was set to True 8. the $election.ode property was set to 5 2selection by row only*% 9. the /ord/rap property was set to True 11. -kay, next the code% &n the form design window, double click the form, which should bring up the code window with a blank 'orm23oa!+- subroutine% ?ere's the code for it) Private Sub Form_Load() 'the format string just lets you define a format for how 'your flexgrid will appear SFlex!rid"#FormatString $ %&rtist 'ame (% ) _ %&lbum 'ame ( *ra+,s% 'ma,e sure the sear+h path to the db is always in the right spot -ata"#-atabase'ame $ &pp#Path ) %./-/olle+tion#mdb% 'set up the re+ordsour+e for the datasour+e and flexgrid +ontrol 'in this +ase0 it's just a raw S1L 2uery0 simple simple# -ata"#3e+ordSour+e $ %sele+t 4 from /-s order by &rtist'ame% 5nd Sub 12. 7ow, go back to the form design window and double click the A!! this in"o button% :ou should now ha(e a blank cm!A!!/ntry2Click+- subroutine% ?ere's what to fill in there) Private Sub +md&dd5ntry_/li+,() 'add a new entry to our table# 6ith -ata"#3e+ordset #&dd'ew 7&rtist'ame $ txt&rtist'ame 7&lbum*itle $ txt&lbum*itle 7*ra+,s $ txt*ra+,/ount #8pdate 5nd 6ith -ata"#3efresh '+lear the text fields on+e the new re+ord is added txt&rtist'ame $ %% txt&lbum*itle $ %%
2. $ label with the caption Select the entry you #ant to remove an! 10. 7ow, the most complicated part is formatting the !lex"rid 2which is called
txt*ra+,/ount $ %% 5nd Sub 13. +ast thing you need is the remo(e code% &n the form design window, double3 click the .emove Selecte! button% :ou should get a shell for the cm!.emove/ntry2Click+- subroutine% This is the code) Private Sub +md3emove5ntry_/li+,() 'delete an entry from the database 6ith -ata"#3e+ordset # ove ( SFlex!rid"#3ow 9 ") ' we minus one be+ause row :ero is the header row #-elete 5nd 6ith -ata"#3efresh 'set the fo+us ba+, to the first add field txt&rtist'ame#SetFo+us 5nd Sub 54% $nd we are done8 &t's actually pretty simple to do this stuff, no problem88 Before you run this thing, you will need to sa(e the pro,ect to the same folder that you sa(ed your database file from the abo(e section to%
ac! to the top""
-kay, the steps to follow) 1. .ust sa(e the file to your desktop% 2. Double click the file to open it with win/ip%
9ith that going, you can push the play button 2center of the top tool bar* and see what it looks like% Theres only one thing you can do with this one88) #lick and hold the mouse on the can(as and roll it around to draw a cute blue line
the s!etchpad 2orm in action (&es I3m rad) ac! to the top""
Build Example Program 0 2rom $cratch -kay, let's actually get to work building this thing% This one is actually Duite simple to build and shouldn't take too long at all88 #heck it out) 1. Start up 6B with a Standard 1B1 pro,ect 2this should be familiar terminology
to you by now*% tool and drawing on the form% .ust make it mostly the same si/e as the entire form% )* 3. #hange the picturebox's (name) property to read %icCanvas 4. 7ow double3click on the form 2not on the picturebox* to get access to a shell for the 'orm23oa!+- subroutine% The code for that looks like) Private Sub Form_Load() '3edraws the image when the window is +overed;un+overed pi+/anvas#&uto3edraw $ *rue '*he +anvas loo, and drawing behaviour pi+/anvas#-raw6idth $ < 'Lines are < units thi+, pi+/anvas#Fore/olor $ vb=lue 'Lines are blue pi+/anvas#=a+,/olor $ vb6hite '=a+,ground +anvas is white 5nd Sub 5. &f you go back to the form3design window and double click on the picturebox now, you'll get a shell for cm!Canvas2Click+- That's not the one you want% !rom the dropdown list on the top of the code window, pick the &ouseDo#n e(ent% ?ere's the code to fill that one in) 'Set the first point and start the line Private Sub pi+/anvas_ ouse-own(=utton &s >nteger0 Shift &s >nteger0 ? &s Single0 @ &s Single) >f =utton $ " *hen pi+/anvas#Line (?0 @)9(?0 @) 5nd >f 5nd Sub
6. -nce that's filled in, from the same e(ent drop3down list at the top of the code window, pick the &ouse&ove e(ent% The code for that bad boy is right here for the taking)
'/ontinue the line to the next point as we move the mouse Private Sub pi+/anvas_ ouse ove(=utton &s >nteger0 Shift &s >nteger0 ? &s Single0 @ &s Single) >f =utton $ " *hen pi+/anvas#Line 9(?0 @) 5nd >f 5nd Sub That should be it8 This is pretty simple, all it does is listen for a button click with the left mouse button on the picturebox% &f it gets a mousedown followed by a drag, it draws a blue line 2as was set up in the formEload subroutine*% Simple use of e(ents makes a fun little app88
ac! to the top""
-kay, the steps to follow) 1. .ust sa(e the file to your desktop% 2. Double click the file to open it with win/ip%
called 0Sketchpad@0 extended s!etchpad program "o in there and double3click 0Sketch@%(bp0 2%(bp stands for 06isual Basic 4ro,ect0* 7ow, you should get 6B loaded up with that pro,ect, no problem8
9ith that going, you can push the play button 2center of the top tool bar* and see what it looks like% There's tons of stuff you can do with this one) :ou can draw a line on the can(as you can change the colour of the line you draw on the can(as you can change the thickness of the line you draw on the can(as you can clear your can(as and start from scratch 2although witha picture like this, why would you clear it<<< )**