Asking for better solution

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lotus18
    Contributor
    • Nov 2007
    • 865

    Asking for better solution

    Hello World

    I have a program and an access as back end. On my Subject table, I set Units (Field name) to Number as datatype with the following properties (Field Size=Integer, Format=Fixed, Decimal Places=1)

    The results on the database were fine

    Units
    5.0
    4.0
    6.0
    2.0
    ...

    But when I retrieve them on vb6.0, the results was not the same as on access.

    Units
    5
    4
    2
    2
    ...

    I tried to change the units to double but still the same.

    Here's my sample codes
    [code=vb]
    rs.Open "Select * From Subject", cn, 1, 1
    list.ListItems. Clear
    While Not rs.EOF
    On Error Resume Next
    With list.ListItems. Add(, , rs!SubjectID, img1, img2)
    .SubItems(1) = rs!Subject
    .SubItems(2) = rs!Units
    '...... and so on...
    End With
    rs.MoveNext
    Wend
    [/code]

    So what I did was:
    [code=vb]
    rs.Open "Select * From Subject", cn, 1, 1
    list.ListItems. Clear
    While Not rs.EOF
    On Error Resume Next
    With list.ListItems. Add(, , rs!SubjectID, img1, img2)
    .SubItems(1) = rs!Subject
    .SubItems(2) = rs!Units & ".0"
    '...... and so on...
    End With
    rs.MoveNext
    Wend
    [/code]

    I think that my second code is not really bad, I know there's really solution for these. Can anyone help me to find it how?

    I tried Cdbl but nothing happens : (
    Last edited by lotus18; Nov 28 '07, 10:48 AM. Reason: Change title
  • CyberSoftHari
    Recognized Expert Contributor
    • Sep 2007
    • 488

    #2
    Do not use on error resume next until the method bugs and errors fixed. Use
    [CODE=vb]FormatNumber(un it,2)[/CODE]

    Comment

    • lotus18
      Contributor
      • Nov 2007
      • 865

      #3
      Originally posted by CyberSoftHari
      Do not use on error resume next until the method bugs and errors fixed. Use
      [CODE=vb]FormatNumber(un it,2)[/CODE]
      I'm using On Error Resume Next because some of my fields are empty and they are not required to be filled upped. : )

      BTW, thanks for your reply : )

      Rey Sean

      Comment

      • 9815402440
        New Member
        • Oct 2007
        • 180

        #4
        Hi.
        Use the following query to retrieve numbers in the desired format.

        select format(intNumbe r0,"#0.00") as intNumber1 from table

        Regards
        manpreet singh dhillon hoshiarpur
        Last edited by Killer42; Nov 29 '07, 12:49 AM.

        Comment

        Working...