13 Replies - 1167 Views - Last Post: 16 July 2008 - 07:55 PM Rate Topic: -----

#1 theBEC88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 22-June 08

Lots O' Calculator-Related Questions, the Novel

Post icon  Posted 15 July 2008 - 12:16 AM

In case anyone out there is in the mood to answer some Kindergarten-type questions, I'll post my assignment. Be aware, I'm not asking anyone to code it for me. I just want you to see what I need to do:

Develop a calculator that allows addition, subtraction, multiplication, division, tangent, square, sine, cosine, and absolute value.

Create numeric buttons for numbers input.
Create . and +/- buttons for real numbers and negative numbers input.
Make the Calculate button the Accept button.
Create a Clear button to clear the result text box and reset all controls.
Create an Exit button.
Use labels to identify the input and output controls.

Okay, this is what I've already done:
Designed a calculator form with these buttons: 0-9 numeric keys, a C, a CE, =, abs, tan, sin, cos, sqrt,+, -, +/-, *, . , and /.
I have a drop down menu with File, Edit and Help (blank right now, of course, but I have made shortcut keys).
And, I've given all the components cute names like Btn1, Btn9, BtnClear, etc.

I have:
Dim UserInput1 As Double
Dim UserInput2 As Double
Dim Solution As Double
Dim Check As Boolean

He wants us to use Select Case for Error trapping, using Select.Err.Number (especially Divide by Zero error). I'm supposed to use Imports.System.Math for the Sqrt, etc... and I still don't understand why the normal operators (plus minus etc) aren't in .Math. That just doesn't make sense to me. If I can go (sine)...I wanna be able to go (add). Ya know?

I looked at the Tutorial question from the guy who needed "help" with his "homework"... but I'm so tired that it just didn't compute (pun intended, this time). Couldn't relate it to my variables. Too worn out.

We are to use the mouse only for inputing data - no keyboard. Is that it? I think so, more or less.

Okay...I'm flagging...can't... go.... on....must...sleep..... :zzz:

Seriously, I have to crash before I DO crash. I will come back after work tomorrow (I mean today) and ask my questions, if ya'll don't mind. I promise I won't ask your favorite color, or the velocity of a laden swallow.

Thanks!
BEC

Is This A Good Question/Topic? 0
  • +

Replies To: Lots O' Calculator-Related Questions, the Novel

#2 josiahb  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 2
  • View blog
  • Posts: 378
  • Joined: 05-March 08

Re: Lots O' Calculator-Related Questions, the Novel

Posted 15 July 2008 - 12:54 AM

Yah know I actually did this as an assignment in college but thanks to my woeful memory I can remember very little of the process... Except it was painful.

addition and subtraction are done just with the normal operator for e.g.

solution = userinput1 + userinput2

Was This Post Helpful? 0
  • +
  • -

#3 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: Lots O' Calculator-Related Questions, the Novel

Posted 15 July 2008 - 06:03 PM

Have you seen this yet?

http://www.dreaminco...wtopic32951.htm
Was This Post Helpful? 0
  • +
  • -

#4 theBEC88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 22-June 08

Re: Lots O' Calculator-Related Questions, the Novel

Posted 15 July 2008 - 07:23 PM

View Postjosiahb, on 15 Jul, 2008 - 12:54 AM, said:

Yah know I actually did this as an assignment in college but thanks to my woeful memory I can remember very little of the process... Except it was painful.

addition and subtraction are done just with the normal operator for e.g.

solution = userinput1 + userinput2


Okay, here's a question (although I probably should put them all in one post...what the hey):

Warning:
This may sound completely ignorant...

By using only two variables, I can only work with two, right? 1 + 1, 2/2, etc. I understand that sqrt and tan, etc are unary; but what if I want to add and add and add and multiply...ad nauseum (yes, pun intended)? No can do?
Was This Post Helpful? 0
  • +
  • -

#5 theBEC88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 22-June 08

Re: Lots O' Calculator-Related Questions, the Novel

Posted 15 July 2008 - 07:42 PM

