A simple 2D pong game in darkGDK

In case you are wondering, Pong is a video game that simulates ping pong. It is a game where you maneuver a bat or paddle by pressing a control or joystick and the goal of the game is to return the ball to the opposing side just like the real ping pong. If you totally don't have any idea how pong works, I suggest googling it first before moving onto the next section. Being accustomed with the game and how it works greatly aids in trasforming it into codes.

Apart from familiarizing the game, we also need to learn few darkGDK game operations and the underlying commands behind them. These operations and commands are enumerated below:

1. Displaying an Image

Before you can display an image in darkGDK, you'll need to load it first into the computer memory. To be able to do that, use the dbLoadImage command which has the following syntax:
  1. dbLoadImage("Imagefilename",imageloadid);  
Where;
1. Imagefilename is an existent image file saved inside your game project folder. darkGDK supports .bmp, .jpg, and .png image file types.

2. imageloadid is a unique image numeric id that can be used later on to refer to a loaded image.

Example:
  1. dbLoadImage("Galaxian.jpg",1);  
Once an image is loaded in the computer memory, you can then display it by using dbPasteImage or dbSprite. dbSprite has the following syntax:
  1. dbSprite(spriteid, x-coordinate, y-coordinate, imageloadid);  
Where;
1. spriteid is a numerical id that can be use to manipulate the displayed image. spriteid can be identical to the imageloadid.

2. x-coordinate and y-coordinate are the x and y coordinate of the upper-left corner of your sprite or image. If you are unfamiliar of x and y coordinate, think of the screen as the fourth quadrant of the Cartesian coordinate system. The upper left corner is the origin which has the coordinate of x=0,y=0. The value of x coordinate increases as you move right. The value of the y coordinate increases as you move down.

3. imageloadid is the numeric id of a loaded image that you wanted to display.

Example:
  1. dbSprite(1,0,01);  
2. Moving Sprites

Sprites and images can be moved or animated by using dbMoveSprite or by simply incrementing or decrementing the x and y coordinate of an image. If you are familiar with java, c++, or visual basic, you probably know what I am talking about.

3. Detecting Collisions

darkGDK comes with powerful command that can be used to detect sprite or object collision. To detect collision, simply use dbSpriteCollission or dbSpriteHit. dbSpriteHit has the following syntax:
  1. dbSpriteHit(Spriteid1, Spriteid2);  
Where;
1. Spriteid1 and Spriteid2 are the numeric spriteids of the images that you wanted to test for collision.

Now that you have learned few basic commands and operations in darkGDK,I guess we can proceed into making our pong game. The following steps demonstrates how:

1. Click Start>All Programs>Microsoft Visual C++ Express Edition.

2. Click on File>New>Project. In the Project Types tree control, select on Wizards.

3. Select Dark GDK-Game from the available Game project options.

4. Type “Pong” no quotes in the Project Name textbox then Click Ok.

5. Click on View>Solution Explorer. Locate Main.cpp in the Solution Explorer Window then double-click it.

6. The following should then appear:

  1. // Dark GDK - The Game Creators - www.thegamecreators.com     
  2. // the wizard has created a very simple project that uses Dark GDK     
  3. // it contains the basic code for a GDK application       
  4. // whenever using Dark GDK you must ensure you include the header file     
  5. #include "DarkGDK.h"      
  6. // the main entry point for the application is this function     
  7. void DarkGDK ( void )     
  8. {     
  9. // turn on sync rate and set maximum rate to 60 fps     
  10. dbSyncOn   ( );     
  11. dbSyncRate ( 60 );       
  12. // our main loop     
  13. while ( LoopGDK ( ) )     
  14. {     
  15. // update the screen     
  16. dbSync ( );     
  17. }       
  18. // return back to windows     
  19. return;     
  20. }     

7. Locate the line #include "DarkGDK.h" and declare the following variables below it:
  1. //handles the ball velocity, the larger the value   
  2. //the faster the ball will move  
  3. int ballxvelocity=5,ballyvelocity=5;  
  4. //handles the updated x and y coordinate of the ball  
  5. int ballxcoord,ballycoord;  
  6. //handles the updated x and y coordinate   
  7. //of player1's paddle  
  8. int bat1xcoord,bat1ycoord;  
  9. //handles the updated x and y coordinate   
  10. //of player2's paddle  
  11. int bat2xcoord,bat2ycoord;  

8. Locate the line dbSyncOn and dbSynRate(60) then type the following below it:
  1. //sets the window title to pong  
  2. dbSetWindowTitle("Pong");  
  3. //sets the window size to 600x400 that is  
  4. //x coordinates runs from 0-600  
  5. //y coordinates runs from 0-400  
  6. dbSetWindowSize(600,400);  
  7. //loads an image located in your game project folder  
  8. //and gives it an id of 1  
  9. dbLoadImage("ball.png",1);  
  10. //loads an image located in your game project folder  
  11. //and gives it an id of 2  
  12. dbLoadImage("bat1.jpg",2);  
  13. //loads an image located in your game project folder  
  14. //and gives it an id of 3  
  15. dbLoadImage("bat2.jpg",3);  
  16.   
  17. //displays the ball at the center of the screen  
  18. dbSprite(1,300,200,1);  
  19. //player1 paddle at the left side of the screen  
  20. dbSprite(2,50,150,2);   
  21. //player2 paddle at the right side of the screen   
  22. dbSprite(3,500,150,3);  


