Linking to an Ms-Access Data Source using Visual C++ 2008 Windows Forms Application

1.Create an Ms-Access database file using the following fields and data types:



2. Name your table as “tblApps” no quotes. Add appropriate record values for instance:



3. Name your Access database file as “dbICons” no quotes and save it in My documents. Make sure to close Ms-Access before you start Visual C++ 2008, otherwise you’ll get an “Already in use” error in the database connection part.

4. Click Start>All Programs>Microsoft C++ 2008 Express Edition.

5. Click File>New>Project>Select CLR from the Visual C++ Project Types tree view>Select Windows Forms Application from the Visual Studio installed templates pane>Enter your desired project name then click Ok.

6. Design your form as follows:



7. Just use the suggested control names above so that you will not get lost later on in this tutorial. To name a control, just select the control and change its name property value in the properties window.

8. At this moment we will now specify the name of our database that we wanted to connect to. To do that, click the Tools menu and select Connect to database:



9. Select Microsoft Access Database File (OLE DB) as a data source value then locate dbIcons and assign it as a Database filename value.



10. Click the oledbDataAdapter control from the general category of the toolbox and drag it to your form. There instances wherein the oledbdataadapter is not shown, to show it, click Tools>Choose Toolbox items>type “ole” not quotes in the filter textbox> then check everything that starts with “ole” then click the Ok button.

11. Once you have added an oledataadapter control, the data adapter configuration wizard will then come into view. If you noticed the table that you have connected previously (using step 8-9) is selected as a default value of the “what data connection should the data adapter use?” listbox. If not then click the listbox button then select “dbIcons” then click the Next button.



12. In the Choose a command type window, select the Use SQL statement radio button then click Next.

13. In the Generate SQL statement window, type “SELECT * FROM tblApps” no quotes in the blank pane then click Next>Finish.

14. Right-click>OleDbDataAdapter form the component tab>generate dataset>Ok.



15. Double-click your form then add the following in the Form_load event.
  1. //Populates the dataset  
  2. this->oleDbDataAdapter1->Fill(this->dataSet11,"tblApps");  
16. This will fill our dataset with record values from our database.

