Results 1 to 16 of 16

Thread: why the two number after the decimal point are always converted to two zeros

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    why the two number after the decimal point are always converted to two zeros

    Gentleman:

    Does anyone knows why the two number after the decimal point are always converted to two zeros with the code below?

    Example:

    If the real value was 175.53

    I only get 175.00

    Why is this?



    Code:
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    
            Dim MyRegEx As New Regex("=\s+(?<MyPat>\d+)")
            Dim s As String = txtDataView.Text
            Dim Mc As MatchCollection = MyRegEx.Matches(s)
            Dim M As Match
            Dim i As Integer
            If Mc.Count > 0 Then
                i = 0
                For Each M In Mc
                    i += 1
                    PutInTextBox(Me, "TextBox" & CStr(i), M.Groups("MyPat").Value)
                Next
            End If
    
        End Sub
    
    
    
        Private Sub PutInTextBox(ByVal ContainerCtrl As Control, ByVal TBName As String, ByVal msg As String)
            Dim ctl As Control
            For Each ctl In ContainerCtrl.Controls
                If TypeOf ctl Is TextBox And ctl.Name = TBName Then
                    ctl.Text = msg
                    Exit For
                Else
                    PutInTextBox(ctl, TBName, msg)
                End If
            Next
    
        End Sub

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Can you point out where do you get that number in your code ??

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376
    Pirate:

    Thank you for your reply.

    On the form there are 75 textboxes named Textbox 1 to Textbox 75.

    The sub "PutInTextBox" is responsible for putting the values in the file txtDataView.Text into these textboxes .

    Any idea why the numbers after the decimal point are converted to Zeros?

    Thanks.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Hmm , can't you use something like this . Before you show the output .
    VB Code:
    1. Convert.ToDecimal(yourdecimal)

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    The problem seems to be with the RegEx can you please help me fix it?

    Pirate:


    The problem seems to be with the RegEx can you please help me fix it?

    Thanks

    Code:
    Dim MyRegEx As New Regex("=\s+(?<MyPat>\d+)")

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I'll do my best to help but can you create little demo of what you are doing ? Just two or three textboxes with the necessary functions !

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    Here is the small demo that shows the RegEx.

    Pirate:

    Here is the small demo that shows the RegEx.

    Thanks
    Attached Files Attached Files

  8. #8
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    This seems to do it:

    Dim MyRegEx As New Regex("=\s+(?<MyPat>[0-9]*[\.]*[0-9]*)")

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Exactly .

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376
    ggprogram & Pirate:

    Thank you very much for the help. That RegEx really worked just fine!!!!

    Great job.

    Thanks a lot


    Andy

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Smile Well... Thanks goes to ggprogram who did it !

    ggprogram , I know this pattern is sort of encrypted string expression but the question is " How can you really figure it out ?" . Meaning , Are there any rules to structure these patterns ?

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    Do you know of any program that will help me develop RegEx or Regular Expressions bes

    ggprogram or anyone else.

    Do you know of any program that will help me develop RegEx or Regular Expressions besides "Expresso" ?


    Thanks

    Andy

  13. #13
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    Balena's Visual Basic .Net book has a chapter that includes a chart that summarizes the entire Regular Expression language (it spans 5 pages of the book).

    Using the chart,

    [0-9] any digit
    * zero or more times

    [\.] an escaped dot means look for dot
    * zero or more times

    [0-9]* any digit zero or more times

    In this case the [\]* was the key because some numbers had a decimal and some did not.

    I don't know if that answers the question, but it represents the way I thought it through.

  14. #14
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Thank you ggprogram .

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376
    ggprogram:

    On these same line of thoughts what the characters will be to constrain the RegEx to only one single character.

    This RegEx ("=\s+(?<MyPat>[0-9]*[\+.]*[0-9]*)")
    , the one you created, will always work as long as the string in question does not have two of this = =

    Example

    The RegEx above will find this
    = 345.33

    and also this (not wanted)
    = = 345.33

    and also this (not wanted)
    ============345.33

    How do you go about it to limit the RegEx in a way that it will ignore the two unwanted conditions above?

    Thanks

    Andy

  16. #16
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    Now you're getting tough!

    OK, I did a fair amount of trial and error and came up with this OR approach:

    Dim MyRegEx As New Regex("={2,}|=\s+(?<MyPat>[^=][0-9]*[\+.]*[0-9]*)")

    The first part looks for 2 or more ='s, if it does NOT find them, it moves on to the other part.

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