11 Replies - 33536 Views - Last Post: 16 September 2012 - 03:44 PM Rate Topic: -----

#1 quakeworld2007  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 71
  • Joined: 28-September 07

Output to textbox?

Posted 09 October 2007 - 08:34 AM

I am trying to make textbox1 display the output when the buttons: button1, btn1 and button2 are clicked. I got it working in console.writeline but i want to replace it so that it displays in the textbox.

 

Public Class Form
	Inherits System.Windows.Forms.Form

	Dim oOrders As New Order()


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

		oOrders.NumBurgers = CType((txtNumberofBurgers.Text), Integer)
		oOrders.NumFries = CType((txtNumberofFrys.Text), Integer)

		Console.WriteLine(OOrders.inputOrder(OOrders.anNumerBurgers, oOrders.NumFries))
		Console.WriteLine()
	End Sub

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


		oOrders.NumBurgers = CType((txtNumberofBurgers.Text), Integer)
		oOrders.NumFries = CType((txtNumberofFrys.Text), Integer)

		Console.WriteLine("Order Amount: " & FormatCurrency(oOrders.GetorderAmount()))
		Console.WriteLine("Sales Tax: " & FormatCurrency(OOrders.GetsalesTax()))
		Console.WriteLine("Amount Due: " & FormatCurrency(OOrders.GetamountDue()))
		Console.WriteLine()

	End Sub

	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

		oOrders.NumBurgers = CType((txtNumberofBurgers.Text), Integer)
		oOrders.NumFries = CType((txtNumberofFrys.Text), Integer)
		OOrders.AmntPaid = CType((txtAmountPaid.Text), Double)

		Console.WriteLine("Amount Paid: " & FormatCurrency(OOrders.AmntPaid))
		Console.WriteLine("Change Due: " & FormatCurrency(OOrders.GetchangeDue()))

		Console.WriteLine()
	End Sub

	Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

		TextBox1.Text = ("Order Amount: " & FormatCurrency(OOrders.GetorderAmount()))
		TextBox1.Text = ("Sales Tax: " & FormatCurrency(OOrders.GetsalesTax()))
		TextBox1.Text = ("Amount Due: " & FormatCurrency(OOrders.GetamountDue()))
		TextBox1.Text = ("Amount Paid: " & FormatCurrency(OOrders.AmntPaid))
		TextBox1.Text = ("Change Due: " & FormatCurrency(OOrders.GetchangeDue()))
	End Sub
End Class



This post has been edited by quakeworld2007: 09 October 2007 - 10:28 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Output to textbox?

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Output to textbox?

Posted 09 October 2007 - 10:51 AM

All you need to do is assign the value to the Text property of the textbox.

TextBox1.Text = "Amount Paid: " & FormatCurrency(OOrders.AmntPaid)



To add multiple lines of data to the textbox you will need to add like this (notice the += signs to add to whatever data is already in the textbox:
TextBox1.Text = "Amount Paid: " & FormatCurrency(OOrders.AmntPaid)
TextBox1.Text += "Change Due: " & FormatCurrency(OOrders.GetchangeDue())

Was This Post Helpful? 1
  • +
  • -

#3 quakeworld2007  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 71
  • Joined: 28-September 07

Re: Output to textbox?

Posted 09 October 2007 - 11:11 AM

I still cant get it to display in the textbox with that code. Do i have to change any of the properties of the textbox too?
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Output to textbox?

Posted 09 October 2007 - 12:24 PM

It appears you have a spelling error, you have this TextBox1.Text = ("Order Amount: " & FormatCurrency(OOrders.GetorderAmount())) yet you instantiate your class like Dim oOrders As New Order()

Are those zero's in your code or just both capital O's?
Was This Post Helpful? 0
  • +
  • -

#5 aceofspades686  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 334
  • Joined: 08-October 07

Re: Output to textbox?

Posted 09 October 2007 - 12:28 PM

I'm going to take a crack at this, see if I can help out any.

Okay, assuming that you want whatever value OOrders.inputOrder() returns to display in textbox1, this would be the code to use it.

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

		oOrders.NumBurgers = CType((txtNumberofBurgers.Text), Integer)
		oOrders.NumFries = CType((txtNumberofFrys.Text), Integer)

		textbox1.text = OOrders.inputOrder(OOrders.anNumerBurgers, oOrders.NumFries)
	End Sub



Concerning the other two, it depends on how you want it displayed within the textbox. I'm going to assume you're using a multiline textbox and want a crlf at the end of each.

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


		oOrders.NumBurgers = CType((txtNumberofBurgers.Text), Integer)
		oOrders.NumFries = CType((txtNumberofFrys.Text), Integer)

		textbox1.text = "Order Amount: " & FormatCurrency(oOrders.GetorderAmount())) & ControlChars.CrLf
		textbox1.text &= "Sales Tax: " & FormatCurrency(OOrders.GetsalesTax())) & ControlChars.CrLf
		textbox1.text &= "Amount Due: " & FormatCurrency(OOrders.GetamountDue())) & ControlChars.CrLf
	End Sub