17. Bind the fieldname to an appropriate control using the following syntax:

  1. this->objectname->databindings->add(gcnew Binding(“Property”, datasetname,”Tablename.fieldname”);  

Add it below the oledbdataadapter.fill line. Your code should now look like this:

  1. private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {  
  2. //Populates the dataset  
  3. this->oleDbDataAdapter1->Fill(this->dataSet11,"tblApps");  
  4. //bind idlabel to the numappid fieldname  
  5. this->idlabel->DataBindings->Add(gcnew Binding("Text",this->dataSet11,"tblApps.numappid"));  
  6. //bind desclabel to the chrappdesc fieldname  
  7. this->desclabel->DataBindings->Add(gcnew Binding("Text",this->dataSet11,"tblApps.chrappdesc"));  
  8. //bind appPictureBox to the chriconurl fieldname  
  9. this->apppictureBox->DataBindings->Add(gcnew Binding("ImageLocation",this->dataSet11,"tblApps.chriconurl"));  
  10. }  
18. Click the run icon to start debugging, you should see the following outputs:

A simple “Hello World” program in BlueJ

1. Click Start>All Programs>BlueJ>BlueJ.
The BlueJ Environment will then come into view.

2. Click the Project menu>New project. In the Look in Listbox, select My documents> Enter “Example” (no quotes) in the Folder Name textbox then click Create.

3. Click the New Class button>Type “Hello” (no quotes) in the Class Name textbox> Ensure that Class is selected in the class type radio buttons then click OK.



A class icon with a caption “Hello” will then appear in the BlueJ workarea.



4.Double click the Hello class icon, the following source code window will then appear:



Before creating our “Hello World” program, let us first dissect the pre-made code bit by bit. If you noticed, I’ve enabled line numbers by clicking Options>Preferences>Display line numbers, for discussion purposes.

Line 8: Is the class declaration section. It simply tells the BlueJ compiler the name of our class and to create class file based on it.
Line 9: Indicates the beginning of our class.
Line 10-12: Is the instance variable declaration section. This is where we declare the variables that will be needed in our application.
Line 16-20: Is the variable initialization section. This is where we initialize the values of our variables.
Line 28-32: Is the method declaration section. This is where we specify the actions that our application is capable of performing.
Line 34: Simply specifies the end of our class.

5. Now that we’ve understood (somehow) Blue’s code structure, let us now make our hello world program. Go to the instance variable declaration section (Line 10-12) and change “private int x;” to “private String strtext;” no quotes. The reason why we are declaring a string variable instead of the default integer variable is because we will be storing text i.e. “Hello World” to this variable in the variable initialization section.



6. Go to the variable initialization section (Line 16 to 20) and assign a “Hello World” value to our previously declared variable. This can be done by erasing ‘x=0;’ and changing it to ‘strtext=”Hello World”;’.



7. Go to the method declaration section (Line 28-32). Since we will not be accepting a numeric value from other methods nor we will be passing numeric value, change :



To



8. Your code will now look like this:

  1. /** 
  2. * Write a description of class Hello here. 
  3.  
  4. * @author (your name)  
  5. * @version (a version number or a date) 
  6. */  
  7. public class Hello  
  8. {  
  9. // instance variables - replace the example below with your own  
  10. private String strtext;  
  11.   
  12. /** 
  13. * Constructor for objects of class Hello 
  14. */  
  15. public Hello()  
  16. {  
  17. // initialise instance variables  
  18. strtext="Hello World";  
  19. }  
  20.   
  21. /** 
  22. * An example of a method - replace this comment with your own 
  23.  
  24. * @param  y   a sample parameter for a method 
  25. * @return     the sum of x and y  
  26. */  
  27. public void sampleMethod()  
  28. {  
  29. //clears the previous outputs  
  30. System.out.println("\u000c");  
  31. //retrieves the value of the strtext variable and display it on the screen.  
  32. System.out.println(strtext);  
  33. }  
  34. }  
9. Click the compile button to convert your Bluej source code into bytecode.

10. Click the Close Button.

11. Create an Object based on your Hello class by right-clicking the Hello class icon>new Hello.



12. Right-click the name of the Hello object>Click your method i.e., sampleMethod.



13. You should now see an output similar to the following:



Google has recently deindexed all co.cc domain extensions names. You can see the details of that here http://www.theinquirer.net/inquirer/news/2092882/security-experts-claim-googles-cocc-ban-inefficient. www.aprogguide.co.cc will be transferring to blogspot for good in one week time.

Creating a Hit Points (HP) Indicator in DarkGDK

HP indicators are normally used in Adventure games to show the character’s present HP level. There are several ways to create an HP level indicator in DarkGDK but the easiest way (I guess) is to create a sprite sheet with three or more columns and with different HP numbers per column. For instance, three HP’s on the first column, two on the second and one on the last. If a character dies, display the appropriate column relative to the character’s HP level. This method can also be used to specify the remaining number of bullets left or the character’s current energy level. If you are confused, follow these steps:

1. Start Microsoft Visual 2008 C++ Express Edition.

2. Click File>New Project>Select the Wizards Project type>Select Dark GDK-2d Game from the Visual Studio installed templates.

3. Click View>Solution Explorer. Double-click main.cpp. The following should then appear:
  1. // Dark GDK - The Game Creators - www.thegamecreators.com  
  2.   
  3. // the wizard has created a very simple 2D project that uses Dark GDK  
  4. // it can be used as a starting point in making your own 2D games  
  5.   
  6. // whenever using Dark GDK you must ensure you include the header file  
  7. #include "DarkGDK.h"  
  8.   
  9. // the main entry point for the application is this function  
  10. void DarkGDK ( void )  
  11. {  
  12. // in this application a backdrop is loaded and then several  
  13. // animated sprites are displayed on screen  
  14.   
  15. // when starting a Dark GDK program it is useful to set global  
  16. // application properties, we begin by turning the sync rate on,  
  17. // this means we control when the screen is updated, we also set  
  18. // the maximum rate to 60 which means the maximum frame rate will  
  19. // be set at 60 frames per second  
  20. dbSyncOn   ( );  
  21. dbSyncRate ( 60 );  
  22.   
  23. // a call is made to this function so we can stop the GDK from  
  24. // responding to the escape key, we can then add in some code in our  
  25. // main loop so we can control what happens when the escape key is pressed  
  26. dbDisableEscapeKey ( );  
  27.   
  28. // now we will set the random seed value to the timer, this will  
  29. // help us to get more random values each time we run the program  
  30. dbRandomize ( dbTimer ( ) );  
  31.   
  32. // we are going to display a backdrop for the scene, to do this  
  33. // we load our image and give it an ID number of 1, this particular  
  34. // image is of a sky at night with stars  
  35. dbLoadImage ( "backdrop.bmp", 1 );  
  36.   
  37. // the next step is to create a sprite that uses this image, this  
  38. // is achieved by calling dbSprite and passing in a value of 1 for the  
  39. // sprites ID, 0 for the X coordinate, 0 for the Y coordinates and a  
  40. // value of 1 for the image  
  41. dbSprite ( 1, 0, 0, 1 );  
  42.   
  43. // next we will load in some animated sprites, before doing this  
  44. // we need to adjust the image color key, by using this function we  
  45. // can make a specific color be transparent, in our case we want this  
  46. // to be bright pink  
  47. dbSetImageColorKey ( 255, 0, 255 );  
  48.   
  49. // in this loop we're going to create some animated sprites, the image  
  50. // we load contains frames of animation for an asteroid  
  51. for ( int i = 2; i < 30; i++ )  
  52.  {  
  53.   // create an animated sprite and give it the ID number from the  
  54.   // variable i, next is the filename, now we come to how many frames  
  55.   // across and down, in our case this is 4, finally we come to the image  
  56.   // ID that the sprite will use, again we use i  
  57.   dbCreateAnimatedSprite ( i, "sprite.bmp", 4, 4, i );  
  58.   
  59.   // position our sprite at a random location  
  60.   dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i );  
  61.  }  
  62.   
  63.  // now we come to our main loop, we call LoopGDK so some internal  
  64.  // work can be carried out by the GDK  
  65.  while ( LoopGDK ( ) )  
  66.  {  
  67.   // run a loop through all our sprites  
  68.   for ( int i = 2; i < 30; i++ )  
  69.   {  
  70.    // move the sprite down and play its animation  
  71.    // moving from frame 1 to 16 with a delay of 60 ms  
  72.    dbMoveSprite ( i, -2 );  
  73.    dbPlaySprite ( i, 1, 16, 60 );  
  74.   
  75.    // check the position of the sprite, if it has gone off scren  
  76.    // then reposition it back to the top  
  77.    if ( dbSpriteY ( i ) > 500 )  
  78. dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i );  
  79. }  
  80.   
  81. // here we check if the escape key has been pressed, when it has  
  82. // we will break out of the loop  
  83. if ( dbEscapeKey ( ) )  
  84. break;  
  85.   
  86. // here we make a call to update the contents of the screen  
  87. dbSync ( );  
  88. }  
  89.   
  90. // when the user presses escape the code will break out to this location  
  91. // and we can free up any previously allocated resources  
  92.   
  93. // delete all the sprites  
  94. for ( int i = 1; i < 30; i++ )  
  95.   dbDeleteSprite ( i );  
  96.   
  97.  // delete the backdrop image  
  98.  dbDeleteImage ( 1 );  
  99.   
  100.  // and now everything is ready to return back to Windows  
  101.  return;  
  102. }  