View PostOliveOyl3471, on 15 Jul, 2008 - 06:03 PM, said:




Yep. The functionality was different than my assignment. I thought about trying to use parts of it; but as you saw last night, I was not in the best frame of mind for deep thought.

What I'm doing right now, is trying to put all my thoughts on one page and see if I can make sense of it enough to ask semi-intelligent questions. I'm gonna go look at it for a little while, then come back with (I pray!) some insightful questions that will, once and for all, get me through this thing.

^_^
Was This Post Helpful? 0
  • +
  • -

#6 theBEC88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 22-June 08

Re: Lots O' Calculator-Related Questions, the Novel

Posted 15 July 2008 - 08:20 PM

Okay,
Here's what I've got so far...see if it makes any sense. It looked logical and I didn't get "squiggly lined".
 Select Case TextBox1.Text
			Case CStr(0)
				Results = UserInput1 + UserInput2
			Case CStr(1)
				Results = UserInput1 - UserInput2
			Case CStr(2)
				Results = UserInput1 * UserInput2
			Case CStr(3)
				Results = UserInput1 / UserInput2
			Case CStr(4)
				Results = Math.Sqrt(UserInput1)
			Case CStr(5)
				Results = Math.Abs(UserInput1)
			Case CStr(6)
				Results = Math.Cos(UserInput1)
			Case CStr(7)
				Results = Math.Sin(UserInput1)
			Case CStr(8)
				Results = Math.Tan(UserInput1)
		End Select



** Edit ** :code:
Was This Post Helpful? 0
  • +
  • -

#7 theBEC88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 22-June 08

Re: Lots O' Calculator-Related Questions, the Novel

Posted 15 July 2008 - 08:47 PM

Here's the whole thing...thought it might be helpful to see everything as it sits.


So far, on Debugging, my 1 button gives me a 0 when I press it, and my Clear...won't.
Imports System.Math
Public Class Form1
	'Declare variables globally
	Dim UserInput1 As Double
	Dim UserInput2 As Double
	Dim Results As Double


	Private Sub BtnEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEquals.Click
		Select Case TextBox1.Text
			Case CStr(0)
				Results = UserInput1 + UserInput2
			Case CStr(1)
				Results = UserInput1 - UserInput2
			Case CStr(2)
				Results = UserInput1 * UserInput2
			Case CStr(3)
				Results = UserInput1 / UserInput2
			Case CStr(4)
				Results = Math.Sqrt(UserInput1)
			Case CStr(5)
				Results = Math.Abs(UserInput1)
			Case CStr(6)
				Results = Math.Cos(UserInput1)
			Case CStr(7)
				Results = Math.Sin(UserInput1)
			Case CStr(8)
				Results = Math.Tan(UserInput1)
		End Select
	End Sub

	Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
		Close()
	End Sub

	Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
		TextBox1.Text = CStr(Results)
	End Sub

	Private Sub BtnSin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSin.Click
		 
	End Sub

	Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
		TextBox1.Clear()

	End Sub

	Private Sub Btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn1.Click
		TextBox1.AppendText("1")
	End Sub
End Class



On the Select Case, the CStr( ) is what VB wanted to do to it.

Thanks for any help/answers/guidance/peptalk...

** Edit ** :code:
Was This Post Helpful? 0
  • +
  • -

#8 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: Lots O' Calculator-Related Questions, the Novel

Posted 15 July 2008 - 09:55 PM

View PosttheBEC88, on 15 Jul, 2008 - 10:47 PM, said:

So far, on Debugging, my 1 button gives me a 0 when I press it, and my Clear...won't.

TextBox1.Clear()


It's been a while since I did any VB programming, and since we have a new computer I don't have a VB compiler on this one. So I can't check it. I did look up some of my old homework projects and I think I can at least answer one of your questions. Maybe two.

The zero instead of one thing might be because programming languages are zero based, meaning they start counting at zero instead of one. I don't know for sure if that's what the problem is, though.

Instead of
TextBox1.Clear()

try this:
TextBox1.ResetText()

This post has been edited by OliveOyl3471: 16 July 2008 - 01:07 AM

