return value

  • Thread starter Thread starter enrico via DotNetMonster.com
  • Start date Start date
E

enrico via DotNetMonster.com

i added a currency sign to my number field which is a "double" field on my
database. this is the code:

Private Sub TextBox11_Leave(ByVal sender As Object, ByVal e As System.
EventArgs) Handles TextBox11.Leave
Dim dblValue As String
If TextBox11.Text.Contains(".") = True Then
dblValue = Format(Val(TextBox11.Text), "P #,###.##")
TextBox11.Text = dblValue
Else
dblValue = Format(Val(TextBox11.Text), "P #,###.00")
TextBox11.Text = dblValue
End If
End Sub

it does work but every time that i save it the value that is returned in my
database is 0. my add code is something like this(only a part of the whole
code):

..addValue(Val(TextBox11.Text), "TotalAmount")
 
Enrico,

You are best not to put a currency symbol within your text boxes as the
symbol will make VB think that the contents of the text box is just text, so
when you try and save the value the text box will hold text and something
like val(Textbox11.text) will return zero as the val of a piece of text is
zero.

I would put the currency symbol in the label outside the text box e.g.:

Sales Value: £ [_______________]

Then you could use the format function to just give the number a couple of
decimal places:

dblValue = format(val(TextBox11.text),"000,000,000.00")

That way you would be able to save the number to your database without it
becoiming zero.

I am in the UK so I have used the £ symbol I am not sure what currency you
use and your decimal notation may be different you may use a dot where I use
a comma and vice versa in the format string.

Hope this helps.

Siv
 
enrico via DotNetMonster.com said:
i added a currency sign to my number field which is a "double" field on my
database. this is the code:

Private Sub TextBox11_Leave(ByVal sender As Object, ByVal e As System.
EventArgs) Handles TextBox11.Leave
Dim dblValue As String
If TextBox11.Text.Contains(".") = True Then
dblValue = Format(Val(TextBox11.Text), "P #,###.##")
TextBox11.Text = dblValue
Else
dblValue = Format(Val(TextBox11.Text), "P #,###.00")
TextBox11.Text = dblValue
End If
End Sub

it does work but every time that i save it the value that is returned in
my
database is 0. my add code is something like this(only a part of the whole
code):

addValue(Val(TextBox11.Text), "TotalAmount")

Turn on both Option Strict and Option Explicit and see what happens.
 
Back
Top