9. Locate the line while ( LoopGDK ( ) ) and type the following after the open curly bracket:
  1. //move the ball  
  2. //adds the value of ballxvelocity   
  3. //and the current x coordinate of the ball  
  4. //and assign it as a new ball x coord value  
  5. ballxcoord=dbSpriteX(1) + ballxvelocity;  
  6. //do the same with y  
  7. ballycoord=dbSpriteY(1) + ballyvelocity;  
  8. //displays the ball in the updated x and y coord positions  
  9. dbSprite(1,ballxcoord,ballycoord,1);  
  10. //if the ball collides with the   
  11. //top or bottom of the screen then  
  12. if (ballycoord <= 0 || ballycoord >= 400)   
  13. {  
  14. //Multiply ballyvelocity by negative 1  
  15. //The result will  later on be added to the  
  16. //current y coordinate of the ball  
  17. //causing the ball to change position  
  18. //depending on the value of ballyvelocity and  
  19. //the current coord of the ball  
  20. ballyvelocity=ballyvelocity*-1;  
  21. }  
  22. //if the ball collides with the left side   
  23. //or right side of the screen then  
  24. if (ballxcoord <= 0 || ballxcoord >= 600)  
  25. {  
  26. //Multiply ballxvelocity by negative 1  
  27. //The result will later on be added to the  
  28. //current x coordinate of the ball  
  29. //causing the ball to change position  
  30. //depending on the value of ballxvelocity and  
  31. //the current x coord of the ball  
  32. ballxvelocity=ballxvelocity*-1;  
  33. }  
  34.   
  35. //check bat collision  
  36. //if the ball collides with player 1's paddle  
  37. if (dbSpriteHit(1,2)==1)  
  38. {  
  39. //if at this point you still don't   
  40. //understand what this do  
  41. //I suggest recalling the rules in multiplying  
  42. //and adding negative numbers  
  43. ballxvelocity=ballxvelocity*-1;  
  44. }  
  45. //if the ball collides with player 2's paddle  
  46. if (dbSpriteHit(1,3)==1)  
  47. {  
  48. //reverse the direction of the ball  
  49. ballxvelocity=ballxvelocity*-1;  
  50. }  
  51.   
  52. //move the player 1 bat  
  53. //if the enter key is pressed  
  54. if (dbReturnKey()==1)  
  55. {  
  56. //decrement the paddle y coord value  
  57. //causing the paddle to move up  
  58. bat1ycoord=dbSpriteY(2)-5;  
  59. //display the paddle in the  
  60. //updated position  
  61. dbSprite(2,bat1xcoord,bat1ycoord,2);  
  62. }  
  63. //if the down arrow is pressed  
  64. if (dbShiftKey()==1)  
  65. {    
  66. //increment the paddle y coord value  
  67. //causing the paddle to move down  
  68. bat1ycoord=dbSpriteY(2)+5;  
  69. //display the paddle in its  
  70. //updated position  
  71.   
  72.   
  73.   
  74. //move player 2 bat  
  75. //if the up arrow is pressed  
  76. if (dbUpKey()==1)  
  77. {  
  78. //decrement the paddle y coord value  
  79. //causing the paddle to move up  
  80. bat2ycoord=dbSpriteY(3)-5;  
  81. dbSprite(3,bat2xcoord,bat2ycoord,3);  
  82. }  
  83. //if the shift key is pressed  
  84. if (dbDownKey()==1)  
  85. {  
  86. //increment the paddle y coord value  
  87. //causing the paddle to move down  
  88. bat2ycoord=dbSpriteY(3)+5;  
  89. dbSprite(3,bat2xcoord,bat2ycoord,3);  
  90. }  
10. Locate the line dbSync ( ); and type the following after the open curly bracket:
  1. //Deletes the loaded image  
  2. //and sprites when the game is closed  
  3. //this will free up the used memory  
  4. for ( int i = 1; i < 30; i++ )  
  5. dbDeleteSprite ( i );  
  6. dbDeleteImage ( 1 );  
11. Let's have a glance of our codes again and this time comments omitted:
  1. // Dark GDK - The Game Creators - www.thegamecreators.com  
  2.   
  3. // the wizard has created a very simple project that uses Dark GDK  
  4. // it contains the basic code for a GDK application  
  5.   
  6. // whenever using Dark GDK you must ensure you include the header file  
  7. #include "DarkGDK.h"  
  8. int ballxvelocity=5,ballyvelocity=5;  
  9. int ballxcoord,ballycoord;  
  10. int bat1xcoord,bat1ycoord;  
  11. int bat2xcoord,bat2ycoord;  
  12. // the main entry point for the application is this function  
  13. void DarkGDK ( void )  
  14. {  
  15. // turn on sync rate and set maximum rate to 60 fps  
  16. dbSyncOn   ( );  
  17. dbSyncRate ( 60 );  
  18. dbSetWindowTitle("Pong");  
  19. dbSetWindowSize(600,400);  
  20. dbLoadImage("ball.png",1);  
  21. dbLoadImage("bat1.jpg",2);  
  22. dbLoadImage("bat2.jpg",3);  
  23.   
  24.    
  25. dbSprite(1,300,200,1);     
  26. dbSprite(2,50,150,2);    
  27. dbSprite(3,500,150,3);    
  28.   
  29.   
  30.   
  31. // our main loop  
  32. while ( LoopGDK ( ) )  
  33. {  
  34. //move the ball  
  35. ballxcoord=dbSpriteX(1) + ballxvelocity;  
  36. ballycoord=dbSpriteY(1) + ballyvelocity;  
  37. dbSprite(1,ballxcoord,ballycoord,1);  
  38. if (ballycoord <= 0 || ballycoord >= 400)   
  39. {  
  40. ballyvelocity=ballyvelocity*-1;  
  41. }  
  42. if (ballxcoord <= 0 || ballxcoord >= 600)  
  43. {  
  44. ballxvelocity=ballxvelocity*-1;  
  45. }  
  46.   
  47. //check bat collission  
  48. if (dbSpriteHit(1,2)==1)  
  49. {  
  50.   
  51. ballxvelocity=ballxvelocity*-1;  
  52. }  
  53. if (dbSpriteHit(1,3)==1)  
  54. {  
  55.   
  56. ballxvelocity=ballxvelocity*-1;  
  57. }  
  58.   
  59. //moves player 1 bat  
  60. if (dbReturnKey()==1)  
  61. {  
  62. bat1ycoord=dbSpriteY(2)-5;  
  63. dbSprite(2,bat1xcoord,bat1ycoord,2);  
  64. }  
  65. if (dbShiftKey()==1)  
  66. {  
  67. bat1ycoord=dbSpriteY(2)+5;  
  68. dbSprite(2,bat1xcoord,bat1ycoord,2);  
  69. }  
  70.   
  71.   
  72. //moves player 2 bat  
  73. if (dbUpKey()==1)  
  74. {  
  75. bat2ycoord=dbSpriteY(3)-5;  
  76. dbSprite(3,bat2xcoord,bat2ycoord,3);  
  77. }  
  78. if (dbDownKey()==1)  
  79. {  
  80. bat2ycoord=dbSpriteY(3)+5;  
  81. dbSprite(3,bat2xcoord,bat2ycoord,3);  
  82. }  
  83.   
  84.   
  85. // update the screen  
  86. dbSync ( );  
  87. }  
  88. for ( int i = 1; i < 30; i++ )  
  89. {  
  90. dbDeleteSprite ( i );  
  91. dbDeleteImage ( 1 );  
  92. }  
  93. // return back to windows  
  94. return;  
  95. }  

12. Press F5 to test the game. You can press the Enter key and shift key to move player1's bat and the up and down arrow to move player2's bat.

13. And that's it. A very simple pong game using few lines of codes. At the point of writing I guess this was the very first pong game tutorial written using darkGDK. I will add attract mode animation, menus, scores, and AI enemy to this when I have time but for now, though it's incomplete, you can use it as starting point. Hope you'll learn something from it and enjoy the game.

A simple 2D Color Slot Machine in Dark GDK

I’m sure every one of us is familiar with slot machine or fruit machine game. Today we will be making a slight version of that game, and we are going to name it as “Color Slot Machine”. There are several elements missing in this game such as the game title screen and the game overview screen so I’ll just explain to you the mechanics of the game. Before the game starts you have an initial account of 100000. To play the game, click on the Spin button. After clicking on the Spin button the computer will generate random colors and your score depends upon the generated color. The scoring system is presented below:

ColorWin
Red-Green-Blue+2000
Red-Red-Red+1000
Green-Green-Green+1000
Blue-Blue-Blue+1000
Others-1000
The following steps demonstrate how to create this game:

1.Prepare the images that will be needed in your game. You can use Ms-Paint, Photoshop or GIMP. The following images are required for this game:



2. After preparing the images, Start Visual C++>File>New>Projects>Wizards>Select Dark GDK-Game>Type “Color Machine” in the name textbox (no quotes).

3. Assuming that you have saved the project in the default directory, minimize Microsoft Visual C++ then go to My Documents>Visual Studio 2008>Projects>Color Machine>Color Machine>Then paste the images that you have made in Step 1.



4. Maximize Visual C++>View>Solution Explorer>Double-click Main.cpp. The following should then come into view:

  1. // Dark GDK - The Game Creators - www.thegamecreators.com  
  2.   
  3. // the wizard has created a very simple project that uses Dark GDK  
  4. // it contains the basic code for a GDK application  
  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.  // turn on sync rate and set maximum rate to 60 fps  
  13.  dbSyncOn   ( );  
  14.  dbSyncRate ( 60 );  
  15.   
  16.  // our main loop  
  17.  while ( LoopGDK ( ) )  
  18.  {  
  19.   // update the screen  
  20.   dbSync ( );  
  21.  }  
  22.   
  23.  // return back to windows  
  24.  return;  
  25. }  

5. Locate the line #include "DarkGDK.h" then declare the following variables below it:
  1. //handles the spriteid of the left box  
  2. int intred;  
  3. //handles the spriteid of the middle box  
  4. int intgreen;  
  5. //handles the spriteid of the right box  
  6. int intblue;  
  7. //handles our loop  
  8. int intcounter;  
  9. //determines if the spin button has been clicked  
  10. int intclicked;  
  11. //displays our status text  
  12. char* chrmessage;  
  13. //handles the balance  
  14. int intbalance=100000;  

6. Locate the line dbSynRate(60); then replace the 60 with 10 so that dark GDK will try to play 10 frames per second and our loop will not play funny , then type the following after it:
  1. //sets the window title  
  2. dbSetWindowTitle("Color Slot Machine");  
  3. //sets the window size  
  4. dbSetWindowSize(400,400);  
  5. //loads our images  
  6. dbLoadImage("red.png",1);  
  7. dbLoadImage("green.png",2);  
  8. dbLoadImage("blue.png",3);  
  9. dbLoadImage("backdrop.png",4);  
  10. dbLoadImage("Spin.png",5);  
  11. dbLoadImage("pointer.png",6);  
  12. //displays our images  
  13. dbSprite(4,0,0,4);  
  14. //sets our backdrop alpha transparency  
  15. //so that our text will be visible  
  16. dbSetSpriteAlpha(4,150);  
  17. dbSprite(5,240,380,5);  
  18. dbSprite(1,130,100,1);  
  19. dbSprite(2,260,100,2);  
  20. dbSprite(3,390,100,3);  

7. Locate the Line while ( LoopGDK ( ) ) then type the following after the open curly brace:
  1. //sets text size to 30 points  
  2. dbSetTextSize(30);  
  3. //displays the balance  
  4. //I still don’t know how to concanate text  
  5. dbText(0,0,"Balance:");  
  6. dbText(150,0,dbStr(intbalance));  
  7.   //displays our status text  
  8.   dbText(250,250,chrmessage);  
  9.   //pessimistic programming  
  10.   //assume that the button has not yet been clicked  
  11.   intclicked=0;  
  12.   //hides our customized mouse pointer  
  13.   //so that only the mouse pointer is visible  
  14.   dbHideSprite(6);  
  15.   //Enables dbRnd to generate an unpredictable  
  16.   //random number generation  
  17.   dbRandomize(dbTimer());  
  18.   dbSetSprite(6,1,100);  
  19.   //enables our sprite to follow the mouse  
  20.   dbSprite(6,dbMouseX(),dbMouseY(),6);  
  21.   //if our hidden sprite collided with the mouse  
  22.   //and the button has been clicked  
  23.   if(dbSpriteHit(6,5)==1 && dbMouseClick()==1)  
  24.   {  
  25.   //assigns 1 to inclicked variable  
  26.   //resets the value of chrmessage  
  27.   intclicked=1;  
  28.   chrmessage="";  
  29.   //generate a random color 10 times  
  30.   for(intcounter=1;intcounter<=10;intcounter++)  
  31.   {  
  32.    intred=1 + dbRnd(2);  
  33.    intblue=1 + dbRnd(2);  
  34.    intgreen=dbRnd(2)+1;  
  35.    dbSprite(1,130,100,intred);  
  36.    dbSprite(2,260,100,intgreen);  
  37.    dbSprite(3,390,100,intblue);  
  38.    dbSync();  
  39.   }  
  40.   }  
  41.     
  42.   //check if the button has been clicked  
  43.   //if it was clicked then  
  44.   
  45.   if (intclicked==1)  
  46.   {  
  47.    //check for color matches  
  48.    if (intred==1 && intblue==1 && intgreen==1)  
  49.    {  
  50.    chrmessage="You win 1000!";  
  51.    intbalance=intbalance+1000;  
  52.     
  53.    }  
  54.    else if (intred==2 && intblue==2 && intgreen==2)  
  55.    {  
  56.    chrmessage="You win 1000!";  
  57.    intbalance=intbalance+1000;  
  58.    }  
  59.    else if (intred==3 && intblue==3 && intgreen==3)  
  60.    {  
  61.    chrmessage="You win 1000!";  
  62.    intbalance=intbalance+1000;  
  63.    }  
  64.    else if (intred==1 && intblue==2 && intgreen==3)  
  65.    {  
  66.    chrmessage="You win 2000!";  
  67.    intbalance=intbalance+1000;  
  68.    }  
  69.    //if no color matches then  
  70.    else  
  71.    {  
  72.    chrmessage="You Lose!";  
  73.    intbalance=intbalance-1000;  
  74.    }  
  75.   }  
  76.   //if the balance is less than or equal to zero  
  77.   if (intbalance<=0)  
  78.   {  
  79.   dbCLS();  
  80.   dbSetTextSize(32);  
  81.   dbText(180,250,"Insufficient balance");  
  82.   dbText(250,300,"GAME OVER");  
  83.   dbSync();  
  84.   dbWait(4000);  
  85.   return;  
  86.  }  