4. Since we intend to make our sample application from the scratch, delete all the pre-made codes, except the following:
  1. // Dark GDK - The Game Creators - www.thegamecreators.com  
  2. #include "DarkGDK.h"  
  3.   
  4. // the main entry point for the application is this function  
  5. void DarkGDK ( void )  
  6. {  
  7.    
  8.  dbSyncOn   ( );  
  9.  dbSyncRate ( 60 );  
  10.   
  11.    
  12.  while ( LoopGDK ( ) )  
  13.  {  
  14.     
  15.   
  16.   // here we make a call to update the contents of the screen  
  17.   dbSync ( );  
  18.  }  
  19.   
  20. }  
5. Make a spritesheet using gimp or photoshop. In this example we will be using the following image: 6. Later on we will be dividing this image into three columns. If you noticed if we divide this image into three divisions each divisions we will have different number of HP’s. 7. Copy this image from whatever location you have saved it. In this example, I have saved it on my desktop so all I need to do is go to the desktop. Select the file “hplevel.bmp”. Then press CTRL + C to copy it.
8. Switch to Micorsoft Visual C++ 2008 DarkGDK to view our game again then click the Open File icon from the formatting toolbar. 9. This causes the Open File dialog box to appear. Click on the empty pane>Press Ctrl + V to paste our “hplevel.bmp” file. 10. The next thing that you’ll need to do is to load this image into the computer’s memory, and divide it into three columns. We can do so by using the dbCreateAnimatedSprite command. Click the cancel button from the open dialog box to close it. This causes our code window to appear. Enter the ff. after the dbSyncRate(60); line.
  1. //divides the image into 3 columns  
  2. dbCreateAnimatedSprite(1,"hplevel.bmp",3,1,1);  
