Tuesday, June 4, 2013

Microsoft Visual C++ Tutorial - Beginners

Microsoft Visual C++ Tutorial 

This tutorial is meant to be a startup tool for student unfamiliar with Microsoft Visual C++.  It's purpose is to be a basic introduction to creating files and using the debugger, additional information on the more in depth features of the Visual C++ program can be found in the help files.

Getting Started

The first thing to do when beginning to use Visual C++ is to create a workspace.  Go to the file menu and click on New.

This will bring up the following window.  If it is not already there click on the Workspace tab

Type in a name for your workspace and click OK.  I usually make one workspace for each class and then keep each assignment as a project in that workspace, but you can use just one workspace if you want to.
Next, you need to create a new project.  For this, you also want to go to the New menu, but this time click on the Projects tab.

Unless you are creating a program which will use graphics, you will probably want to create a Win32 Console Application.  Give the project a name and click "Add to current workspace" if it is not already selected.  Then click OK.  After that a window will come up asking what kind of Console Application you want.  Make sure "empty workspace" is selected and then click Finish.  Click OK in the next window and you have created a new project.  The project and its files will appear in the workspace window (the one in the upper left corner).  For example, I created a project called demo in my workspace and now the screen looks like this:

Creating Files

Next, we will write some code for the new project.  First, we will create a header file for a new class called Complex.  Bring up the File menu and click on New.  Then click on the tab that says files if it is not already selected.  Chose C/C++ Header File and then type the name Complex into the name field.  Also, make sure that "add to project" is checked.

Now, copy the following lines into the text filed of the screen.
class Complex
{
private:
double real;
double imaginary;
public:
Complex();
Complex(double,double);
double getReal();
double getImaginary();
void setReal(double);
void setImaginary(double);
};
The screen should look like this.  Save the file either by bring up the file menu and clicking on save, or clicking the icon of a disk right below the Edit menu.

Now create a new C++ source file and copy the following into the text box.  When you cut and paste from this page the alignment of the lines will not be correct, but this will not affect the programs functionality.
#include "Complex.h"

Complex::Complex()
{
real=0;
imaginary=0;
}

Complex::Complex(double r, double i)
{
real=r;
imaginary=i;
}

double Complex::getImaginary()
{
return imaginary;
}

double Complex::getReal()
{
return real;
}

void Complex::setReal(double r)
{
real=r;
}

void Complex::setImaginary(int i)
{
imaginary=i;
}
Save this new file.  Bring up the build menu and click on compile.

As you can see there is an error.  Errors that occur during the compiling of code are the first type of errors that you can fix with this program.  This one is relatively simple.  Double click on the error description and you will be taken to where the error is.

Replace the highlighted "int" with "double" and try to compile again.  This time it should work.
Now, create a new C++ source file and call it main.  Then type, rather than just copying, the following lines
#include <iostream.h>
#include "Complex.h"

int main()
{
Complex a,b;
a.setReal(25);

Notice that when you type a. a list of the functions and variables of the complex class will drop down.  This is a very handy feature.
(If this list doesn't appear then go to the Tools menu, click on Options.  Under the Editor tab there are boxes which will turn on and off the auto-complete features.)
Now write the rest of these lines.
a.setImaginary(2.5);
cout << "a = " << a.getReal() << " + " << a.getImaginary() << "i" << endl;
return 0;
}
Save this file and then go to the build menu and select build.  This will compile the necessary files and link them together into an executable file.  (Note: if you ever want to exclude one of the files in the project from the build, right click on the file in the workspace window, and select settings.  This will bring up the project settings window, click on the general tab and then select "Exclude file from build")

Debugger

Now that we have an executable file, we can explore one of the most useful features, the debugger.  First, run the program normally by selecting execute from the build menu.  A window should pop up that looks like this.

Press any key to make that window disappear.  Now, make sure main.cpp is in the text window and right click next to a.setReal(25).  From this menu select Insert/Remove Breakpoint.

There should now be a red dot next to this line.  This sets a spot where the program execution should pause while debugging.  Go to the build menu, go under start debug and click on go.  This should bring up the console window and also change the main window into debugging mode.  The screen should now look something like this.

There are two new windows for the debugger.  The window on the bottom left will show variables that are associated with the current statement.  The window on the bottom right contains variables that you want to keep and eye on.  Go up to the text window and right click on b.  Click on QuickWatch and select AddWatch.  This variable will now always be accessible in the bottom right window.

Now, we will begin stepping through the program.  First, select Step Over (either from the Debug menu, from the icon below the menu bar or F10)  This will move to the next line regardless of whether there was a function in the line it was on.  If you click on the + next to a in the bottom left window, you will see that the value of real has changed to 25.

Now, rather than using Step Over, select Step Into for the next line.  This will take you to the function body of the setImaginary function.  You will see the value of i in the lower left window, and if you step to the next line imaginary will also show up.

Leave this function by selecting Step Out.
Finish the program execution either by selecting Go or Stop Debugging from the Debug menu.
This concludes the Visual C++ tutorial.

Sunday, June 2, 2013

The errno, perror() and strerror()

As such C programming does not provide direct support for error handling but being a system programming language, it provides you access at lower level in the form of return values. Most of the C or even Unix function calls return -1 or NULL in case of any error and sets an error code errno is set which is global variable and indicates an error occurred during any function call. You can find various error codes defined in <error.h> header file.
So a C programmer can check the returned values and can take appropriate action depending on the return value. As a good practice, developer should set errno to 0 at the time of initialization of the program. A value of 0 indicates that there is no error in the program.

The errno, perror() and strerror()

The C programming language provides perror() and strerror() functions which can be used to display the text message associated with errno.
  • The perror() function displays the string you pass to it, followed by a colon, a space, and then the textual representation of the current errno value.
  • The strerror() function, which returns a pointer to the textual representation of the current errno value.
Let's try to simulate an error condition and try to open a file which does not exist. Here I'm using both the functions to show the usage, but you can use one or more ways of printing your errors. Second important point to note is that you should use stderr file stream to output all the errors.
#include <stdio.h>
#include <errno.h>
#include <string.h>

extern int errno ;

int main ()
{
   FILE * pf;
   int errnum;
   pf = fopen ("unexist.txt", "rb");
   if (pf == NULL)
   {
      errnum = errno;
      fprintf(stderr, "Value of errno: %d\n", errno);
      perror("Error printed by perror");
      fprintf(stderr, "Error opening file: %s\n", strerror( errnum ));
   }
   else
   {
      fclose (pf);
   }
   return 0;
}
When the above code is compiled and executed, it produces the following result:
Value of errno: 2
Error printed by perror: No such file or directory
Error opening file: No such file or directory

Divide by zero errors

It is a common problem that at the time of dividing any number, programmers do not check if a divisor is zero and finally it creates a runtime error.
The code below fixes this by checking if the divisor is zero before dividing:
#include <stdio.h>
#include <stdlib.h>

main()
{
   int dividend = 20;
   int divisor = 0;
   int quotient;
 
   if( divisor == 0){
      fprintf(stderr, "Division by zero! Exiting...\n");
      exit(-1);
   }
   quotient = dividend / divisor;
   fprintf(stderr, "Value of quotient : %d\n", quotient );

   exit(0);
}
When the above code is compiled and executed, it produces the following result:
Division by zero! Exiting...

Program Exit Status

It is a common practice to exit with a value of EXIT_SUCCESS in case of programming is coming out after a successful operation. Here EXIT_SUCCESS is a macro and it is defined as 0.
If you have an error condition in your program and you are coming out then you should exit with a status EXIT_FAILURE which is defined as -1. So let's write above program as follows:
#include <stdio.h>
#include <stdlib.h>

main()
{
   int dividend = 20;
   int divisor = 5;
   int quotient;
 
   if( divisor == 0){
      fprintf(stderr, "Division by zero! Exiting...\n");
      exit(EXIT_FAILURE);
   }
   quotient = dividend / divisor;
   fprintf(stderr, "Value of quotient : %d\n", quotient );

   exit(EXIT_SUCCESS);
}
When the above code is compiled and executed, it produces the following result:
Value of quotient : 4

Defining a Union in visual basic.net

A union is a special data type available in C that enables you to store different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multi-purpose.

Defining a Union

To define a union, you must use the union statement in very similar was as you did while defining structure. The union statement defines a new data type, with more than one member for your program. The format of the union statement is as follows:
union [union tag]
{
   member definition;
   member definition;
   ...
   member definition;
} [one or more union variables];  
The union tag is optional and each member definition is a normal variable definition, such as int i; or float f; or any other valid variable definition. At the end of the union's definition, before the final semicolon, you can specify one or more union variables but it is optional. Here is the way you would define a union type named Data which has the three members i, f, and str:
union Data
{
   int i;
   float f;
   char  str[20];
} data;  
Now a variable of Data type can store an integer, a floating-point number, or a string of characters. This means that a single variable ie. same memory location can be used to store multiple types of data. You can use any built-in or user defined data types inside a union based on your requirement.
The memory occupied by a union will be large enough to hold the largest member of the union. For example, in above example Data type will occupy 20 bytes of memory space because this is the maximum space which can be occupied by character string. Following is the example which will display total memory size occupied by the above union:
#include <stdio.h>
#include <string.h>
 
union Data
{
   int i;
   float f;
   char  str[20];
};
 
int main( )
{
   union Data data;        

   printf( "Memory size occupied by data : %d\n", sizeof(data));

   return 0;
}
When the above code is compiled and executed, it produces following result:
Memory size occupied by data : 20

Accessing Union Members

To access any member of a union, we use the member access operator (.). The member access operator is coded as a period between the union variable name and the union member that we wish to access. You would use union keyword to define variables of union type. Following is the example to explain usage of union:
#include <stdio.h>
#include <string.h>
 
union Data
{
   int i;
   float f;
   char  str[20];
};
 
int main( )
{
   union Data data;        

   data.i = 10;
   data.f = 220.5;
   strcpy( data.str, "C Programming");

   printf( "data.i : %d\n", data.i);
   printf( "data.f : %f\n", data.f);
   printf( "data.str : %s\n", data.str);

   return 0;
}
When the above code is compiled and executed, it produces following result:
data.i : 1917853763
data.f : 4122360580327794860452759994368.000000
data.str : C Programming
Here we can see that values of i and f members of union got corrupted because final value assigned to the variable has occupied the memory location and this is the reason that the value if str member is getting printed very well. Now let's look into the same example once again where we will use one variable at a time which is the main purpose of having union:
#include <stdio.h>
#include <string.h>
 
union Data
{
   int i;
   float f;
   char  str[20];
};
 
int main( )
{
   union Data data;        

   data.i = 10;
   printf( "data.i : %d\n", data.i);
   
   data.f = 220.5;
   printf( "data.f : %f\n", data.f);
   
   strcpy( data.str, "C Programming");
   printf( "data.str : %s\n", data.str);

   return 0;
}
When the above code is compiled and executed, it produces following result:
data.i : 10
data.f : 220.500000
data.str : C Programming
Here all the members are getting printed very well because one member is being used at a time

Saturday, June 1, 2013

Checkbox Tutorial VB.NET

The Checkbox Code
This lessons follows on from the previous page
If you click on any one of your Checkboxes and examine its Properties in the Property box, you'll notice that it has a CheckState Property. Click the down arrow to see the options this CheckState has.
The CheckState property
As you can see, you are given three options: Unchecked, Checked, Indeterminate.
If a checkbox has been selected, the value for the CheckState property will be 1; if it hasn't been selected, the value is zero. (The value for the Indeterminate option is also zero, but we won't be using this.)
We're only going to test for 0 or 1, Checked or Unchecked. You can do the testing with a simple If Statement. Like this:
If CheckBox1.CheckState = 1 Then
MsgBox("Checked")
End If
After you type the equal sign, though, VB will give you a drop down box of the values you can choose from. So the above code is the same as this:
If CheckBox1.CheckState = CheckState.Checked Then
MsgBox("Checked")
End If
Whichever you choose, the Statement will be True if the checkbox is ticked and False if it isn't.
Add a Button to your Form and put that code behind it (either of the two, or test both). When you've finished typing the code, run your programme. Put a tick inside Checkbox1, and click your button. You should get a Message Box popping up.
Amend your code to this:
If CheckBox1.CheckState = CheckState.Checked Then
MsgBox("Checked")
Else
MsgBox("Not Checked")
End If
An alternative to Else is ElseIf. It works like this:
If CheckBox1. CheckState = 1 Then
MsgBox "Checked"
ElseIf Checkbox1. CheckState = 0 Then
MsgBox "Unchecked"
End If
When using the ElseIf clause, you need to put what you are testing for on the same line, just after ElseIf. You put the word Then right at the end of the line. You can have as many ElseIf clauses as you want. In other words, it's exactly the same as the first "If" line only with the word "Else" in front "If".


Add 4 more If Statements to check for the values in your other Checkboxes :
Checkbox2.CheckState, Checkbox3.CheckState, etc.
We're now going to get rid of the Message Boxes inside the If Statements. So either comment out all your MsgBox lines, or delete them altogether.
Instead, we'll build up a String Variable. So add a String Variable to the code for your button, and call it message.
The message variable needs to go inside the If Statement. If the user has checked a Box (If its CheckState property is 1), then we build the message. We need to remember what is inside the message variable, so we can just use this:
message = message & Checkbox1.Text & vbNewLine
That way, every time an option is Checked, Visual Basic will keep what is in the variable called message and add to it whatever the text is for the Checkbox.
So add that line to your If Statements. Something like this
If Checkbox1.CheckState = 1 Then
message = message & Checkbox1.Text & vbNewLine
End If
If Checkbox2.CheckState = 1 Then
message = message & Checkbox2.Text & vbNewLine
End If
And at the end of your If Statements, on a new line, add this:
MsgBox "You have chosen " & vbNewLine & message
Here, we're building a text message for out Message Box. We're saying our Message Box is to contain the text "You have chosen " And a New Line And whatever is inside the variable called message.
When you've finished, Run your Programme to test it out. Put a tick inside all of your Checkboxes. When you click your button all your Soap Operas should appear in the Message Box. Check and Uncheck some options, and click the button again. Only those items that are selected should appear in your Checkbox.
So, we can test to see which Check Boxes a user has ticked, and we can keep a record of those choices for ourselves.
What we can also do is count how many Check Boxes were ticked. We can then use a Select Case Statement to display a suitable message.
Keeping a count is straightforward. First we set up an integer variable called counter, and set it's value to zero.
Dim counter As Integer = 0
Then we can just keep adding one to whatever is in this counter variable. In other words, every time a Checkbox has a value of 1 (is ticked), we can add one to our counter (increment our variable).
We can add this straight into our If Statement, on a new line after the message code.
counter = counter + 1
So your code would be this:
If Checkbox1.CheckState = 1 Then
message = message & Checkbox1.Text & vbNewLine
counter = counter + 1
End If
To test that your counter is working, you can add a second message box to the end of the code, just below your first message box:
MsgBox("Counter = " & counter)
Or adapt your first message box:
MsgBox("You have chosen " & counter & " soaps")
Now that we have a way to count how many Checkboxes are ticked, we can add a Select Case Statement.

