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:
#pragma endregion
6. Declare the following variables below it:
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:
#pragma endregion
int intnum1, intnum2,intans;

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

intnum1=int::Parse(this->FnumTextBox->Text);
intnum2=int::Parse(this->SnumTextBox->Text);
intans=intnum1 * intnum2;
this->OperatorLabel->Text="*";
this->AnsLabel->Text=Convert::ToString(intans);

Your code should now appear just like this:

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

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

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

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

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

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

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

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

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


12.Double-click ExitButton, then type this->Close:
private: System::Void ExitButton_Click(System::Object^  sender, System::EventArgs^  e) {
this->Close();
}
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:

this->DestinationObjectName->Property=Convert::ToString (this-> SourceObjectName->Property);
//or simply
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:

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

private: System::Void OkButton_Click(System::Object^  sender, System::EventArgs^  e) {
this->EnteredLabel->Text= Convert::ToString (this->StringtextBox->Text);
}
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:

private: System::Void ExitButton_Click(System::Object^  sender, System::EventArgs^  e) {
this->Close();
}
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:

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:

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:
//Converts the number inputed by the user into a numeric data
//and assign it to an integer variable named intusernum
int intusernum=int::Parse(this->StringtextBox->Text);
//Converts the numeric data into a string data and display it in a
//control named EnteredLabel
this->EnteredLabel->Text=Convert::ToString(intusernum);

Your code should now look like this:
private: System::Void OkButton_Click(System::Object^  sender, System::EventArgs^  e) {
int intusernum=int::Parse(this->StringtextBox->Text);
this->EnteredLabel->Text=Convert::ToString(intusernum);   
} 
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:
private: System::Void ExitButton_Click(System::Object^  sender, System::EventArgs^  e) {
this->Close();
}   
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:

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.