8. Let’s have a look of our code once again and this time, crappy comments ommitted.
  1. // Dark GDK - The Game Creators - www.thegamecreators.com  
  2.   
  3. // the wizard has created a very simple project that uses Dark GDK  
  4. // it contains the basic code for a GDK application  
  5.   
  6. // whenever using Dark GDK you must ensure you include the header file  
  7. #include "DarkGDK.h"  
  8. int intred;  
  9. int intblue;  
  10. int intgreen;  
  11. int intcounter;  
  12. int intclicked;  
  13. char* chrmessage;  
  14. int intbalance=100000;  
  15. // the main entry point for the application is this function  
  16. void DarkGDK ( void )  
  17. {  
  18.   
  19.  // turn on sync rate and set maximum rate to 60 fps  
  20.  dbSyncOn   ( );  
  21.  dbSyncRate ( 20 );  
  22.  dbSetWindowTitle("Color Slot Machine");  
  23.  dbSetWindowSize(400,400);  
  24.  dbSetGamma(500,255,500);  
  25.  dbLoadImage("red.png",1);  
  26.  dbLoadImage("green.png",2);  
  27.  dbLoadImage("blue.png",3);  
  28.  dbLoadImage("backdrop.png",4);  
  29.  dbLoadImage("Spin.png",5);  
  30.  dbLoadImage("pointer.png",6);  
  31.  dbSprite(4,0,0,4);  
  32.  dbSetSpriteAlpha(4,150);  
  33.  dbSprite(5,240,380,5);  
  34.  dbSprite(1,130,100,1);  
  35.  dbSprite(2,260,100,2);  
  36.  dbSprite(3,390,100,3);  
  37.   
  38.  // our main loop  
  39.  while ( LoopGDK ( ) )  
  40.  {  
  41.   
  42.   dbSetTextSize(30);  
  43.   dbText(0,0,"Balance:");  
  44.   dbText(150,0,dbStr(intbalance));  
  45.   dbText(250,250,chrmessage);  
  46.   intclicked=0;  
  47.   dbHideSprite(6);  
  48.   dbRandomize(dbTimer());  
  49.   dbSetSprite(6,1,100);  
  50.   dbSprite(6,dbMouseX(),dbMouseY(),6);  
  51.   if(dbSpriteHit(6,5)==1 && dbMouseClick()==1)  
  52.   {  
  53.   intclicked=1;  
  54.   chrmessage="";  
  55.    for(intcounter=1;intcounter<=10;intcounter++)  
  56.    {  
  57.    intred=1 + dbRnd(2);  
  58.    intblue=1 + dbRnd(2);  
  59.    intgreen=dbRnd(2)+1;  
  60.    dbSprite(1,130,100,intred);  
  61.    dbSprite(2,260,100,intgreen);  
  62.    dbSprite(3,390,100,intblue);  
  63.    dbSync();  
  64.    }  
  65.   }  
  66.   
  67.   if (intclicked==1)  
  68.   {  
  69.    if (intred==1 && intblue==1 && intgreen==1)  
  70.    {  
  71.    chrmessage="You win 1000!";  
  72.    intbalance=intbalance+1000;  
  73.     
  74.    }  
  75.    else if (intred==2 && intblue==2 && intgreen==2)  
  76.    {  
  77.    chrmessage="You win 1000!";  
  78.    intbalance=intbalance+1000;  
  79.    }  
  80.    else if (intred==3 && intblue==3 && intgreen==3)  
  81.    {  
  82.    chrmessage="You win 1000!";  
  83.    intbalance=intbalance+1000;  
  84.    }  
  85.    else if (intred==1 && intblue==2 && intgreen==3)  
  86.    {  
  87.    chrmessage="You win 2000!";  
  88.    intbalance=intbalance+1000;  
  89.    }  
  90.    else  
  91.    {  
  92.    chrmessage="You Lose!";  
  93.    intbalance=intbalance-1000;  
  94.    }  
  95.   }  
  96.     
  97.   if (intbalance<=0)  
  98.   {  
  99.   dbCLS();  
  100.   dbSetTextSize(32);  
  101.   dbText(180,250,"Insufficient balance");  
  102.   dbText(250,300,"GAME OVER");  
  103.   dbSync();  
  104.   dbWait(4000);  
  105.   return;  
  106.   }  
  107.   
  108.   // update the screen  
  109.     
  110.   dbSync ( );  
  111.  }  
  112.   
  113.  // return back to windows  
  114.  return;  
  115. }  
9. Press F5 to test our game. Click the Spin button and see what happens.

Binding a fieldname to a control programmatically in Visual J#

Before the Database Connection and Binding process I want you to make an Ms-Access database file named “dbEmployee” containing a table named “tblEmployee”. Use the following specifications:
Field Name Data Type Description
chrempno text Handles employee id
chrfname text Handles employee’s name
chrlname text Holds employee’s last name

After designing the structure of your table, you can enter appropriate values for each field. For instance:
chrempno chrfname Chrlname
2010A John Doe

Now that we are done creating a table and adding appropriate values to it, we can now link to that table and bind the fields to our windows application control by following these steps:

1. Start>All programs>Visual J# 2005 Express Edition.

2. Click File>New>Project>Select Windows Application from the windows studio installed templates then click Ok.

3. A new form will appear. Before adding appropriate controls to our form let us first establish a connection to our dbEmployee database file. To do this we will use a database access tool called OleDbDataAdapter. OleDbDataAdapter will enable us to set the filename of a database file and the name of the table that we wanted to be made available in our project. It also permits us to set-up how the record values will be displayed on our form by using an appropriate SQL statement.

4. By default, OleDbDataAdapter is not shown on the Visual J# 2005 Express control toolbox, to add it, click Tools>Choose control toolbox>Type “ole” (no quotes ) on the filter textbox then check all the items that starts with “ole” and finally click the Ok button. OleDbDataAdapter should now appear on your toolbox.

5. Expand the All Windows Forms toolbox category then double-click OleDbDataAdapter.

6. A Data Adapter configuration wizard will then appear. Click the new connection button>Select Microsoft Access Database File from the data source list.

7. Click the browse button then locate your dbEmployee.mdb file then click the Ok button.

8. Click Next>A message box containing the following prompt will appear:
“The connection you selected uses a local data file that is not in the current project would you like to your project for the connection? If you copy the data file to your project, it will be copied to the project’s output directory”> just click the Ok button then click next.

9. A Generate SQL statement, type “SELECT * FROM tblEmployee” (no quotes) this will export all the record value of our table to our project then. Click Next after typing the SQL statement and finally click the Finish Button.

10. After specifying the table name, right-click OleDbDataAdapter1 from the bottom portion of Visual J# IDE then click Generate Data Set then click the Ok button. If you are wondering what a dataset is, a Dataset is an imaginary box the holds the field names of your table. It is use a temporary storage box for table data.

11. At this point, you will need to design the interface of your application. Double-click the label tool. In the properties window, change its text to “Employee number:” (no quotes).

12. Double-click the label tool and put it in the right-side of your Employee number label. Change its name to Empnumberlabel.

13. Add another label below the Employee number label and change its text to “Firstname:” (no quotes). Put a label on its right side and name it Fnamelabel.

14. Add another label below the Firstname label and change its text to “Lastname:” (no quotes). Put another label on its right side and name it Lnamelabel.

15. Double-click your form, type the following code:
  1. //fills our dataset with record values  
  2. this.oleDbDataAdapter1.Fill(this.dataSet11);  
  3. //Use the dataset methods collection to retrieve the record values  
  4. //The get_Item() method after the get_Rows() method retrieves the table row value  
  5. //while the last get_Item retrieves the table column value  
  6. Empnumberlabel.set_Text(String.valueOf(dataSet11.get_Tables().get_Item("tblEmployee").get_Rows().get_Item(0).get_Item(0)));  
  7. //The index number of the first table row is 0, the second row is 1 and so on.  
  8. //Column index number starts from 0, the second table column is 1 and so on.  
  9. Fnamelabel.set_Text(String.valueOf(dataSet11.get_Tables().get_Item("tblEmployee").get_Rows().get_Item(0).get_Item(1)));  
  10. //Dataset collection methods returns an object data that is why we use the   
  11. //String.valueOf data conversion function to convert it to string.  
  12. Lnamelabel.set_Text(String.valueOf(dataSet11.get_Tables().get_Item("tblEmployee").get_Rows().get_Item(0).get_Item(2)));  
