|
-
Feb 26th, 2011, 01:18 PM
#1
Thread Starter
Member
TextBox Formatting
Example:
Format(781234.57,”0”) 781235
Format(781234.57,”0.0”) 781234.6
Format(781234.576,”0.00”) 781234.58
Format(781234.576,”#,##0.00”) 781,234.58
Format(781234.576,”$#,##0.00”) $781,234.58
Format(0.576,”0%”) 58%
Format(0.5768,”0.00%”) 57.68%
Hi, my name is joe.. and im the junior programming
From the example i given. I just wanna say.. i seems familiar with thats formatting number.
But i having trouble with Textbox that i set on Texboxt_textchanged event. Which i want to set a number when i write it in textbox and automatically transform to a number formatting (example: i write 20000, on my textbox write as 20.000), but on the same time id like to calculate my Textbox1 to my Textbox2)
Code:
Private Sub Textbox1_TextChanged(ByVal sender as .....)
Textbox1.Text = Format(Text_total.Text, "#,#")
Textbox2_total.Text = TextBox1.Text + 2)
End Sub
When i compile the code above.. its generate an error.. that said i cannot transfer string to integer..
ill try to convert back my TextBox1 with Format(TextBox1, "General Number") and calculate it but that not works..
can somebody help?
-
Feb 26th, 2011, 06:00 PM
#2
Re: TextBox Formatting
To do that format you need to pass a valid object, in your case a double. So you need before trying to convert the value cast the Text_total.Text to double.
vb.net Code:
Textbox1.Text = Format(Double.Parse(Text_total.Text), "#,#") 'Assuming that the Text it's a valid double
In the second line you should do the same and in the end call the ToString method.
vb.net Code:
Textbox2_total.Text = (Double.Parse(TextBox1.Text) + 2).ToString()
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Feb 27th, 2011, 12:26 AM
#3
Thread Starter
Member
Re: TextBox Formatting
Code:
Private Sub Text_amount_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text_amount.TextChanged
Text_amount.Text = Format(Double.Parse(Text_amount.Text), "#,#")
Label12.Text = (Double.Parse(Text_amount.Text) + 2).ToString
End Sub
Thanks for helping this.. and its works..
But now i tried to using if command on the textbox. if that textbox null its generate zero number
but when i first complie it, again its generate an error  
"System.StackOverflowException"
Code:
Private Sub Text_amount_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text_amount.TextChanged
If String.IsNullOrEmpty(Text_amount.Text) Then
Text_amount.Text = 0
Else
Text_amount.Text = Format(Double.Parse(Text_amount.Text), "#,#")
Label12.Text = (Double.Parse(Text_amount.Text) + 2).ToString
End If
End Sub
and i need some tips about starting point of the text-cursor on my TextBox.. when i started write on my Text_ammount.Text, its start
5
54
542
5,423
when its reach to formating number. My text-cursor change to left side of the text. thats make me write into:
(my next number was "6")
65.423 it should become 54.236
Can som1 help me? and thanks for Mickey for helping me on my first problem.
-
Feb 27th, 2011, 03:12 PM
#4
Re: TextBox Formatting
You could use a custom NumericUpDown control which in the constructor sets Decimal places to 2, ThousandsSeparator = True. Create a property for how much to increment the Value of the control and provide a property to output the incremented value as a string.
Custom NumericUpDown
Code:
Imports System.ComponentModel
Namespace NumericEditBox
<System.ComponentModel.DesignerCategoryAttribute("Code")> _
Public Class NumericEditBox
Inherits System.Windows.Forms.NumericUpDown
Private mIncrementor As Integer
<Description("How much to increment the final value "), Category("Behavior")> _
Public Property Incrementor() As Integer
Get
Return mIncrementor
End Get
Set(ByVal value As Integer)
mIncrementor = value
End Set
End Property
Public ReadOnly Property StringValue() As String
Get
Return CStr(Me.Value + Incrementor)
End Get
End Property
Public Sub New()
Controls(0).Visible = False
ThousandsSeparator = True
DecimalPlaces = 2
End Sub
End Class
End Namespace
Usage
Code:
Private Sub NumericEditBox1_ValueChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles NumericEditBox1.ValueChanged
TextBox2.Text = NumericEditBox1.StringValue
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|