Visual Basic 6 Calculator


Option Explicit Dim intCount As Integer Dim sngOne As Single Dim sngTwo As Single Private Sub cmd0_Click() txtAnswer.Text = txtAnswer.Text & "0" End Sub Private Sub cmd1_Click() txtAnswer.Text = txtAnswer.Text & "1" End Sub Private Sub cmd2_Click() txtAnswer.Text = txtAnswer.Text & "2" End Sub Private Sub cmd3_Click() txtAnswer.Text = txtAnswer.Text & "3" End Sub Private Sub cmd4_Click() txtAnswer.Text = txtAnswer.Text & "4" End Sub Private Sub cmd5_Click() txtAnswer.Text = txtAnswer.Text & "5" End Sub Private Sub cmd6_Click() txtAnswer.Text = txtAnswer.Text & "6" End Sub Private Sub cmd7_Click() txtAnswer.Text = txtAnswer.Text & "7" End Sub Private Sub cmd8_Click() txtAnswer.Text = txtAnswer.Text & "8" End Sub Private Sub cmd9_Click() txtAnswer.Text = txtAnswer.Text & "9" End Sub Private Sub cmdClear_Click() txtAnswer.Text = "" End Sub Private Sub cmdDecimal_Click() txtAnswer.Text = txtAnswer.Text & "." End Sub Private Sub cmdDLeft_Click() sngOne = txtAnswer.Text intCount = 0 txtAnswer.Text = "" intCount = intCount + 5 End Sub Private Sub cmdDRight_Click() sngOne = txtAnswer.Text intCount = 0 txtAnswer.Text = "" intCount = intCount + 4 End Sub Private Sub cmdEqual_Click() sngTwo = txtAnswer.Text If intCount = 1 Then txtAnswer.Text = sngOne + sngTwo End If If intCount = 2 Then txtAnswer.Text = sngOne - sngTwo End If If intCount = 3 Then txtAnswer.Text = sngOne * sngTwo End If If intCount = 4 Then txtAnswer.Text = sngOne \ sngTwo End If If intCount = 5 Then txtAnswer.Text = sngOne / sngTwo End If If intCount = 6 Then txtAnswer.Text = sngOne ^ sngTwo End If If intCount = 7 Then txtAnswer.Text = sngOne ^ (1 / sngTwo) End If If intCount = 8 Then txtAnswer.Text = sngOne Mod sngTwo End If End Sub Private Sub cmdFix_Click() txtAnswer.Text = Fix(Val(txtAnswer.Text)) End Sub Private Sub cmdMinus_Click() sngOne = txtAnswer.Text intCount = 0 txtAnswer.Text = "" intCount = intCount + 2 End Sub Private Sub cmdMOD_Click() sngOne = txtAnswer.Text intCount = 0 txtAnswer.Text = "" intCount = intCount + 8 End Sub Private Sub cmdOnOff_Click() If cmdOnOff.Caption = "Off" Then End End If If cmdOnOff.Caption = "On" Then frmCalculator.BackColor = &H0& txtName.BackColor = &H0& cmdOnOff.Caption = "Off" cmd0.Enabled = True cmd1.Enabled = True cmd2.Enabled = True cmd3.Enabled = True cmd4.Enabled = True cmd5.Enabled = True cmd6.Enabled = True cmd7.Enabled = True cmd8.Enabled = True cmd9.Enabled = True cmdDecimal.Enabled = True cmdClear.Enabled = True cmdEqual.Enabled = True cmdPlus.Enabled = True cmdMinus.Enabled = True cmdTimes.Enabled = True cmdDRight.Enabled = True cmdDLeft.Enabled = True cmdMOD.Enabled = True cmdFix.Enabled = True cmdRoot.Enabled = True cmdPower.Enabled = True End If End Sub Private Sub cmdPlus_Click() sngOne = txtAnswer.Text intCount = 0 txtAnswer.Text = "" intCount = intCount + 1 End Sub Private Sub cmdPower_Click() sngOne = txtAnswer.Text intCount = 0 txtAnswer.Text = "" intCount = intCount + 6 End Sub Private Sub cmdRoot_Click() sngOne = txtAnswer.Text intCount = 0 txtAnswer.Text = "" intCount = intCount + 7 End Sub Private Sub cmdTimes_Click() sngOne = txtAnswer.Text intCount = 0 txtAnswer.Text = "" intCount = intCount + 3 End Sub

That's my code thus far.

My problem now is basically just that I can enter numbers and calculate them, but I can't do longer equations. For example:

1 + 3 = 4

No problem doing that at all.

In our assignment we should be able to do equations like this:

2 * 4 3 ^ 2 = 25

Instead, it would do the last two numbers along with their sign.

So it would end up being 3 ^ 2 = 9.

I don't know how to make it so that it will do the entire equation rather than the last parts of it.

We can not use things like As Double, As Boolean, etc...

So if it can be done using things like As Integer, As Single, or As String please use that method.
This post has been edited by Johann Vanoustren: 31 October 2007 - 03:50 PM
Posted On: Monday 24th of December 2012 01:15:08 AM Total Views:  232
View Complete with Replies

RELATED TOPICS OF Visual Basic PROGRAMMING LANGUAGE




How to use the "non visual" timer?

I remember using code looking like: xTimer = Timer + 1 Do While xTimer > Timer DoEvents Loop To pause the code for 1 second, however I can't find any examples of this code and my computer doesn't have enough RAM for me to open a project where I used this before. Can anyone give me an example of this code so I can use it in my project What I basically need to know is do I have to store the Timer value in a single variable and does the number returned represent minutes, seconds, days or what
VIEWS ON THIS POST

79

Posted on:

Tuesday 16th October 2012
View Replies!

Help : how to fill textbox in flash using visual basic 6

