Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

How to Display 4 digits in textbox control

Last post 05-11-2008 6:25 AM by ashwin_think. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 05-06-2008 6:22 AM

    How to Display 4 digits in textbox control

    Hi,

    I want to display the 4 digit number in textbox control which having some limitations. Actually Textbox control having the limitation to display maximum value 999 (3 digit only) and minimum 000. But it's having a facility or functionality that it can show the no. 1 from the left side of digits as a flag only. Supposed I want to display a value 12.43 then the limitation of 3 digits it cannot show all the number in textbox control. But having facility of flag 1 it will be able to display the value 12.43 in textbox. But if I want to display 23.45 in textbox then it will display only 23.4 as the first digit of the value (23.45) is other than 1. How I can do this in VB.net through programming ? Please help me….

     Thanks.

     
    Regards,

    Ashwin
     

    • Post Points: 10
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 05-06-2008 6:53 AM In reply to

    Re: How to Display 4 digits in textbox control

    for displaying four digit value in the textbox  convert the value into text and display.

     

    like

    text1.text=str("1111111.111111")

    • Post Points: 10
  • 05-06-2008 7:33 AM In reply to

    Re: How to Display 4 digits in textbox control

     I think so you had not understood my problem. Please read my post again. As I'm able to display the values in text but whenever I'm handling the value as string the limitations as per application need it cannot exceed the value more than 3 digits if the first digit of value is other than 1. If the first digit of the value is 1 then the textbox control can able to display it upto 4 digit only.

     

    Thanks. 

    • Post Points: 15
  • 05-06-2008 7:59 AM In reply to

    Re: How to Display 4 digits in textbox control

    but I have chacked it is working fine in vb.net 2.0

    • Post Points: 5
  • 05-06-2008 8:18 AM In reply to

    • Bart_K
    • Not Ranked
    • Joined on 02-12-2008
    • United Kingdom
    • Junior Member
    • Points 195

    Re: How to Display 4 digits in textbox control

    Something like this? 

    Dim number As Decimal = 23.45
    Dim str As String = number.ToString

    If str.Chars(0) = "1" Then

                'if you don't want the flag removed delete the first line
                str = str.Remove(0, 1)
                If str.Length > 5 Then str = str.Remove(5)
            Else
                str = str.Remove(0, 1)
                If str.Length > 4 Then str = str.Remove(4)
            End If

    • Post Points: 10
  • 05-06-2008 1:10 PM In reply to

    Re: How to Display 4 digits in textbox control

     For single case it is fine.. But how I can generate the following output, -

     Input Value             Output Value (Should be)
     

    20.01                        20.0

    19.99                        19.99

    30.25                        30.2

    15.12                        15.12

    156.55                        156.5

    279.6                        279 

    0.001                        0.00

    1.001                        1.001

     

    I've given the Input values in the Input coloumn and expected output should be in Output coloumn. It's good example to self explanatory.

     Thanks for all of you and plz. help me little bit to solve this problem.

     
    Ashwin.
          

    • Post Points: 10
  • 05-06-2008 1:31 PM In reply to

    • Bart_K
    • Not Ranked
    • Joined on 02-12-2008
    • United Kingdom
    • Junior Member
    • Points 195

    Re: How to Display 4 digits in textbox control

    Like I said just remove the

    str = str.Remove(0, 1)

    lines...

    • Post Points: 10
  • 05-07-2008 7:36 AM In reply to

    Re: How to Display 4 digits in textbox control

     Not Understood.... Could u plz explain it in details As I've done your stuff in my application but no luck.

     Thanks.

     

    Ashwin.
     

    • Post Points: 10
  • 05-07-2008 8:39 AM In reply to

    • Bart_K
    • Not Ranked
    • Joined on 02-12-2008
    • United Kingdom
    • Junior Member
    • Points 195

    Re: How to Display 4 digits in textbox control

    Damn, forgot about the decimal point. 

            Dim num As Decimal = 123.456
            Dim str As String = num.ToString
            Dim dot As Byte = 0
            Dim dotindex As Byte = str.IndexOf(".")

            If str.Chars(0) = "1" Then
                If dotindex > 0 And dotindex < 4 Then dot = dot + 1
                If str.Length > 4 Then str = str.Remove(dot + 4)
            Else
                If dotindex > 0 And dotindex < 3 Then dot = dot + 1
                str = str.PadRight(5)
                str = str.Remove(dot + 3)
            End If

     

     
    • Post Points: 10
  • 05-08-2008 10:49 AM In reply to

    Re: How to Display 4 digits in textbox control

    How I can take the input from input box or Textbox without assigning the value to num as decimal directly in programing...

    Could you please explain the same as I tried to num = textbox1.text but I'm getting the 0 value every time.

     Thanks for extra-ordinary help.

     
    Ashwin.
     

    • Post Points: 10
  • 05-08-2008 12:25 PM In reply to

    • williamsg
    • Not Ranked
    • Joined on 10-11-2007
    • United Kingdom
    • Member
    • Points 235

    Re: How to Display 4 digits in textbox control

    Im fairly sure this is what you want: 

            Dim sTemp As String = vbNullString
            Dim sTemp2 As String = vbNullString
            Dim iMaxLen As Integer = 4
            Dim iPos As Integer = 0
            sTemp = TextBox1.Text
            If sTemp <> vbNullString Then
                If sTemp.StartsWith("1") Then
                    iMaxLen = 4
                Else
                    iMaxLen = 3
                End If

                If Len(sTemp) > iMaxLen Then
                    If InStr(sTemp, ".") > 0 And InStr(sTemp, ".") < iMaxLen Then
                        iMaxLen = iMaxLen + 1
                        sTemp = Microsoft.VisualBasic.Left$(sTemp, iMaxLen)
                    ElseIf InStr(sTemp, ".") > iMaxLen Then
                        sTemp2 = Microsoft.VisualBasic.Left$(sTemp, InStr(sTemp, "."))
                        sTemp = Microsoft.VisualBasic.Left$(sTemp2, iMaxLen)
                        For iPos = iMaxLen To Len(sTemp2)
                            sTemp = sTemp & "0"
                        Next
                    ElseIf InStr(sTemp, ".") = iMaxLen Then
                        sTemp = Microsoft.VisualBasic.Left$(sTemp, iMaxLen + 1)
                    End If
                End If

                TextBox1.Text = sTemp
            End If

    I code, it's what I do
    • Post Points: 10
  • 05-11-2008 6:25 AM In reply to

    Re: How to Display 4 digits in textbox control

     Hey williamsg,

     Really impressive code dude. It's resolve the issue where I stuck from last 2 weeks and you had done massive job for me. Really appreciated.

    Thanks a lot.

     
    Best Regards,

    Ashwin.

     

    • Post Points: 5
Page 1 of 1 (12 items)