11. If you run your application now, it will just display a blue screen. To display your animated sprite,use the dbSprite command. Enter the following code after the dbCreateAnimatedSprite line.
  1. //displays our animated sprite  
  2. dbSprite(1,0,0,1);  
12. Press Ctrl+ F5 to test our application again. If you noticed the first column of our animated sprite is shown together with a white background. To clear the white background, use the dbSetImageColorKey command. Enter the following before the dbCreateAnimated line:
  1. //clears the white background  
  2. dbSetImageColorKey(255,255,255);  
13. Your code should now look like this:
  1. // Dark GDK - The Game Creators - www.thegamecreators.com  
  2. #include "DarkGDK.h"  
  3.   
  4. // the main entry point for the application is this function  
  5. void DarkGDK ( void )  
  6. {  
  7.   
  8. dbSyncOn   ( );  
  9. dbSyncRate ( 60 );  
  10. //clears the white background  
  11. dbSetImageColorKey(dbRgb(255,255,255));  
  12. //divides the image into 3 columns  
  13. dbCreateAnimatedSprite(1,"hplevel.bmp",3,1,1);  
  14. //displays our animated sprite  
  15. dbSprite(1,0,0,1);  
  16.   
  17.   
  18.   
  19. while ( LoopGDK ( ) )  
  20. {  
  21.   
  22.   
  23. // here we make a call to update the contents of the screen  
  24. dbSync ( );  
  25. }  
  26.   
  27. }  