16. Your code should now look like this:
  1. private void Form1_Load(Object sender, System.EventArgs e)  
  2. {  
  3. this.oleDbDataAdapter1.Fill(this.dataSet11);  
  4. Empnumberlabel.set_Text(String.valueOf(dataSet11.get_Tables().get_Item("tblEmployee").get_Rows().get_Item(0).get_Item(0)));  
  5. Fnamelabel.set_Text(String.valueOf(dataSet11.get_Tables().get_Item("tblEmployee").get_Rows().get_Item(0).get_Item(1)));  
  6. Lnamelabel.set_Text(String.valueOf(dataSet11.get_Tables().get_Item("tblEmployee").get_Rows().get_Item(0).get_Item(2)));  
  7. }  
17. Press F5 to test your application.You should now see the following output:


Search a Record Value in Microsoft Visual Basic 2008 Express Edition

As you may probably know, standard navigational buttons are only effective if you are managing few record values but when it comes to billions of records a search module is considerably significant. Search module allows you to quickly test whether a specific record value exists in a multi-records database.
I’d been using Visual Basic 2008 Express Edition for a while now but I can hardly find a method appropriate in searching record. No wonder why most questions that relate to searching a record values in nearly all web forums are unanswered. Perhaps there are other methods that I may not know but here’s an approach that I discovered through inquiries and experimentation.

To give you an idea of how to do it, let us first examine the common algorithm shared by most search modules.

1. First, a search text is entered in a text box as an input.

2. That text is then compared to the first record or beginning of file(BOF). If the first record is equal to the search text, a corresponding record is then displayed.

3. If the search text is not equal to the first record, the record pointer is moved to the next record and a search text is then compared to that record.

4. The record pointer is continuously incremented until a match is found and the end of file(EOF) has not yet been reached.


At this point we will now apply these pseudo codes into our search module. Though that may seem simple, it is more complicated to use BOF and EOF functions in Visual Basic 2008 than in lower versions of Visual Basic. I barely know how to use them on text files, which leave us no choice but to do everything the lengthy yet easiest way. The following steps demonstrate how:


1. Design an Ms-Access 2003 database file named “dbnames” using the following field structure:

Field nameData TypeDescription
chrfname text Handles the firstname of whoever
chrlname Text Handles the lastname


2. Add the following values.

chrfname chrlname
John Doe
Jean Doe
Jane Doe

3. Save your table as “tblNames”.

4. After designing your table, close Ms-Access then click Start>Select All Programs then Click Visual Basic 2008 Express Edition. The Visual Basic 2008 Express Edition IDE should then appear.

5. Click the File menu then Select New Project.

6. The New Project dialog box should then come into view >Double-click Windows Forms Application from the available templates.

7. A new form will appear. Before adding appropriate controls to our form let us first establish a connection to our dbnames database file. To do this we will use a database access tool called OleDbDataAdapter. OleDbDataAdapter will enable us to set the filename of a database file and the name of the table that we wanted to be made available in our project. It also permits us to set-up how the record values will be displayed on our form by using an appropriate SQL statement.

8. By default, OleDbDataAdapter is not shown on the VB 2008 control toolbox, to add it, click Tools>Choose control toolbox>Type “ole” (no quotes ) on the filter textbox then check all the items that starts with “ole” and finally click the Ok button. OleDbDataAdapter should now appear on your toolbox.

9. Expand the All Windows Forms toolbox category then double-click OleDbDataAdapter.

10. A Data Adapter configuration wizard will then appear. Click the new connection button>Select Microsoft Access Database File from the data source list.

11. Click the browse button then locate your dbicons.mdb file then click the Ok button.

12. Click Next>A message box containing the following prompt will appear:
“The connection you selected uses a local data file that is not in the current project would you like to your project for the connection? If you copy the data file to your project, it will be copied to the project’s output directory”> just click the Ok button then click next.

13. A Generate SQL statement, type “SELECT * FROM tblNames” (no quotes) this will export all the record value of our table to our project then. Click Next after typing the SQL statement and finally click the Finish Button.

14. After specifying the table name, right-click OleDbDataAdapter1 from the bottom portion of VB 2008 IDE then click Generate Data Set then click the Ok button. If you are wondering what a dataset is, a Dataset is an imaginary box the holds the field names of your table. It is use a temporary storage box for table data.

15. At this point we will now design the interface of our application. Arrange your controls as follows:



Note: Those texts that appear beside each control are the suggested names for our form controls in this module. To change the value of the name property of each control, just click each individual control then locate the name property in the properties window then assign those descriptive names in our illustration correspondingly.

16. Click the label named Namelabel. In the properties window, locate data bindings>text>form1 instance>Dataset11>tblnames>chrfname. This will bind your field value to your Namelabel control.

17. Click the label named Lnamelabel. In the properties window, locate data bindings>text>form1 instance>Dataset11>tblnames>chrlname. This will bind your field value to your Lnamelabel control.

18. Double-click your form, type the following code:
  1. 'Populates your dataset with record values  
  2. OleDbDataAdapter1.Fill(DataSet11)  

19. Double-click your control named SearchButton then type the following:

  1. 'handles the row index number of our table  
  2. Dim introws as integer  
  3. 'determines whether the record is found or not  
  4. Dim blnfound as Boolean  
  5. 'at the start let us assume that a match has no yet been found  
  6. 'this is called pessimistic programming or something  
  7. blnfound=false  
  8. 'Holds the search text from the textbox   
  9. Dim strtext as String  
  10. 'Holds the record value from the chrfname field   
  11. Dim strname as String  
  12. 'Holds the total number of records  
  13. Dim inttotrec as Integer  
  14. 'this is our EOF  
  15. inttotrec=Dataset11.Tables("tblNames").Rows.Count  
  16. 'Moves the record pointer to the first record  
  17. 'which has a row index number of zero  
  18. introws = 0  
  19. 'Converts the value of the first record of our chrfname field to capital  
  20. 'letter and assign it to a variable named strname  
  21. strname = UCase(DataSet11.Tables("tblNames").Rows(introws).Item("chrfname"))  
  22. 'Converts the text entered in our search textbox to Uppercase  
  23. 'The purpose of converting both record values and search text to upper case  
  24. 'is to compare both values in uppercase form regardless of whatever  
  25. 'case they were typed initially  
  26. strtext = UCase(SearchTextBox.Text)  
  27. 'If the searchtext is equal to our record then  
  28. If (strtext = strname) Then  
  29. 'assign true to our blnfound variable  
  30. 'will be used later whether to display or not  
  31. 'to display our message box  
  32. blnfound = True  
  33. 'display the record values on their corresponding controls  
  34. 'to understand how to view records on your form  
  35. 'visit www.homeandlearn.com  
  36. 'this site helped me a lot when I was just starting .Net programming  
  37. 'thanks www.homeandlearn.com  
  38. NameLabel.Text=DataSet11.Tables("tblNames").Rows(introws).Item("chrfname")  
  39. LnameLabel.Text = DataSet11.Tables("tblEmployee").Rows(introws).Item("chrlname")  
  40. End If  
  41. 'if not equal to the first record then  
  42. While (strtext <> strname) And (introws < inttotrec - 1)  
  43. 'increment the record pointer   
  44. introws = introws + 1  
  45. 'assign the value of the next record pointer to strname  
  46. strname = UCase(DataSet11.Tables("tblNames").Rows(introws).Item("chrfname"))  
  47. 'tests if the next record value is equal to the search text  
  48. 'if yes then  
  49. If (strtext = strname) Then  
  50. 'assign true to our blnfound variable  
  51. blnfound = True  
  52. 'display the record values on their corresponding controls  
  53. NameLabel.Text=DataSet11.Tables("tblNames").Rows(introws).Item("chrfname")  
  54. LnameLabel.Text = DataSet11.Tables("tblNames").Rows(introws).Item("chrlname")  
  55. End If  
  56. 'Continue incrementing the record pointer until a match is found  
  57. 'and the end of file has not been reached  
  58. End While  
  59. 'if the record is not found,  display Record not found in our  messagebox  
  60. If blnfound = false Then  
  61. MsgBox("Record not found", MsgBoxStyle.Information, "Search a Record")  
  62. End If  

20. Press F5 to test your application.

21. Try searching names that exists in a database. You can also try searching records that doesn't exist. Notice how our search module works splendidly and effectively. Feels like birthday, right?

22. For future improvements of this module, I suggest adding search options such as search by name or by last name. And I leave that to you to figure out wahaha!

Creating a plain object in DarkGDK

A plain is a mesh object that can be used as ground in your game scene. To create a plain object, use the dbMakeObjectPlain function.

Syntax:

  1. dbMakeObjectPlain(object id,plain width,plain height);  

Example:
  1. dbMakeObjectPlain(1,100,100);  

By default an object is drawn in gray. You can add colors to your plain object by Using the dbColorObject function which has the following syntax:

  1. dbColorObject(object id, color);  

Colors can be defined by using the dbRGB function which has the following syntax:

  1. dbRGB(red,green,blue);  

Wherein red, green, and blue are numbers that ranges from 0-255.