And then use the same technique for the Button2_Click sub.

Hopefully this was of some help.

View Postjayman9, on 9 Oct, 2007 - 10:51 AM, said:

...To add multiple lines of data to the textbox you will need to add like this (notice the += signs to add to whatever data is already in the textbox:
TextBox1.Text = "Amount Paid: " & FormatCurrency(OOrders.AmntPaid)
TextBox1.Text += "Change Due: " & FormatCurrency(OOrders.GetchangeDue())


In this case, wouldn't you use &= instead of += since you're concatenating a string and not adding values? Just wondering because I don't recall seeing it done that way, but I'm still learning so I may be mistaken.
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Output to textbox?

Posted 09 October 2007 - 12:50 PM

View Postaceofspades686, on 9 Oct, 2007 - 12:28 PM, said:

In this case, wouldn't you use &= instead of += since you're concatenating a string and not adding values? Just wondering because I don't recall seeing it done that way, but I'm still learning so I may be mistaken.


Either symbol & or + will work for strings. You cannot add strings together, they will always being concatenation. So these operators do exactly the same thing, as far as strings are concerned.
Was This Post Helpful? 0
  • +
  • -

#7 aceofspades686  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 334
  • Joined: 08-October 07

Re: Output to textbox?

Posted 09 October 2007 - 12:54 PM

View Postjayman9, on 9 Oct, 2007 - 12:50 PM, said:

View Postaceofspades686, on 9 Oct, 2007 - 12:28 PM, said:

In this case, wouldn't you use &= instead of += since you're concatenating a string and not adding values? Just wondering because I don't recall seeing it done that way, but I'm still learning so I may be mistaken.


Either symbol & or + will work for strings. You cannot add strings together, they will always being concatenation. So these operators do exactly the same thing, as far as strings are concerned.


Alright, makes sense, I just hadn't seen it used that way.
Was This Post Helpful? 0
  • +
  • -

#8 quakeworld2007  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 71
  • Joined: 28-September 07

Re: Output to textbox?

Posted 09 October 2007 - 01:53 PM

Thanks I got it working :) :) :)
Was This Post Helpful? 0
  • +
  • -

#9 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Output to textbox?

Posted 09 October 2007 - 02:04 PM

View Postaceofspades686, on 9 Oct, 2007 - 12:54 PM, said:

Alright, makes sense, I just hadn't seen it used that way.

You will see it used extensively in Java and C# and a myriad of other languages. As far as I know, VB is the only one that can also use the ampersand(&) operator for string concatenation. (someone correct me if I am wrong)
Was This Post Helpful? 0
  • +
  • -

#10 Guest_John*


Reputation:

Re: Output to textbox?

Posted 24 June 2010 - 08:00 AM

View Postquakeworld2007, on 09 October 2007 - 10:11 AM, said:

I still cant get it to display in the textbox with that code. Do i have to change any of the properties of the textbox too?

I believe that you would have better luck using a label box instead of a text box,(yes, you will have to change some properties, as well as the user could change the information in the text box) that way the use won't be able to change the information.
Was This Post Helpful? 0

#11 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Output to textbox?

Posted 25 June 2010 - 05:52 AM

Jayman, the only reason I prefer using & instead of plus with VB.Net is the settings that you are allowed to turn on or off can change the result (ie, option explicit and option strict) Take the following example

Option Strict Off
Option Explicit Off
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      x = 12
      y = "10"
      z = x + y
      MessageBox.Show(z) ' Results in 22
      z = x & y
      MessageBox.Show(z) ' Results in 1210
    End Sub
End Class


So in the case of the first even though a string is involved, the + performs a mathematical operation instead of appending the two even though one of those is a string holding a numeric value. An error occurs however if the string contains any non-numeric character for example y = ":Age" would not give you "12:Age" instead it would error. This is why you will see people express changing + for concatenation in vb with &

This post has been edited by CharlieMay: 25 June 2010 - 05:55 AM

Was This Post Helpful? 0
  • +
  • -

#12 metalmaniac816  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-September 12

Re: Output to textbox?

Posted 16 September 2012 - 03:44 PM

View PostJayman, on 09 October 2007 - 10:51 AM, said:

All you need to do is assign the value to the Text property of the textbox.

TextBox1.Text = "Amount Paid: " & FormatCurrency(OOrders.AmntPaid)



To add multiple lines of data to the textbox you will need to add like this (notice the += signs to add to whatever data is already in the textbox:
TextBox1.Text = "Amount Paid: " & FormatCurrency(OOrders.AmntPaid)
TextBox1.Text += "Change Due: " & FormatCurrency(OOrders.GetchangeDue())



thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1