14. The next thing that we want to do is to subtract the number of HP’s everytime the space key is pressed. Of course you can replace this with more advanced algorithms such as when your player dies or when a shot is fired, etc. But for the sake of simplicity, lets just go with the space key(hehehe). 15. Declare an integer variable named intspritesheetcols just below #include "DarkGDK.h" line and assign a a default value 1. 16. Enter the following after the while ( LoopGDK ( ) ){
  1. //you can replace dbSpaceKey with  "if a player dies" or "if a gun is fired" algorithms  
  2. if (dbSpaceKey())  
  3. {  
  4. //increment the value of intspritesheetcols by 1  
  5. //if you recall we've initially assigned a starting value 1 to  
  6. //our intspritesheetcols variable. If you press the  
  7. //the space key for the first time it will be incremented by 1  
  8. intspritesheetcols=intspritesheetcols + 1;  
  9. //displays the spritesheet division relative to the specified  
  10. //intspritesheetcols value. The first time you press the space key  
  11. //intspritescols will have a value to causing the second column  
  12. //of our spritesheet to be displayed  
  13. dbSetSpriteFrame(1,intspritesheetcols);  
  14. //displays our sprite  
  15. dbSprite(1,0,0,1);  
  16. }  
  17. //if the number of columns exceeds 3  
  18. //you can display your game over screen here but in this case let's  
  19. //just exit the game  
  20. if(intspritesheetcols>3)  
  21. {  
  22. return;  
  23. }  
17. Your whole code should now look like this:
  1. // Dark GDK - The Game Creators - www.thegamecreators.com  
  2. #include "DarkGDK.h"  
  3. int intspritesheetcols=1;  
  4. // the main entry point for the application is this function  
  5. void DarkGDK ( void )  
  6. {  
  7.   
  8. dbSyncOn   ( );  
  9. dbSyncRate(5);  
  10. //clears the white background  
  11. dbSetImageColorKey(255,255,255);  
  12. //divides the image into 3 columns  
  13. dbCreateAnimatedSprite(1,"hplevel.bmp",3,1,1);  
  14. //displays our animated sprite  
  15. dbSprite(1,0,0,1);  
  16.   
  17. while ( LoopGDK ( ) )  
  18. {  
  19. //you can replace dbSpaceKey with  "if a player dies" or "if a gun is fired" algorithms  
  20. if (dbSpaceKey())  
  21. {  
  22. //increment the value of intspritesheetcols by 1  
  23. //if you recall we've initially assigned a starting value 1 to  
  24. //our intspritesheetcols variable. If you press the  
  25. //the space key for the first time it will be incremented by 1  
  26. intspritesheetcols=intspritesheetcols + 1;  
  27. //displays the spritesheet division relative to the specified  
  28. //intspritesheetcols value. The first time you press the space key  
  29. //intspritescols will have a value to causing the second column  
  30. //of our spritesheet to be displayed  
  31. dbSetSpriteFrame(1,intspritesheetcols);  
  32. //displays our sprite  
  33. dbSprite(1,0,0,1);  
  34. }  
  35. //if the number of columns exceeds 3  
  36. //you can display your game over screen here but in this case let's  
  37. //just exit the game  
  38. if(intspritesheetcols>3)  
  39. {  
  40. return;  
  41. }  
  42. // here we make a call to update the contents of the screen  
  43. dbSync ( );  
  44. }  
  45.   
  46. }  
18. Press CTRL + F5 to run your application. You should now see an output similar to the following:
19. That’s all.

Blender 2.5 Beta Boids Particle System

Boids particle system is used to emulate the movements of animals moving in clusters or groups. To create a simple boids simulation in Blender 3d 2.5 Beta, follow these steps:

1. Start Blender by clicking on Start>All Programs>Blender Foundation>Blender>Blender.

2. Press Esc to get rid of the Splash screen then select the default cube by right-clicking it.



3. Click the particles button in the Properties View (formerly known as Buttons Window).



4. Click the + (add particles) button.



5. Blender will automatically create a particle system named “ParticleSystem”. Locate the Physics category by scrolling the scrollbar down> Then click the boids button.



6. At this point you can press Alt+A to test our animation.If you noticed, our simulation does not would do that much because what we have done so far is to create the cube object as a source or emitter of our boids particles.

7. The next thing that we need to do is to add an object that will serve as destination or goal of our boids particles. To do that, position the 3d cursor a few blender units away from our cube object.



8. Press Shift + A>Mesh>Icosphere.



9. You can add any object you want as a destination of our boids particles but in this case we’ve used an icosphere as our goal object(no reason in particular). Select the icosphere by right-clicking on it>Click the Physics button from the Properties View.