The following codes demonstrates dbMakeObjectPlain and dbColorObject at work:

  1. // Dark GDK - The Game Creators - www.thegamecreators.com  
  2.   
  3. // the wizard has created a very simple project that uses Dark GDK  
  4. // it contains the basic code for a GDK application  
  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. // turn on sync rate and set maximum rate to 60 fps  
  13. dbSyncOn   ( );  
  14. dbSyncRate ( 60 );  
  15. //Creates a 400 X 200 plain object with an object id of 1 and   
  16. dbMakeObjectPlain(1,400,200);  
  17. //Applies a red color to our plain  
  18. dbColorObject(1,dbRGB(255,0,0));  
  19. //Positions the camera on the side of our object  
  20. dbPositionCamera(-1,-600,-100);  
  21. // our main loop  
  22. while ( LoopGDK ( ) )  
  23. {  
  24. // update the screen  
  25. dbSync ( );  
  26. }  
  27. //deletes all objects  
  28. for ( int i = 1; i < 50; i++ )  
  29. dbDeleteObject ( i );  
  30. // return back to windows  
  31. return;  
  32. }  

Accepting Decimal or Floating Point Inputs(Windows Forms Applications-Microsoft Visual C++ 2008 Express Edition)

In general, every data inputted in a textbox are treated as string. For instance if you enter 5, Visual C++ 2008 will treat it as “5” which is a problem if you intend to use the input in calculations. If you have read my post about Accepting Numeric Data, we have used int::Parse function to treat the input as a numeric data. Unfortunately int::Parse works only on whole number inputs and returns a build errors on floating point input. To prepare your variable or control in accepting floating point input use the float::Parse function.

Syntax:
  1. Destination=float::Parse(Source);  

Wherein;
1. Source can be a control or variable that where you will be getting your floating point data.
2. Destination is a control or variable will you will be displaying or storing your floating point data.

The following steps demonstrate float::Parse at work:

1. Start MSVC++ Express 2008 by clicking on the Start button, All Programs then clicking on the Microsoft Visual C++ Express Edition Start menu option.

2. Click File>New>Project. The new project dialog box will then come into view.

3. Select Windows Forms Application from the Visual Studio Installed templates, type the project name>Click Ok.
After clicking the Ok button, an IDE suited for windows forms application will then appear containing a form, a toolbox window, and a properties window.

4. Create a user interface similar to the one below:



Note: Those texts that appear beside each control are the suggested names for our form controls in this example. If you noticed I am using .Net naming convention in naming controls because it is simpler to use than Leszynski naming convention. To change the value of the name property of each control, just click each individual control then locate the name property in the properties window then assign those descriptive names in our illustration correspondingly.

5. Double-click your form then locate the following line:

#pragma endregion

6. Declare the following variables below it:

  1. float fltcurrpricex,fltcurrpricey, fltdiscountx,fltdiscounty, fltnewpricex,fltnewpricey;  

Declaring these variables below the #pragma endregion line allows our variables to be available publicly and to be used by other procedures.

Your code should now appear just like this:

  1. #pragma endregion    
  2. float fltcurrpricex,fltcurrpricey, fltdiscountx,fltdiscounty, fltnewpricex,fltnewpricey;    

7. Double-click the control named ComputeButton,type the following:

  1. fltcurrpricex=float::Parse(this->XPricetextBox->Text);  
  2. fltcurrpricey=float::Parse(this->YPricetextBox->Text);  
  3. fltdiscountx=float::Parse(this->DiscountXtextBox->Text);  
  4. fltdiscounty=float::Parse(this->DiscountYtextBox->Text);  
  5. fltnewpricex= fltcurrpricex - (fltcurrpricex*fltdiscountx);  
  6. fltnewpricey= fltcurrpricey - (fltcurrpricey*fltdiscounty);  
  7. this->XPricelabel->Text=Convert::ToString(fltnewpricex);  
  8. this->YPricelabel->Text=Convert::ToString(fltnewpricey);  

8. Your could willnow look like this:

  1. private: System::Void ComputeButton_Click(System::Object^  sender, System::EventArgs^  e)   
  2. {  
  3. fltcurrpricex=float::Parse(this->XPricetextBox->Text);  
  4. fltcurrpricey=float::Parse(this->YPricetextBox->Text);  
  5. fltdiscountx=float::Parse(this->DiscountXtextBox->Text);  
  6. fltdiscounty=float::Parse(this->DiscountYtextBox->Text);  
  7. fltnewpricex= fltcurrpricex - (fltcurrpricex*fltdiscountx);  
  8. fltnewpricey= fltcurrpricey - (fltcurrpricey*fltdiscounty);  
  9. this->XPricelabel->Text=Convert::ToString(fltnewpricex);  
  10. this->YPricelabel->Text=Convert::ToString(fltnewpricey);  
  11. }  

9.Press F5 to test your appliaction.

Storing and retrieving an image from a database file
(Visual Basic 2008 Express Edition)

One of the frequent problems encountered by most newbie database developers and designers is the difficulty in storing or retrieving an image data from a database file. Though there are a number of ways to store an image, the most comfortable way (for me) is to create a fieldname and store the URL (Uniform Resource Locator) or location and filename of an image as its value. One of the advantages of this approach is it allows you to access an image from a database file painlessly and swiftly compare to using ole objects. Prior to the image retrieval process, I want you to make a database file named “dbicon” containing a table named “tblicons” . This table will store the name and icon of a particular application. Use the following specifications:

Field Name
Data Type
Description
chrdesc
Text
This will store the name or descriptionof an application
chrimage
Text
This will store the icon of an application.I suggest that you use the maximum value for this field which is 255 because most image URLs contain multiple characters. Alternatively, you can use the memo data type.

To retrieve the image from the database file and display it into a picture box on your client application, use the ImageLocation property of the picture box then assign the value of your image fieldname as the ImageLocation’s value.

After designing the structure of your table, you can enter appropriate values for each field. For instance:

Chrdesc
chrimage
Apache Web Server
C:\Program Files\Apache Group\Apache\manual\images\favicon.ico
PHP
C:\Program Files\PHP\php.gif


Now that you are done designing your table, it’s time to retrieve the image from your database file and display it in a picture box on your client application. To achieve this, the idea is to make use of the ImageLocation property of the Picturebox and assign the value of your image fieldname to it. The following steps demonstrate how:

1. Click Start>Select All Programs then Click Visual Basic 2008 Express Edition. The Visual Basic 2008 Express Edition IDE should then appear.

2. Click the File menu then Select New Project.

3. The New Project dialog box should then come into view >Double-click Windows Forms Application from the available templates.

4. A new form will appear. Before adding appropriate controls to our form let us first establish a connection to our dbicons database file. To do this we will use a database access tool called OleDbDataAdapter. OleDbDataAdapter will enable us to set the filename of a database file and the name of the table that we wanted to be made available in our project. It also permits us to set-up how the record values will be displayed on our form by using an appropriate SQL statement.

5. By default, OleDbDataAdapter is not shown on the VB 2008 control toolbox, to add it, click Tools>Choose control toolbox>Type “ole” (no quotes ) on the filter textbox then check all the items that starts with “ole” and finally click the Ok button. OleDbDataAdapter should now appear on your toolbox.

6. Expand the All Windows Forms toolbox category then double-click OleDbDataAdapter.

7. A Data Adapter configuration wizard will then appear. Click the new connection button>Select Microsoft Access Database File from the data source list.

8. Click the browse button then locate your dbicons.mdb file then click the Ok button.

9. Click Next>A message box containing the following prompt will appear:
“The connection you selected uses a local data file that is not in the current project would you like to your project for the connection? If you copy the data file to your project, it will be copied to the project’s output directory”> just click the Ok button then click next.

10. A Generate SQL statement, type “SELECT * FROM tblicons” (no quotes) this will export all the record value of our table to our project then. Click Next after typing the SQL statement and finally click the Finish Button.

11. After specifying the table name, right-click OleDbDataAdapter1 from the bottom portion of VB 2008 IDE then click Generate Data Set then click the Ok button. If you are wondering what a dataset is, a Dataset is an imaginary box the holds the field names of your table. It is use a temporary storage box for table data.

12. At this point, you will need to design the interface of your application. Double-click the label tool. In the properties window, change its text to “Name:” (no quotes).

13. Double-click the textbox tool and put it in the right-side of your label. Change its name to Nametextbox.

14. Add another label and change its text property to “Icon” (no quotes).

15. Add a PictureBox and Position it below the Icon label. Change its name to IconPictureBox .

16. Now, double-click your form, the load procedure event should then come into view:

  1. Public Class Form1  
  2.   
  3. Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
  4.   
  5.       
  6. End Sub  
  7. End Class  

17. Type the following codes between the Private Sub and End Sub:

  1. 'This will fill our dataset with record   
  2. 'values specified in our OleDbDataAdapter1  
  3. OleDbDataAdapter1.Fill(DataSet11)  
  4. 'Displays the first record of the   
  5. 'first fieldname from our tblicons     table  
  6. NameTextBox.Text =DataSet11.Tables("tblicons").Rows(0).Item("chrname")  
  7. 'Extract the URL of our image stored   
  8. 'on the first record value of our   chrimage field and  
  9. 'store it as a value of our picturebox ImageLocation property  
  10. PictureBox1.ImageLocation =DataSet11.Tables("tblicons").Rows(0).Item("chrimage")  