hello all , i just have a small question if i have a page with flash textbox , how can i fill it using visual basic 6
VIEWS ON THIS POST

142

Posted on:

Thursday 18th October 2012
View Replies!

Re: visual basic run time error 5 class

Dear Friend, I'm getting problem in vb class module.I have no idea about class module but i was created class file. When i run my application it showing run time error '5'. me for this problem. In form code: Code: Dim List As SpdListing If KeyCode = vbKeyF2 Then DoEvents Set List = New SpdListing --> Here i am getting error List.Class_Initialize With List .SpdShowList Me, SpdStyle, SpdStyle.ARow, SpdStyle.ActiveCol, "StyleId", "Style", "Style", Qry = "" End With End If Class Module Code: Public Type SpdList Frm As Object spd As Object ARow As Integer ACol As Integer Field1 As String Field2 As String TblObj As String Qry As String End Type Public Function SpdShowList(CurrentFrm As Object, Currentspd As Object, ARow As Integer, ACol As Integer, Field1 As String, Field2 As String, TblObj As String, Qry As String) As String Dim List As SpdList With List .Frm = CurrentFrm .spd = Currentspd .ARow = ARow .ACol = ACol .Field1 = Field1 .Field2 = Field2 .TblObj = TblObj .Qry = Qry Strsql = "Select " & .Field1 & VBA.chr(13) & "," & VBA.chr(13) & .Field2 & VBA.chr(13) & " From " + .TblObj If .Qry "" Then Strsql = Strsql & VBA.chr(13) & " Where " & VBA.chr(13) & .Field1 & VBA.chr(13) & " In(" & .Qry & ")" Else Strsql = Strsql & VBA.chr(13) & " Where " & .Field1 & "='" & FrmSpdListing.SpdFilter.Text & "%'" End If End With Set SpdRs = New ADODB.Recordset SpdRs.Open Strsql, SpdCn, adOpenStatic, adLockReadOnly Set FrmSpdListing.SpdGrid.DataSource = SpdRs 'FrmSpdListing.SpdGrid.Columns(0).Width = 0 FrmSpdListing.Show End Function
VIEWS ON THIS POST

133

Posted on:

Thursday 18th October 2012
View Replies!

Printing in visual basic 6 question

I want to print some text in visual basic. But im from Poland and in my language we use characters like ź, ć, ż, ś, ł, ... so if i want to print words with that letters in this place are other characters... How can i change it for printing in my language
VIEWS ON THIS POST

211

Posted on:

Thursday 18th October 2012
View Replies!

Problems working in team with visual basic 6.

Hallo, I am new of this Thread, and i am a computer developper. Now, I'm using Visual Basic 6. I'm working on a project with another developper. When one of us open the project all classes are loaded, and if one of us change a class and save it, but the other load class and save it, he overwrite the changes made by the first developper. And if I open a class I see the class updated when I open the project and I don't see changes made by other developper. Struments like Visual Source Safe are not sure to use. They use a database to store the various version of classes, but they don't see then changes made by another when I open a class, and if I save they don't notify me that another user has changed the class. Is there the way to work on the same project with the absolute sure that noone overwrite the changes made by another Like Office When, in Office, I open a document, if another user is using it Office notify me and open the document in read only mode, and I cannot save it to overwrite changes of other users. For example Borland Delphi when a class is modified other users are advised and delphi ask to reload the class. I
VIEWS ON THIS POST

136

Posted on:

Tuesday 23rd October 2012
View Replies!

Things I need help with...Database Looping doesn't seems to work

\Private Sub tmupds_Timer() Dim j As Long Dim leng As String Dim lret As Long Dim phoneline As Long Dat.MoveFirst While Not Dat.EOF ino = Dat.Fields(0) iname = Dat.Fields(1) If Dat.Fields(2) = 0 Then txtS.Text = txtS.Text + vbCrLf + ...
VIEWS ON THIS POST

217

Posted on:

Tuesday 20th November 2012
View Replies!

How do you load a password protected webpage?

I mean this is simple: Inet1.OpenURL(URLName, DataType) But it only works on webpages that do not require authentication...
VIEWS ON THIS POST

141

Posted on:

Tuesday 20th November 2012
View Replies!

Run-time error 3706

I have a program developed in Visual Basic 6 that uses an Access database. The program has almost 500 users now and someone called today asking about a run-time error I have never seen before. It is: "Run-Time Error 3706: ...
VIEWS ON THIS POST

282

Posted on:

Monday 26th November 2012
View Replies!

Is there an equivalent for % (from SQL) in VB .NET?

Is there an equivalent for % (from SQL) in VB .NET. Ex: If Txt.Text = " " & % & "!" then ...
VIEWS ON THIS POST

173

Posted on:

Thursday 29th November 2012
View Replies!

Add item to Combox and save

Not sure if this is possible. Searched by could not find how to do. I am using Combo boxes in my project that gets populated from an Access Database. No problem with add from database and save the selected item back to database. If there is another option not in the drop down list the user can type it in and save the result in the database. My question is can this also be added to the combo box table in the database so that next time it will automatically appear in the combo box drop down list
VIEWS ON THIS POST

82

Posted on:

Friday 30th November 2012
View Replies!

Report Generation

Hi , Please help me generating a data report. I want to generate a report the basic purpose of the report is to find the records of those people who didn't pay the installments. The user should be able to run the report at the end of the month and the report should display the record of those people who didn't pay their installments.
VIEWS ON THIS POST

103

Posted on:

Friday 30th November 2012
View Replies!

printing texts from form using vB.6

i want to print the contents of many things such as labels and texts and combo please help me as soon as you could
VIEWS ON THIS POST

92

Posted on:

Friday 30th November 2012
View Replies!