Exercise I

Add a Select Case Statement to the end of your code to test whatever is inside the variable called counter.
Remember what the format is for a Select Case? It's this:
Select Case VariableName
Case 0
MsgBox "You obviously don't watch soaps!"
End Select

Fix: Create Cross Thread on Backgroundworker [SOLVED]


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Control.CheckForIllegalCrossThreadCalls = False
    End Sub
End Class

Friday, May 31, 2013

Sell Annuity Payment

An annuity is an asset that offers a definite cycle of payments in the future in exchange for an immediate sum of money. An annuity maybe purchased to facilitate an immediate or deferred payout and could be of a fixed or variable investment type. An annuity may be self-purchased, a gift or even an inheritance. An annuity can be considered a safe source of income, especially after retirement.
However there are times when one needs to have real money in hand to meet expenses rather than documented and sealed bonds. One needs to have control over ones complete monetary resources to meet continuously varying requirements. Selling some or all of ones annuity payments provides flexibility to instantaneously use ones money according to personal needs.
Certain businesses buy annuities from investors in need of physical money. This process is known as selling annuity payments. When an investor decides to trade annuity, the buyer offers a bargained lump-sum imbursement based on the complete present assessment of an annuity contract. The buyer may also offer a portion of the future annuity payments, depending on how much annuity one decides to sell.
While customary annuity payments may be the right choice for the original proprietor, they might not suit the person receiving them as a gift or inheritance. Selling some or all of ones annuity payments gives one the opportunity to use the money to its full potential. Trading annuity may also involve buying another annuity in exchange, which is more suitable to a buyer's needs. If one owns a fixed annuity, there is a prospect for one to sell some or all of the annuity payments. As such, if annuity contract is over a period of twenty years, one can sell a fraction of the annuity payments from the 20-year component, while still preserving the assured lifetime proceeds.
Most plans for selling annuity payments are customized, which enables the people involved to determine how much is to be paid on an individual basis. There are many variables involved. These include fiscal rating of the insurance company making the payments, the volume of ones deal and how far into the future the costs expand. These factors collectively help establish the amount one will receive. When selling annuity payments, financial experts should be consulted, as it can be a complex process.
Sell Annuity [http://www.WetPluto.com/Sell-Annuity.html] provides detailed information on Sell Annuity, Sell Annuity Payment, Sell Annuity Settlement, Sell Health Annuity and more. Sell

Article Source: http://EzineArticles.com/251462

Tuesday, May 28, 2013

Mesothelioma law firm , Sell annuity payment , Asbestos lawyersMesothelioma law firm ,Sell annuity payment ,Asbestos lawyers 105.84 Structured annuity settlement 100.8 Annuity settlements 100.72 Car donate 88.26 Virtual data rooms 83.18 Automobile accident attorney 76.57 Auto accident attorney 75.64 Car accident lawyers 75.17 Data recovery raid 73.22 Motor insurance quotes 68.61 Personal injury lawyer 66.53 Car insurance quotes 61.03 Asbestos lung cancer 60.96 Injury lawyers 60.79 Personal injury law firm ,Online criminal justice degree ,Car insurance companies 58.66 Business voip solutions 51.9

Chicago Mesothelioma Lawyers Connelly & Vogelzang | Top Mesothelioma Asbestos Attorneys | Mesothelioma Law Firm

Connelly & Vogelzang LLC is a Chicago, Illinois based mesothelioma and asbestos law firm dedicated to representing victims of mesothelioma. If you or a loved one has been diagnosed with mesothelioma, you are most likely overwhelmed dealing with medical issues. Although taking legal action may not be the family’s top priority, it should not be ignored. The sole focus of Asbestos Attorneys Connelly & Vogelzang LLC is representing individuals and families of individuals who have been exposed to asbestos, resulting in cancer. The victims of mesothelioma and their families may be entitled to compensation because many companies failed to warn workers about the dangers of their asbestos-containing products.
Why Top Chicago Mesothelioma Law Firm Connelly & Vogelzang?
Mesothelioma Attorneys & Asbestos Lawyers William Connelly and Nicholas Vogelzang have been working with victims of asbestos related disease and mesothelioma for nearly 20 years. They have represented hundreds of victims from across the United States and understand the grief and anguish caused by mesothelioma. Connelly and Vogelzang LLC is dedicated to the representation of those who have been put into an extremely difficult position and are also helping individuals and families navigate the often confusing world of litigation and mesothelioma related health services.

Mesothelioma law firm 179.01
Sell annuity payment 107.46
Asbestos lawyers 105.84
Structured annuity settlement 100.8
Annuity settlements 100.72
Car donate 88.26
Virtual data rooms 83.18
Automobile accident attorney 76.57
Auto accident attorney 75.64
Car accident lawyers 75.17
Data recovery raid 73.22
Motor insurance quotes 68.61
Personal injury lawyer 66.53
Car insurance quotes 61.03
Asbestos lung cancer 60.96
Injury lawyers 60.79
Personal injury law firm 60.56
Online criminal justice degree 60.4
Car insurance companies 58.66
Business voip solutions 51.9