18. Your code will now look like this:

  1. Public Class Form1  
  2.   
  3. Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
  4. 'This will fill our dataset with   
  5. 'record values specified in our OleDbDataAdapter1  
  6.    OleDbDataAdapter1.Fill(DataSet11)  
  7. 'Displays the first record of the   
  8. 'first fieldname from our tblicons table  
  9. NameTextBox.Text = DataSet11.Tables("tblicons").Rows(0).Item("chrname")  
  10. 'Extract the URL of our image stored   
  11. 'on the first record value of our   chrimage field and  
  12. 'store it as a value of our   
  13. 'picturebox ImageLocation property  
  14.    PictureBox1.ImageLocation = DataSet11.Tables("tblicons").Rows(0).Item("chrimage")  
  15.   
  16.     End Sub  
  17. End Class  

18. Press F5 to see the culmination of your effort.

19. You should now see “Apache” beside the Name label and a quill icon beside the Icon label.

Connecting to an Ms-Access 2003 database file using Visual Basic 2008 Express Edition

The simplest way to retrieve a data from an Ms-Access 2003 database file in VB 2008 Express Edition is to use Database Explorer. Database Explorer is a database management tool that enables user to access server-based or local-based databases. There are other handy database access tools such as OleDbDataAdapter or SqlDataAdapter but I prefer using Database Explorer because it is simpler to use and it allows you to link to a database file conveniently and effortlessly.

To connect to an Ms-Access database file, you should first specify the location and file name of the database file that you wanted to link to. The following steps show you how:

1. Create an Ms-Access 2003 database file.(If you are familiar with database programming, this one is just common sense to you).

2. Start Visual Basic 2008 Express Edition.

3. Click File>New Projects>Select Windows Forms Application from the Visual Studio installed templates option>Click the Ok button.
This will display a blank form on the screen.

4. Next, click the View menu>Select Database Explorer. This will display the Database Explorer panel on the left portion of your VB 2008 Express Edition Integrated Development Environment. Alternatively, you can press CTRL+ALT+S.

5.In the Database explorer panel, locate the Add Connections option>Right-click it, then select Add connection…

6. The Add Connection Dialog box will appear. Click the Change… button beside the data source label>Select Microsoft Access Database File form the data source list box>Click Ok.

7. Click the Browse… button beside the Database file name label then locate and double-click your (Ms-Access database file).mdb file>Click Ok.

Click the Test Connection button to test if the database connection is working properly. Just make sure that you database file is not password protected or else you will get a “Not a valid Password” error.

After choosing the file name of the Ms-Access file that you wanted to connect to, you will need to select the data source or the data that you wanted to work with your application. Data sources can be made from a database application such as Ms-Access, or from a web server.

To define the data source, follow these steps:

1.Click the Data menu>Click the Add new data source… option.

This will bring out the Data Source Configuration Wizard. Since we will be getting our data from a database application and not from a web-server and definitely not from any bound object embedded on a form,select database>Click the Next button.

2.In the next screen, you will see your database file name in the Data Connection list box>Just click the next button.

3. After clicking the next button, a message box containing the following prompt will appear:
“The connection you selected uses a local data file that is not in the current project. Would you like to copy the file to you project and modify the connection?
If you copy the file to your project, blah blah blah”. Just click the Yes button.

4.The connection string dialog box will appear. A connection string is simply a string containing information about the connection.Just click the Next button.

5.The Database object screen will be shown containing a tree control with Tables and Views parent items. Tables contains your actual table while Views stores virtual tables,To manipulate your actual table, just expand the Tables parent item, and check the table that you wanted to be available in you project. Alternatively, you can check the Tables parent item if you wanted all you tables to be made available on your project.

6.Finally, click Finish.

After designating the table where you wanted to get your records from, the next thing that you need to do is to show the record values on your form. These steps teach you how:

1.Click the Data menu> Select Show Data Sources. This will show the available data sources or tables in a tree control. Alternatively, you can also press Shift+Alt+D.

2. In the Data Sources Panel, expand the table that you wanted to view the data in a form>Click and drag the individual fieldnames from the data sources panel to your form.

3. A bound control will be displayed for each field name. Together with a binding navigator that contains next, top, bottom, previous, add, delete, and save buttons.

4. Press F5 to run your application.

Try to click any of the navigational buttons and see how they worked perfectly like a charm. If you missed any of the steps during the connection process then your application will definitely fail. But don't despair, as Henry Ford once said, "Failure is simply the opportunity to begin again, this time more intelligently".

A Simple Hello World Program (Windows Forms Application-Microsoft Visual C++ 2008 Express Edition)

From the name itself, a windows forms application is local-based application that uses a graphical user interface similar to windows. The following steps show you how to create a windows forms application and display a "Hello world!" text in it:

1. Start MSVC++ Express 2008 by clicking on the Start button, All Programs then clicking on the Microsoft Visual C++ Express Edition Start menu option.

2. Click File>New>Project. The new project dialog box will then come into view.

3. Select Windows Forms Application from the Visual Studio Installed templates, type the project name>Click Ok.
After clicking the Ok button, an IDE suited for windows forms application will then appear containing a form, a toolbox window, and a properties window.

4. Select your form by clicking its title bar. In the properties window, locate the Name property then assign “NameForm” as its value. In similar manner, locate the Text property then assign “Display Hello World” as its value. Both values should be entered without quotation marks.


5. In the toolbox window, Select the label tool then click and drag it into an area in your form where you wanted to appear your “Hello world!” text.

6. Select your label, in the properties window, locate the Name property then assign “HelloLabel” as its value. In the same manner, locate the Text property then assign “Hello world!” as its value. Both values should be typed without quotation marks.

7. Press F5 to execute your application. If all went well, you should now see you windows form application with a "Hello world!" text displayed in it.

Changing the value of a control property through codes (Windows Forms Application-Microsoft Visual C++ 2008 Express Edition)

In case you might not notice, Visual Programming otherwise known as Object-Oriented programming revolves around changing the values of a property of an object through codes. To change the value of a control property using codes in Visual C++ Express Edition, use the following syntax:

  1. //enclosed the value in a quotation mark   
  2. //if the value of a property is a string  
  3. this->ControlName->Property=”value”;   
  4. //do not add quotation marks  
  5. //if the value of the property is Boolean or Number  
  6. this->ControlName->Property=value;  

The following steps illustrate a sample application of this syntax:

1. Start MSVC++ Express 2008 by clicking on the Start button, All Programs then clicking on the Microsoft Visual C++ Express Edition Start menu option.

2. Click File>New>Project. The new project dialog box will then come into view.

3. Select Windows Forms Application from the Visual Studio Installed templates, type the project name>Click Ok.
After clicking the Ok button, an IDE suited for windows forms application will then appear containing a form, a toolbox window, and a properties window.

4. Design your interface similar to the one shown below:



Note: Those texts that appear beside each control are the suggested names for our form controls in this example. If you notice I am using .Net naming convention in naming controls because it is simpler to use than Leszynski naming convention. To change the value of the name property of each control, just click each individual control then locate the name property in the properties window then assign those descriptive names in our illustration correspondingly.


5. Double-click the control named FnameButton, then enter:

  1. //this will assign John as an FnameLabel text  
  2. this->FnameLabel->Text=”John”;   

Your code will now look like this:

  1. private: System::Void FnameButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. this->FnameLabel->Text=”John”;  
  3. }  

6. Double-click LnameButton, the following should then the following between the open and close curly brackets:

  1. //this will assign John as an FnameLabel text  
  2. this->LnameLabel->Text=”Doe”;   


Your code will now look like this:


  1. private: System::Void LnameButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. this->LnameLabel->Text=”Doe”;  
  3. }  

7. Double-click the control named ExitButton, then type this->Close(); between the open and curly brackets. The Close() method terminates the current form.

Your code will now look like this::


  1. private: System::Void ExitButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. this->Close();  
  3. }  

8. Press F5 to run your application. If all went well, you will see our sample application instantly without build erros.

Using Math Operators (Windows Forms Applications-Microsoft Visual C++ 2008 Express Edition)

As you may already know, math operators are used to perform mathematical computations and just like any other languages, MSVC++ 2008 Express supports the following basic math operators:

(+)Addition
(-)Subtraction
(/)Division
(*)Multiplication

The following steps demonstrate these operators at work:

1. Start MSVC++ Express 2008 by clicking on the Start button, All Programs then clicking on the Microsoft Visual C++ Express Edition Start menu option.

2. Click File>New>Project. The new project dialog box will then come into view.

3. Select Windows Forms Application from the Visual Studio Installed templates, type the project name>Click Ok.
After clicking the Ok button, an IDE suited for windows forms application will then appear containing a form, a toolbox window, and a properties window.

4. Create a user interface similar to the one below:



Note: Those texts that appear beside each control are the suggested names for our form controls in this example. If you noticed I am using .Net naming convention in naming controls because it is simpler to use than Leszynski naming convention. To change the value of the name property of each control, just click each individual control then locate the name property in the properties window then assign those descriptive names in our illustration correspondingly.

5. Double-click your form then locate the following line:
  1. #pragma endregion  
6. Declare the following variables below it:
  1. int intnum1, intnum2, intans;  
Declaring these variables below the #pragma endregion line allows our variables to be available publicly and to be used by other procedures.

Your code should now appear just like this:
  1. #pragma endregion  
  2. int intnum1, intnum2,intans;  

7. Double-click the control named TimesButton,type the following:

  1. intnum1=int::Parse(this->FnumTextBox->Text);  
  2. intnum2=int::Parse(this->SnumTextBox->Text);  
  3. intans=intnum1 * intnum2;  
  4. this->OperatorLabel->Text="*";  
  5. this->AnsLabel->Text=Convert::ToString(intans);  

