- Joined
- Jul 29, 2007
- Messages
- 392 (0.06/day)
- Location
- Portugal
System Name | Lil'Lighty |
---|---|
Processor | Intel Core i3 530 @ Stock |
Motherboard | Asus P7P55D |
Cooling | Artic Cooling Freezer Pro Rev.2 |
Memory | Gskill Ripjaw 1600MHz 9-9-9-24 8GB |
Video Card(s) | MSI GeForce GTX650 OC 1GB |
Storage | WD Blue 500GB AAKS |
Display(s) | ASUS 20' |
Case | Aerocool Aeroengine II // Two 120mm Blue Fans |
Audio Device(s) | Creative SoundBlaster LE // Logitech X-230 |
Power Supply | Corsair VX450W |
Software | Windows 8.1 Pro x64 |
Hey all. I thought that this section needed a little help so there it is.
For someone that wants to start programming in Visual Basic, I have a simple program that I'm going to show you.
I will teach, step-by-step how to build a simple calculator.
So here it goes ok?
First, make sure you have at least Visual Studio 2005 (it's the best I've ever experimented and you will learn fast).
Click the New Project button.
To begin with, you need to create a Visual Basic application with an empty project, like shown on this image.
The name of the project is at your criteria.
Then, when the project is created, you should click with the right mouse button on the bold letters on the Solution Explorer,I mean the name of the project. Then go to Add, Windows Form. Now, it should appear the same window that appears on the image. Then again, the name of the form is at your criteria.
Then double-click on the form you have just created and your window should look like this. If the toolbox doesn't appear, then go to View,Toolbox or press Ctrl+Alt+X.
Then in the toolbox, look for Textbox. Click on it and draw two textboxes on the form. Again, the size is at your will.
I will not change the name of the objects to keep things simple. Then look for label and draw one.
Now click on the label you've just created. In the block Properties just below Solution Explorer, change AutoSize to False and clear the Label1 text in Text. Then it should be like on the image, except for position and size of objects.
Now go to the toolbox and look for Button. Draw the first one, go to properties and in the Text value write Add.
Draw the second one and in Text value write Subtract, draw the third and in Text value write Multiply. Finally, draw the fourth and in Texh value write Divide. Oh I forgot, after doing all that, click on the label that you've introduced on the form and look in Properties for BorderStyle. Change it to Fixed3D.
Now that we have it all, we can now start to write the source code.
Now, double-click on the Add button. It should appear a window like this. This window is the coder part of the program.
It's where you write the source code of the program, more precisly, the Add button you've created on the form. Warning: Do not confuse Button1_Click with the Add button. Button1 is the name of the object to the program, Add is just a string to know what the button does.
Then put this on the code:
This will add the value on Textbox1 with Textbox2 and show it on Label1. Now click on the design tab and double click on the subtract button and put the same code, you only need to change the signal to minus. Do the same procedure to Multiply and change it to the right signal. Now go click on the Divide button.
This is the one that needs a different code, because it's more suspectible to errors like dividing 0 by 0.
Put this code:
This will end the errors on dividing zero by zero or dividing without anything on the textboxes.
The code should be like this (depending how are your tastes at formatting text).
Ignore the warnings, the program still works perfectly. If you have followed all the steps, now try out the program.
Click on the green play and try it
.
I know that this may look too easy, but I wanted to show to people that programming is not so boring. I hope you like it and if someone has corrections do do, please step foward.
For someone that wants to start programming in Visual Basic, I have a simple program that I'm going to show you.
I will teach, step-by-step how to build a simple calculator.
So here it goes ok?
First, make sure you have at least Visual Studio 2005 (it's the best I've ever experimented and you will learn fast).

Click the New Project button.
To begin with, you need to create a Visual Basic application with an empty project, like shown on this image.
The name of the project is at your criteria.

Then, when the project is created, you should click with the right mouse button on the bold letters on the Solution Explorer,I mean the name of the project. Then go to Add, Windows Form. Now, it should appear the same window that appears on the image. Then again, the name of the form is at your criteria.

Then double-click on the form you have just created and your window should look like this. If the toolbox doesn't appear, then go to View,Toolbox or press Ctrl+Alt+X.

Then in the toolbox, look for Textbox. Click on it and draw two textboxes on the form. Again, the size is at your will.
I will not change the name of the objects to keep things simple. Then look for label and draw one.
Now click on the label you've just created. In the block Properties just below Solution Explorer, change AutoSize to False and clear the Label1 text in Text. Then it should be like on the image, except for position and size of objects.
Now go to the toolbox and look for Button. Draw the first one, go to properties and in the Text value write Add.
Draw the second one and in Text value write Subtract, draw the third and in Text value write Multiply. Finally, draw the fourth and in Texh value write Divide. Oh I forgot, after doing all that, click on the label that you've introduced on the form and look in Properties for BorderStyle. Change it to Fixed3D.
Now that we have it all, we can now start to write the source code.

Now, double-click on the Add button. It should appear a window like this. This window is the coder part of the program.
It's where you write the source code of the program, more precisly, the Add button you've created on the form. Warning: Do not confuse Button1_Click with the Add button. Button1 is the name of the object to the program, Add is just a string to know what the button does.
Then put this on the code:
Code:
Label1.Text = Val(TextBox1) + Val(TextBox2)
This will add the value on Textbox1 with Textbox2 and show it on Label1. Now click on the design tab and double click on the subtract button and put the same code, you only need to change the signal to minus. Do the same procedure to Multiply and change it to the right signal. Now go click on the Divide button.
This is the one that needs a different code, because it's more suspectible to errors like dividing 0 by 0.
Put this code:
Code:
Try
Label1.Text = Val(TextBox1.Text) / Val(TextBox2.Text)
Catch ex As Exception
End Try
This will end the errors on dividing zero by zero or dividing without anything on the textboxes.

The code should be like this (depending how are your tastes at formatting text).
Ignore the warnings, the program still works perfectly. If you have followed all the steps, now try out the program.
Click on the green play and try it

I know that this may look too easy, but I wanted to show to people that programming is not so boring. I hope you like it and if someone has corrections do do, please step foward.
Last edited: