Hi,
I want to select a number with 0's after its decimal point.
For example, if I have incoming data as 16.90, 17.00, 17.10, 17.20, 17.30, ......, 17.90, 18.00, 18.10, 18.20, ......., 18.90, 19.00, 19.10, ......... and so on. I want to select only numbers 17.00, 18.00, 19.00, ..... from this series.
How could this be done..?? Any help plz....

Assuming that all your numbers will be in the same format, less than 100 and in a listbox, use the following mid statement...

Dim xCount As Integer, strNuls As String

For xCount = 0 To List1.ListCount - 1
    List1.ListIndex = xCount

    If Mid$(List1.Text, 4, 2) = "00" Then
        strNuls = List1.Text

        Text1.Text = Text1.Text & ", " & strNuls
    End If
Next xCount

If not, then use the right statement...

Dim xCount As Integer, strNuls As String

For xCount = 0 To List1.ListCount - 1
    List1.ListIndex = xCount

    If Right(List1.Text, 2) = "00" Then
        strNuls = List1.Text

        Text1.Text = Text1.Text & ", " & strNuls
    End If
Next xCount

The data is arriving real-time across a Modbus and the numbers could vary from 0 to around 4000 and also the numbers after the decimal point varies from nil to around 10 sometimes, like the data may be 1749.745865248 ..
I think format function alongwith right function would help me solve the issue.. will check with it..
thnx for the "Right" function...

Only a pleasure. Once you get the length of text after the decimal, use the right function then to return the value. You can play around with the following code to count the words after the decimal...

Dim position As Long
Dim words As Long
Dim myText As String

    position = 1
    myText = Text1.Text
    ' massage string:
    ' replace line feeds with spaces
    myText = Replace(myText, Chr(13) & Chr(10), " ")
    ' replace tabs with single spaces
    myText = Replace(myText, Chr(9), " ")
    myText = Trim(myText)
    ' Count the first word
    ' Because the last word isn't delimited by
    ' a space, if the string isn't blank, then it
    ' contains at least one word.
    ' By setting words=1, we won't have to increase the
    ' number of words by 1 when we are done counting.
    If Len(myText) > 0 Then words = 1
    ' while the string contains spaces...
    Do While position > 0
        position = InStr(position, myText, " ")
        ' ... increase word count
        If position > 0 Then
            words = words + 1
            ' and skip additional spaces
            While Mid(myText, position, 1) = " "
                position = position + 1
            Wend
        End If
    Loop
    MsgBox "The TextBox contains " & words & " words"

Just start your counter from the "." in the string length....

got the point..
I used the following method to almost solve the issue... Let me knw if there could be a probable run-time error..

Dim myNum as Single     'Input String
Dim str as Single       'Formatted String

    'Formatting numbers after decimal point
str = Format(myNum, "#.##########")     
If Right(str,10) = 0 then               
        'Starting from right of the formatted string
        'if all the digits are 0s then i get the desired number
    Msgbox "Got the number"
Endif

thanx..

The code looks fine, did not test it as yet. Let me know if any errors occured.

tested.. working fine till now.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.