Your code should now appear just like this:

  1. private: System::Void TimesButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. intnum1=int::Parse(this->FnumTextBox->Text);  
  3. intnum2=int::Parse(this->SnumTextBox->Text);  
  4. intans=intnum1 * intnum2;  
  5. this->OperatorLabel->Text="*";  
  6. this->AnsLabel->Text=Convert::ToString(intans);  
  7. }  

8. Double-click the control named DivButton,type the following:
  1. intnum1=int::Parse(this->FnumTextBox->Text);  
  2. intnum2=int::Parse(this->SnumTextBox->Text);  
  3. intans=intnum1 / intnum2;  
  4. this->OperatorLabel->Text="/";  
  5. this->AnsLabel->Text=Convert::ToString(intans);  

Your code should now appear just like this:
  1. private: System::Void DivButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. intnum1=int::Parse(this->FnumTextBox->Text);  
  3. intnum2=int::Parse(this->SnumTextBox->Text);  
  4. intans=intnum1 / intnum2;  
  5. this->OperatorLabel->Text="/";  
  6. this->AnsLabel->Text=Convert::ToString(intans);  
  7. }  

9. Double-click the control named AddButton,type the following:
  1. intnum1=int::Parse(this->FnumTextBox->Text);  
  2. intnum2=int::Parse(this->SnumTextBox->Text);  
  3. intans=intnum1 + intnum2;  
  4. this->OperatorLabel->Text="+";  
  5. this->AnsLabel->Text=Convert::ToString(intans);  

Your code should now appear just like this:
  1. private: System::Void AddButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. intnum1=int::Parse(this->FnumTextBox->Text);  
  3. intnum2=int::Parse(this->SnumTextBox->Text);  
  4. intans=intnum1 + intnum2;  
  5. this->OperatorLabel->Text="+";  
  6. this->AnsLabel->Text=Convert::ToString(intans);  
  7. }  

10. Double-click the control named DiffButton,type the following:
  1. intnum1=int::Parse(this->FnumTextBox->Text);  
  2. intnum2=int::Parse(this->SnumTextBox->Text);  
  3. intans=intnum1 - intnum2;  
  4. this->OperatorLabel->Text="-";  
  5. this->AnsLabel->Text=Convert::ToString(intans);  

Your code should now appear just like this:
  1. private: System::Void DiffButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. intnum1=int::Parse(this->FnumTextBox->Text);  
  3. intnum2=int::Parse(this->SnumTextBox->Text);  
  4. intans=intnum1 - intnum2;  
  5. this->OperatorLabel->Text="-";  
  6. this->AnsLabel->Text=Convert::ToString(intans);  
  7. }  

11. Double-click the control named ClearButton,type the following:
  1. this->FnumTextBox->Text="";  
  2. this->SnumTextBox->Text="";  
  3. this->OperatorLabel->Text="";  
  4. this->AnsLabel->Text="";  

Your code will now look like this:
  1. private: System::Void ClearButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. this->FnumTextBox->Text="";  
  3. this->SnumTextBox->Text="";  
  4. this->OperatorLabel->Text="";  
  5. this->AnsLabel->Text="";  
  6. }  


12.Double-click ExitButton, then type this->Close:
  1. private: System::Void ExitButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. this->Close();  
  3. }  
13. Press F5 to execute your application. I will add comments to the codes above when I have time. Till then:)

Accepting and Displaying String Inputs (Windows Forms Applications-Microsoft Visual C++ 2008 Express Edition)

Visual C++ 2008 accepts and displays input in a manner that is very similar to java. In other words, the method used in accepting string data is different from the method used in accepting numeric data.
To accept a string data, and display it on your desired control, use the following syntax:

  1. this->DestinationObjectName->Property=Convert::ToString (this-> SourceObjectName->Property);  
  2. //or simply  
  3. this->DestinationObjectName->Property= this-> SourceObjectName->Property;  

Where;

1. DestinationObjectName is the name of the control where the value will be displayed.
2. SourceObjectName is the name of the control where the value will come from.

Convert::ToString is a method that converts a value inputted in a control to text or string. Using Convert::ToString method in accepting user’s input is not obligatory because all data inputted in a textbox are recognized as string.

A sample application of Convert::ToString method is demonstrated in the following steps:

1. Start MSVC++ Express 2008 by clicking on the Start button, All Programs then clicking on the Microsoft Visual C++ Express Edition Start menu option.

2. Click File>New>Project. The new project dialog box will then come into view.

3. Select Windows Forms Application from the Visual Studio Installed templates, type the project name>Click Ok.
After clicking the Ok button, an IDE suited for windows forms application will then appear containing a form, a toolbox window, and a properties window.

4. Create a user interface similar to the one shown below:



Note: Those texts that appear beside each control are the suggested names for our form controls in this example. If you noticed I am using .Net naming convention in naming controls because it is simpler to use than Leszynski naming convention. To change the value of the name property of each control, just click each individual control then locate the name property in the properties window then assign those descriptive names in our illustration correspondingly.

6. Double-Click the control named OkButton then key-in the following:

  1. //Converts the value inputted in the StringtextBox to string  
  2. //Using Convert::ToString method is optional because  
  3. //The text entered in a textbox is already interpreted as string  
  4. this->EnteredLabel->Text=Convert::ToString(this->StringtextBox->Text);   
Your code should then appear like this:

  1. private: System::Void OkButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. this->EnteredLabel->Text= Convert::ToString (this->StringtextBox->Text);  
  3. }  
7. Double-click ExitButton, then type this->Close(); between the open and close curly brackets. The this keyword refers to the current form while the Close() method ends the execution of the current form.

Your code should now like this:

  1. private: System::Void ExitButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. this->Close();  
  3. }  
8. Press F5 to execute your application. If you have followed our steps carefully, our sample application should now appear without build errors.

Accepting and Displaying Numeric Data (Windows Forms Applications-Microsoft Visual C++ 2008 Express Edition)

Oftentimes, we create programs that needs to ask numbers from the user.
To accept a numeric data in Visual C++ Express Edition, use the following syntax:

  1. Expression= int::Parse (this-> SourceObjectName->Property);  

Where;

1. Expression can either be an ObjectName or a variable.
2. SourceObjectName is the name of the control where the value will come from.

int::Parse is a method that converts text or string into an integer. The int::Parse method is required in accepting numeric inputs. If you omit the int::Parse method, the numeric input will be interpreted as string.

To display a numeric data, use the following syntax:

  1. this-> DestinationObjectName->Property=Convert::ToString(Expression);  

Where;

1. Expression can either be an ObjectName or variable.
2. SourceObjectName is the name of the control where the value will come from.

Convert::ToString is a method that converts a value inputted in a control to text or string and is required in displaying numeric output to avoid parameter conversion build errors.

To see int::Parse and Convert::ToString methods in action, follow these steps:

1. Start MSVC++ Express 2008 by clicking on the Start button, All Programs then clicking on the Microsoft Visual C++ Express Edition Start menu option.

2. Click File>New>Project. The new project dialog box will then come into view.

3. Select Windows Forms Application from the Visual Studio Installed templates, type the project name>Click Ok.
After clicking the Ok button, an IDE suited for windows forms application will then appear containing a form, a toolbox window, and a properties window.

4. Create a user interface similar to the one shown below:



Note: Those texts that appear beside each control are the suggested names for our form controls in this example. To change the value of the name property of each control, just click each individual control then locate the name property in the properties window then assign those descriptive names in our illustration correspondingly.

6. Double-Click the control named OkButton, the following event procedure should then come into sight:

7. Double-click the control named OkButton then type the following between the open and close curly brackets:
  1. //Converts the number inputed by the user into a numeric data  
  2. //and assign it to an integer variable named intusernum  
  3. int intusernum=int::Parse(this->StringtextBox->Text);  
  4. //Converts the numeric data into a string data and display it in a  
  5. //control named EnteredLabel  
  6. this->EnteredLabel->Text=Convert::ToString(intusernum);  

Your code should now look like this:
  1. private: System::Void OkButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. int intusernum=int::Parse(this->StringtextBox->Text);  
  3. this->EnteredLabel->Text=Convert::ToString(intusernum);     
  4. }   
8. Double-click the control named ExitButton then type this->Close();. This will terminate the execution of the current form. Your code will then look like this:
  1. private: System::Void ExitButton_Click(System::Object^  sender, System::EventArgs^  e) {  
  2. this->Close();  
  3. }     
9. Press F5 to execute your application.

Networking Visual FoxPro Database by Brute Force

There are variety of ways in networking databases in Visual FoxPro and today we will learn how to do it by brute force...Hopefully...

Preliminaries...

1. Ensure that you have a functional Local Area Network. For instance, if you want your PHONE DIRECTORY SYSTEM in StationA to be accessed in StationB, the first thing that you need to do is to start command prompt and ping StationB. Once you receive four packets response then both computers have working network connections. Additionally, make sure that both computers have file and printer sharing enabled.

2. Once network connection testing is complete and successful,you should now prepare your PHONE DIRECTORY SYSTEM for networked environment. Alter your source code and make sure that you have included the SHARED alias in your USE TABLE_NAME command. For instance, if your primary table is TFOXPHONEDIR, modify USE TFOXPHONEDIR to USE TFOXPHONEDIR SHARED. This will enable your table to be manipulated in a networked-based environment. Don't forget to save changes.

Almost there...

3. Next, create a program superlauncher for the first form of your PHONE DIRECTORY SYSTEM. To do this, press CTRL + F2 then type MODI COMM SUPERLAUNCHER in the command window. This command performs two things. It creates a Visual FoxPro program named superlauncher.prg and it displays the Visual FoxPro editor. Type the following in the FoxPro editor textarea:

  1. DO FORM FIRSTFORMNAME  

Don't forget to replace FIRSTFORMNAME with the actual firstname of your first form. For example if the filename of your first form is LOGINFORM.SCX, replace DO FORM FIRSTFORM with DO FORM LOGINFORM. CLick close to save changes.

4. Now, share the Microsoft Visual Studio Folder. This will enable your system to be available to all clients in the network, assuming that all your forms and databases are located inside the Visual Studio directory.

The finale...

5. To access your PHONE DIRECTORY SYSTEM in StationB or in any workstations in the network, browse your network places and locate your shared Microsoft Visual Studio folder. Look for your superlauncher.prg then double-click it.

6. In similar manner, double-click superlauncher.prg in StationA.You should now have phone directory systems activated in separate computers at the same time.

7. Though you are using the same form, it can perform independent actions in each workstations. To test your system, perform a record search in StationA, while one of your pals edits a record in StationB. Notice how it worked perfectly as mentioned. And that's all, a simple database networking  by brute force in VFP just for you.

Multiple Starting Values, Ending Values and Step Values in Looping Constructs for Structured Programming Languages

For starters, loop is a repetition structure that enables your program to execute the same statement(s) over and over and over and over and over again.There are several looping constructs that can be used for structured languages such as for, while,do-while,while-until and do-until. It's just so sad that most books showed us to use those statements by using only a single starting value,an ending value, and counter which made us conclude that it isn't possible to use compound loop elements.But did you know that you can use several initializations,loop conditions, and starting values in any looping constructs? You heard me right my friend. Here's how.
Syntax:

startingvalue1;
startingvalue2;
startingvaluen;
while((endingvalue1)&&(endingvalue2)&&(endingvaluen))
{
statement1;
statement2;
statementn;
stepvalue1;
stepvalue2;
stepvaluen;
}
For the sake of example I will be using while statement in PHP.

Example:
  1. <?php  
  2. $intcount1=1;  
  3. $intcount2=10;  
  4. $intcount3=21;  
  5. while(($incount1<=10)&&($intcout2>=1)&&($intcount3<=30))  
  6. {  
  7. echo "$intnum1 $intnum2 $intnum3   
  8. ";  
  9. $intcount1++;  
  10. $intcount2--;  
  11. $intcount3++;  
  12. }  
  13. ?>  
The script above produces the following outputs:

1 10 21
2 9 22
3 8 23
4 7 24
5 6 25
6 5 26
7 4 27
8 3 28
9 2 29
10 1 30

You can use this as a good alternative for nested loops. Or if you wanted to hit several birds in one stone, that is, several outputs in one looping statement.

Changing the Background and Static Text Color of your MFC Dialog box

By default, VC++ doesn’t have a backcolor or forecolor control properties unlike other visual programming languages such as VB or VFP. But you can change the dialog box text and back color by following these simple steps.

1. Start VC++ by clicking the start button>All Programs>Microsoft Visual Studio 6.0> Microsoft Visual C++ 6.0.
2. Click File>New>Select MFC AppWizard (exe)>Type the Project name>Click Ok>Select Dialog based>Click Finish.
3. Right click your dialog box>In the Class name list box>Select CprojectnameAPP>Double click the InitInstance member function.

The following codes will appear:

  1. CBkColorApp theApp;  
  2. /////////////////////////////////////////////////////////////////////////////  
  3. // CBkApp initialization  
  4. BOOL CBkColorApp::InitInstance()  
  5. {  
  6. AfxEnableControlContainer();  
  7.   
  8. // Standard initialization  
  9. // If you are not using these features and wish to reduce the size  
  10. // of your final executable, you should remove from the following  
  11. //  the specific initialization routines you do not need.  
  12.   
  13. #ifdef _AFXDLL  
  14. Enable3dControls(); // Call this when using MFC in a shared DLL  
  15. #else  
  16. Enable3dControlsStatic();// Call this when linking to MFC statically  
  17. #endif  
4. Type the following before or after the line AfxEnableControlContainer(). Change the numbers inside the oval brace to create different background or text colors.
  1. SetDialogBkColor(RGB(255,255,255),RGB(255,255,255));  
5. The first RGB is for the backcolor and the other one is for the text.
6. Click the run icon to view the result.

Adding Colors to you C++ Program Output

There are several methods that can be used to add colors to your C++ program output but the simplest way is by using the system function. The system function allows you to pass commands to the operating system for execution. The syntax of using system varies in different programming languages. In C++, system function takes the following syntax:

system(“command”);
example:

  1. system(“logoff”);  
To add a color to your program output, use the color command which has the following syntax:

color bf
Were b is the background and f is the foreground.
Available colors for background and foreground are as follows:

0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White
So if you want to have a black background with light green text, use:

  1. system(“color oa”);  

system function is typed inside your main function (or inside other functions) just after the opening curly brace and before the closing curly brace.

example:
  1. #include<iostream>  
  2. using namespace std;  
  3. int main()  
  4. {  
  5. system(“Color 0a”);  
  6. cout<<”I am blue”;  
  7. cin.get();  
  8. }  

The codes above produce a red text in black background. There are several things that you can do with the system function, and it’s up to you to discover. Good luck!

Viewing the Control Toolbox in Microsoft Visual C++ 6.0 MFC

Unlike other application and development tools, Visual C++ does not permit viewing some of its Integrated Development Environment (IDE) components such as dialog box or control toolbox using the View menu. Unintentionally closing an IDE component could result to total disarray. To show one of its important components, the Control toolbox, use any of the following methods:

Method 1:

1. Right-click an empty pane in the Microsoft Visual C++ toolbar. A pop-up menu containing several options will be displayed>Select Controls option.

Note: The Controls option only appears on the pop-up menu if your dialog-based application is shown on the screen. If you dialog-box is hidden, click the resource tab on the right pane of you Visual C++ IDE> Expand the Dialog tree control item>Double-click IDD_Nameofyouproject_DIALOG.

Or

Method 2:

1. Click on the tools menu>Customize>Click the toolbars tab.

2. Check Controls from the toolbars list box>Click the close button.

ISAPLHA and ISDIGIT functions in Visual FoxPro 9

ISALPHA function is one of the powerful functions in Visual FoxPro 9 that can be used to test if the inputted data is a string or character. By default, ISALPHA has a false value and returns a true value when the Expression is a string data. It is very helpful in filtering illegal inputs:

Syntax:
ISALPHA(Expression)

Where;
1. Expression can be a variable, a text, or a control. ISAPLHA can be entered in any capitalization.

Examples:
ISALPHA(“John”)
ISALPHA(strname)
ISALPHA(Thisform.NameTextbox.Value)

To see ISALPHA in action, follow these steps:

1. Click Start>All Programs>Microsoft Visual FoxPro 9.0.
2. Click File>New>Form>New File.
3. Design your interface as follows:



4. Double-click the control named OkButton then enter the following codes:



5.Press F5 to test our sample application.

Another useful input validation function in Visual FoxPro 9.0 is the ISDIGIT function. It works like ISNUMERIC function in PHP wherein it allows you to test whether the input is a numeric data. Just like the ISALPHA function, the default value of is numeric function is false and it returns true whenever the contents of the expression is a numeric value.

Syntax:
IDIGIT (Expression)

Where;
1. Expression can be a variable, a number, or a control. ISDIGIT can be entered in any capitalization.

Examples:
ISDIGIT (“John”)
ISDIGIT (intage)
ISDIGIT (Thisform.AgeTextbox.Value)

The following example demonstrates the capability of ISDIGIT function:

1. Click Start>All Programs>Microsoft Visual FoxPro 9.0.
2. Click File>New>Form>New File.
3. Design your interface as follows:



4. Double-click the OkButton then enter the following:



5. Press F5 to test our sample application.

Those are the two powerful input validation functions in Visual FoxPro 9. Hope you learn something from it. Till next time.

Changing the header text of a grid control in Visual FoxPro 9

By default, grid control gets its header text from the fieldname caption of a record value displayed in a grid column. To change the grid control header text, follow these steps:

1. Click Start > All Programs > Visual FoxPro 9.

2. Click File>New>Table>New File> Type the table name. For the sake of example, use tblNames as a filename>Click Save. Alternatively, you can type CREA tblNames in the command window. Enter the following fieldname captions and data type:



3. Then Click the Ok Button.

4. Press CTRL + F2 to view the command window. Type APPE then press enter. The APPE or APPEND commands pops-up the append window which enables you to add new records.

5. Add the following records:



6. Click the close button [x] to save the inputted records.

7. Create a new form by clicking File>New>Form>New File. Alternatively, type CREA form in the command window then press enter.

8. Click View> Form Control Toolbar(twice) to activate the toolbox window then click and drag a Grid control from the toolbox to your form.

9. Right-click the Grid control on your form>Select builder. A dialog box containing the following options should then appear:



10. Click the [>>] button. This transfers the fieldnames in the Available fields list box to the selected fields list box.

11. Click the layout tab. The following should then appear:



12. Click the grid control’s column header then enter your desired caption in the caption textbox.




13. Click the Ok button to apply the changes then press CTRL + E to run your form. Alternatively, you can click the run [!] icon.