10. Locate the Force Field category. Select Magnetic from the type listbox.



11. Select your cube object by right-clicking on it>Click the particles button> Locate the Boid Brain Category>Click the +(Add Rule) button>Select Goal.



12. Click the Goal object textbox> Select icosphere.



13. Press Alt+A to test your animation. If you noticed our boids particles seemed to be moving in the direction of our destination object (icosphere). Unfortunately it does not actually reached the icosphere because it dies after 50 frames. To increase the boids life, right-click the cube object>Click the Particles button. In the emission category, change its Lifetime value to 999.000.



14. You can change whatever particles lifetime value you like just make sure that it is identical to the ending frame of our animation. To change the ending frame of our animation, locate the End option in the timeline then change it to 999.



15. Press Alt + A to test your animation. You should now see an output similar to the following.

Display Record Values from Two Tables in ASP.net Visual Web Developer Express Edition

To display data from two tables in ASP.net, we’ll need two tables with one or more identical fields. One field should act as a primary key on one table and the other should act as a foreign key or normal key on the other table. For the sake of example, let’s make two tables tblStudents and tblBooks using the following structures:

a. tblStudents
Column NameData Type
chrstudidnchar(10)
chrstudfnamenchar(20
chrstudlnamnchar(20)

b. tblBooks

Column NameData Type
chrbookidnchar(10)
chrtitlenchar(30
chrauthornchar(30)
chrstudidnchar(10)

1. Start Visual Web Developer Express Edition.

2. Click File>New Website>Select Asp.net website from Visual Studio Installed Templates options>Click Ok.

3. Click View>Solution Explorer>Right-click App_Data from the solution Explorer>Add New Item>Select SQL Server Database from Visual Studio Installed templates options>Accept the default database.mdf name>Click Add.



4. The Database Explorer panel will then come into view. To create a new table>Right-click Tables from the database explorer panel>Select Add new table.



Enter the following column names, use chrstudid as a primary key:



5. Click the close(x) button when done. You will be prompted if you wanted to saves changes to the table, just Click the Yes button>Enter “tblStudents” in the Enter a name for the table textbox>Click Ok.

6. Click the + icon beside the Tables node in the database Explorer>Right-click tblStudents>Click Show Table Data.



Enter the following values:




7. Right-click Tables from the Database Explorer again then Select Add New Table.



Enter the following Column names using chrbookid as a primary key:





8. Click the close(x) button when done. You will be prompted if you wanted to saves changes to the table, just Click the Yes button>Enter “tblBooks” in the Enter a name for the table textbox>Click Ok.

9. Click the + icon beside the Tables node in the database Explorer>Right-click tblBooks>Click Show Table Data.



Enter the following values:



10. Click View Solution Explorer > Double-Click Default.aspx> Double-click the design button>Expand the Data category of the toolbox>Click and drag a SqlDataSource control to the Outline Designer window.



11. Click the configure data source link>Select Database.Mdf from the “Which data connection should your application use to connect to the database?” listbox>Next.


12. Click the Specify a custom SQL statement or stored procedure radio button>Next.

13. Click the SELECT tab then enter the following SQL statements in the SQL Statement textarea:



14. This statement retrieves the values of our specified column names from both tables. If you noticed, we’ve added tblStudents dot chrstudid to specify that the values should be retrieve from the tblStudents table since tblBooks table also has chrstudid.Moreover, we’ve added INNER JOIN to join our tables using a common field
due to the fact that chrbookid, chrtitle, and chrauthor exists on the other table.


15. Click next. You can click the test query button to preview the result then click the finish button.

16. Click a grid view control from the data category of the toolbox then drag it onto the Outline Designer. Select the name of your SQLDataSource from the gridview’s Choose Data Source List Box.



16. Press CTRL + F5 to test your application.

17. You should now see an output similar to the following screenshot: