Lost Password?

  #1 (permalink)  
Old 01-04-2007, 01:57 AM
AfTriX AfTriX is offline
Programming God
 
Join Date: Jan 2007
Location: Sri Lanka
Posts: 596
Rep Power: 0
AfTriX is on a distinguished road
Default Basic Calculator

ever wanted to create a calculator to do basic math?
well here is your chance!!

follow these simple steps and create your own calculator

first start off by creating a standard .exe application project

and create two text boxes, one Combo box, one command button and one label.

name them like this:
text box 1: txtNumber1
text box 2: txtNumber2
comdo box: cmbOperator
command button: cmdCalculate
label: lblResult

now go into your coding view and start off by adding

Option Explicit
to the code
the option explicit prevent variables and such from being created without proper deceleration and it makes debugging bigger applications much easier and the reason for adding it here is because its best to get used to add it to every project from the start

now we need to add the desired operator\'s to the combo box:
we want the population of the combo box to happen while the application loads and how we do this is simple

write the code

Private Sub Form_Load()

End Sub


into your code
any code we now add between those two lines will be executed doing the load of the form
Note: The Form part of the Form_load is the name of the form

now we add the code to populate the combo
write the code:

cmdOperator.AddItem (\"+\")
cmdOperator.AddItem (\"-\")
cmdOperator.AddItem (\"*\")
cmdOperator.AddItem (\"/\")


between the other lines we added before.

Now we need to add the code to calculate the numbers with the chosen Operator.

add the code:

Private Sub cmdCalculate_Click()

End Sub

below all the code we have written

all code we add between those lines will be executed then the user press the cmdCalculate Button

the code for calculating this is fairly simple and easy to under stand

we want to calculate the two numbers with the chosen operator and we want to display a error message if the user haven\'t chosen anything

we will do this by a if else statement
add the code:

If cmdOperator.Text = \"\" Then

Else

End If


between the last lines we wrote

now we checks if the user haven\'t chosen anything and do a specific code if he haven\'t otherwise it will execute the \"Else\" code

now we want to display a message box and we do this with a \"msgbox\" function:

add the code:

MsgBox (\"You most chose a operator!!\")


right after

If cmdOperator.Text = \"\" Then


this will display a standard message box to the user

now that we have checked if the user has chosen anything we need to add the calculation code:

now after the else line we need to have one way to know what operator the user has chosen

this is done by a select case statement (it can also be done by a if statement but the case statement is much cleaner

now add the code:


Select Case cmbOperator.Text
Case \"+\"

Case \"-\"

Case \"*\"

Case \"/\"

End Select


right after the \"Else\" Line

this will allow us to add code for every operator

now we will take the case \"+\" together and then you can try the other ones by yourself(just to learn) if you don\'t want to do this then just download the attachment for the complete source

we want to display the result in the label (lblResult)
and we do this by using the property .Caption

so now we start building up the line of code

first in the line add

lblResult.Caption
and we want to sett this property to the result of the calculation this is done by a \"=\" operator so add the \"=\" right after the last part of the code now we need to use the \"Val()\" Function to make the application treat the numbers as numbers otherwise they will be treated as text

so the next code is just Val(txtNumber1.Text) [operator here] Val(txtNumber2.Text)

example:

lblResult.Caption = Val(txtNumber1.Text) + Val(txtNumber2.Text)


now try to code the other 3 lines by yourself and if you don t understand it just take a look at the attachment

Attached File

hope this sums it up!!
happy coding!!

Ref:
Photoshop Tutorials and Flash Tutorials
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 01-04-2007, 02:03 AM
clookid's Avatar   
clookid clookid is offline
Programmer
 
Join Date: Jan 2007
Posts: 148
Rep Power: 6
clookid is on a distinguished road
Default

So this obviously wasn't written by you... I don't think that tutorialized allow you to copy their tutorials... I think you my have just broken the law, buddy!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-04-2007, 02:21 AM
AfTriX AfTriX is offline
Programming God
 
Join Date: Jan 2007
Location: Sri Lanka
Posts: 596
Rep Power: 0
AfTriX is on a distinguished road
Default

Of course its not written by myself, and there are no restrictions to copy the coding from them. Since all the members are sharing their knowledge among them.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 08:53 AM
shane3221 shane3221 is offline
Newbie
 
Join Date: Feb 2008
Posts: 1
Rep Power: 0
shane3221 is on a distinguished road
Default

I have a web browser that i made. Is there any way I can get a history bar on it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic Calculator Hydromethod Visual Basic Programming 0 08-25-2007 10:23 AM
HTML Basic Formatting clookid Tutorials, Classes and Code 14 03-06-2007 03:10 PM
My friend made some cool BASIC videos elfshadow14 The Lounge 5 01-09-2007 10:20 PM
Flex, bison multifunction calculator annatsos C and C++ 1 01-04-2007 06:00 AM
Parallel Port Programming Using Visual Basic kevintcp85 Visual Basic Programming 12 12-06-2006 12:09 PM


All times are GMT -5. The time now is 06:05 PM.

Contest Stats

John ........ 87.50000
dargueta ........ 75.00000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads