return value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • enrico via DotNetMonster.com

    return value

    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(Text Box11.Text), "P #,###.##")
    TextBox11.Text = dblValue
    Else
    dblValue = Format(Val(Text Box11.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) , "TotalAmoun t")

    --
    Message posted via http://www.dotnetmonster.com

  • Siv

    #2
    Re: return value

    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.t ext) 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(Text Box11.text),"00 0,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.c om" <u41845@uwewrot e in message
    news:81053df613 6d8@uwe...
    >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(Text Box11.Text), "P #,###.##")
    TextBox11.Text = dblValue
    Else
    dblValue = Format(Val(Text Box11.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(Te xtBox11.Text), "TotalAmoun t")
    >
    --
    Message posted via http://www.dotnetmonster.com
    >

    Comment

    • PvdG42

      #3
      Re: return value

      "enrico via DotNetMonster.c om" <u41845@uwewrot e in message
      news:81053df613 6d8@uwe...
      >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(Text Box11.Text), "P #,###.##")
      TextBox11.Text = dblValue
      Else
      dblValue = Format(Val(Text Box11.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(Te xtBox11.Text), "TotalAmoun t")
      >
      --
      Message posted via http://www.dotnetmonster.com
      >
      Turn on both Option Strict and Option Explicit and see what happens.

      Comment

      Working...