tutiworks

i have made the interface for a calculator but whenever i press a number button it replaces what was previously on the display textbox. What do i do to make the whole sum or equation appear on the display textbox before i press the = sign and where exactly do i put the code for execution I am not used to this .net kind of programming enviroment but i am good in programming in vb 6.0 setting. Please help me.


Re: Visual Basic Express Edition still on calculator

Deviation

It sounds like you aren't appending the text, but rather replacing it. Can you post a bit of your code so we can see what you are doing




Re: Visual Basic Express Edition still on calculator

js06

The key to this one is to add the text with the new text

Text + Text

or

Text & Text






Re: Visual Basic Express Edition still on calculator

Deviation

js06 wrote:

The key to this one is to add the text with the new text

Text + Text

or

Text & Text

Textbox1.Text += StrToAppend

But let's see some code so we can help you out. Chances are you're attempting to do a calculator similar to the one used in Gnome where it shows the entire equation until you press =.






Re: Visual Basic Express Edition still on calculator

Solitaire

You should be using the concatenation operator (&) rather than the addition (+) symbol:

Code Block

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim newstring As String, num As Integer

TextBox1.Text = "5"

num = 9

newstring = num.ToString

TextBox1.Text &= newstring

End Sub

The textbox should now display: 59






Re: Visual Basic Express Edition still on calculator

Deviation

Yeah I was still stuck on my integers from this morning... Why create the extra variable
Code Block

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim num As Integer
TextBox1.Text = "5"
num = 9
TextBox1.Text &= num.ToString
End Sub






Re: Visual Basic Express Edition still on calculator

js06

I was thinking this could be a little easier than that

Button1 click

me.textbox1.text = me.textbox1.text & "1"

end sub

Then parse the combined number text when you are ready to make your calculation

otherwise you need a variable for each button number and a variable to hold the combined number

After all this you have 10 variables that are not needed. (1 for each button)






Re: Visual Basic Express Edition still on calculator

Deviation

Well until we hear from the OP on what he/she is trying to accomplish, we have no idea on what to solve.




Re: Visual Basic Express Edition still on calculator

Deviation

Code Block
me.textbox1.text = me.textbox1.text & "1"

Except that you have no way to know which sets of numbers to perform the operation on or which operation. If you want to add 10 + 5 * 2, it would look like 1052.

It would have to be something like

Code Block

Me.TextBox1.Text = Me.TextBox1.Text & strOperator & strNewNumber

Which would give you 10+5*2

That way you would know what operation to perform at which point and what the numbers actually are.






Re: Visual Basic Express Edition still on calculator


Re: Visual Basic Express Edition still on calculator

js06

I understand what you are trying to say

There are several ways to do this one

However it is done, the text in the display box can just be for viewing and your numbers and operators can be handled with variables to do the calculation.

I was suggesting entering a single combined number to parse it from the textbox after you hit an operator key

then you can enter the next number

Example

type in 13

hit the + sign

Mark the operator as +

parse 13 then clear for the next number to be added

etc...

The reason i was suggesting this at all was that this is probably a homework assignment that many new posters have been asking about here in the last week or so. I don't think they are trying to do anything too complex with it. Just what a basic simple calculator does.

And either way about my post before this one, if you were to use that concept for each button it would show the expression in the display box correctly. You would then store your numbers and operator flags in the variables. You don't necessarily have to use the variables to create your display.

Example

Start blank

button1 click

text = text & "1"

1 is shown in the display

button2 click

text = text & "2"

12 is shown in the display

button+ click

12+ is shown in the display

All the variables can be handled along with this as everything is input.

So i agree with you i just think you were expecting it to work a certain way or you misunderstood what i was saying.

Which i understand because i only gave a small bit




Re: Visual Basic Express Edition still on calculator

Deviation

So i agree with you i just think you were expecting it to work a certain way or you misunderstood what i was saying.

Which i understand because i only gave a small bit

No worries here. I was just giving another way to look at it. I've grown quite used to the Gnome Calculator and just thought I'd share the idea with others who may not delve much into Linux. ..oops I said the L word.