Was This Post Helpful? 0
  • +
  • -

#9 theBEC88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 22-June 08

Re: Lots O' Calculator-Related Questions, the Novel

Posted 15 July 2008 - 10:01 PM

Thanks for the reminder, Olive! I realized I posted the code wrong -after I posted the code.

Thanks also for the suggestion...I'll give it a go.
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5363
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Lots O' Calculator-Related Questions, the Novel

Posted 15 July 2008 - 10:01 PM

View PosttheBEC88, on 15 Jul, 2008 - 10:47 PM, said:

So far, on Debugging, my 1 button gives me a 0 when I press it, and my Clear...won't.

TextBox1.Clear()


What does TextBox1.Text = "" do?

Sorry, I'm horrible with VB & dot Net.
Was This Post Helpful? 0
  • +
  • -

#11 theBEC88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 22-June 08

Re: Lots O' Calculator-Related Questions, the Novel

Posted 15 July 2008 - 10:18 PM

View Postno2pencil, on 15 Jul, 2008 - 10:01 PM, said:

View PosttheBEC88, on 15 Jul, 2008 - 10:47 PM, said:

So far, on Debugging, my 1 button gives me a 0 when I press it, and my Clear...won't.

TextBox1.Clear()


What does TextBox1.Text = "" do?

Sorry, I'm horrible with VB & dot Net.



Hey!
It would work; but he doesn't accept Null. I already made that mistake on an earlier project.
Thanks for playing, though... ;)

My most pressing issue at this juncture (Thanks Bush Sr), is making the number keys work.

And am I ok on the Select Case stuff?

Enquiring minds wanna know...
Was This Post Helpful? 0
  • +
  • -

#12 theBEC88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 22-June 08

Re: Lots O' Calculator-Related Questions, the Novel

Posted 16 July 2008 - 12:00 AM

   TextBox1.ResetText()


My Clear, does.


  TextBox1.Text = ("1")


This is an example of how I'm doing the number keys - which works, if in a cumbersome way. What they won't do, is stay in the textbox. When a new button is pressed, the previous number disappears instead of moving over. Also, the numbers are showing on the wrong side of the textbox.

I have an inkling that something like this might work, if I knew how to put it:
 While Btn1 <>(* + - / =) ...



Please, how can I write it, so that it looks like a calculator??? I have the example program that we're supposed to base it on, and it works just like a real calculator, for the most part.

I'm just about to have to let this go - since this is the very last moment that he'll accept the work - and I really hate to do that. I only need 150 points out of this, and the previous assignment, to squeak a C and thus avoid having to take out an extra loan.

Plus, it's the principle of the thing.

Please, someone, help???
Was This Post Helpful? 0
  • +
  • -

#13 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: Lots O' Calculator-Related Questions, the Novel

Posted 16 July 2008 - 01:31 AM

It's probably too late now, but for the principle of it...

Again, I can't test it, but to add new stuff to the textbox without erasing the old stuff in the textbox, try using += instead of just =. I don't know if it works in VB but it works in C# (like that helps you).

like so:
  TextBox1.Text += ("1")

This post has been edited by OliveOyl3471: 16 July 2008 - 01:33 AM

Was This Post Helpful? 0
  • +
  • -

#14 theBEC88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 22-June 08

Re: Lots O' Calculator-Related Questions, the Novel

Posted 16 July 2008 - 07:55 PM

View PostOliveOyl3471, on 16 Jul, 2008 - 01:31 AM, said:

It's probably too late now, but for the principle of it...

Again, I can't test it, but to add new stuff to the textbox without erasing the old stuff in the textbox, try using += instead of just =. I don't know if it works in VB but it works in C# (like that helps you).

like so:
  TextBox1.Text += ("1")



Hey, I'm not on the PC right now; but I will definitely try it when I get a chance. It's the principle of the thing. BTW, that does sound vaguely familiar, so I'd bet that's what I needed to do.
I"m still waiting on my final grade. I was telling B2C that I will have at least one more Programming class before I'm done, so maybe I can get some more Future advice...
Thanks Olive!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1