Results 1 to 5 of 5

Thread: Textbox formating problem.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Textbox formating problem.

    hi

    I have control array of Textbox. Text1(0),Text1(1),Text1(2),Text1(3),Text1(4). The textbox are formatted as Number(with comma after 1000).
    Below is the code:

    Sub Text1_Change(Index as Integer)
    Select case Index

    case 0 Text1(2)=val(Text1(0))+val(Text1(1))

    case 3 Text1(4)=Val(Text1(2))+Val(Text1(3))

    End Select

    Everything works fine, except one problem. When its add the value ot Text1(2) and Text1(3), such as 123,456+123,456, it display value in Text1(4) as 246 only, while it should display 246,912. But when i remove the textbox format, it displays 246912. I want the format as well as the value to be displayed as 246,912.

    Any alternative way to do this.

    Thanks

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    When you enter 123,456 as intput and use val function, it treats it as string and not number, so thats why it only takes the first valid number 123.

    You should use the format function

    e.g
    VB Code:
    1. Select Case Index
    2.     Case 0
    3.         Text1(2).Text = Format(Val(Text1(0).Text) + Val(Text1(1).Text), "#,##0.00")
    4.    
    5.     Case 3
    6.         Text1(4).Text = Format(Val(Text1(2).Text) + Val(Text1(3).Text), "#,##0.00")
    7. End Select

    do not enter , when entering number as input. Put 12345678 instaed of 123,456,78. The format function will output the number with specified format.

    Hope this helps.

    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253
    thanks for quick reply.

    I tried your way Danial, but its not working. I am not putting the number as 123,456, I have formated the textbox.dataformat as number, and when you leave the text box it format the number as 123,456. But it works fine if i remove the text.dataformat as number. I formatted the textbox as for the end user that they can see properly what number they are putting.

    Hope I made my question clear.


    Thanks.

  4. #4
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Hi,
    Sorry i did not get you at the first time. I think i have got it this time !

    Here is one dirty way of doing it!!

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Text1_Change(Index As Integer)
    4.     Dim T(4) As Double
    5.    
    6.     T(0) = Val(Replace(Text1(0).Text, ",", "", , , vbBinaryCompare))
    7.     T(1) = Val(Replace(Text1(1).Text, ",", "", , , vbBinaryCompare))
    8.     T(2) = Val(Replace(Text1(2).Text, ",", "", , , vbBinaryCompare))
    9.     T(3) = Val(Replace(Text1(3).Text, ",", "", , , vbBinaryCompare))
    10.     T(4) = Val(Replace(Text1(4).Text, ",", "", , , vbBinaryCompare))
    11.    
    12.     Select Case Index
    13.         Case 0
    14.             Text1(2).Text = Format(T(0) + T(1), "#,##0.00")
    15.        
    16.         Case 3
    17.             Text1(4).Text = Format(T(2) + T(3), "#,##0.00")
    18.     End Select
    19.  
    20. End Sub
    21.  
    22. Private Sub Text1_LostFocus(Index As Integer)
    23.     Text1(Index).Text = Format(Text1(Index).Text, "#,##0.00")
    24. End Sub

    Is this what you are looking for? Let me know
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    thanks

    hi danial thanks for your reply. i have found the way, i have just remove the textbox data format, as my end user doesn't need that.


    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width