Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2008
    Posts
    117

    Unanswered: Check this coding

    My check1 recordset contains no1 field with 11/2, 5/3, 4, 6
    So this coding converts them to decimal by dividing 11/2 etc.
    But this is done when the datas are in fraction form but not with others.
    (ie) it converting only 11/2 and 5/3 but not 4 and 6.
    Pls help me in converting them also.

    Private Sub Command1_Click()

    rs.Open "check1", db, 3, 2
    Do While Not rs.EOF
    Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item(0).Value)
    rs.MoveNext
    Loop
    rs.Close
    For i = 1 To ListView1.ListItems.Count
    Set item1 = ListView1.ListItems(i)
    a = Left([item1], InStr([item1], "/") - 1)
    b = Right([item1], Len([item1]) - InStr([item1], "/"))
    c = IIf([b] = [item1], [item1], ([a] / [b]))
    MsgBox c
    Next

    End Sub

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I'd suggest you sue the split function in place
    I don't understand why you retrieve the data, stuff it into a listbox and then start a for loop to process the data


    Code:
    dim HorribleKludgeWorkAround() as string
    dim DecimalValue as single
    rs.Open "check1", db, 3, 2
    Do While Not rs.EOF
      Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item(0).Value)
      rs.MoveNext
      if not isnull(  HorribleKludgeWorkAround) then
        HorribleKludgeWorkAround=split(rs.Fields.Item(0).Value,"/")
        if ubound(HorribleKludgeWorkAround.count) = 1 then ' we have 2 terms so we must have a fraction. note this cannot handle say 3/32/4
          DecimalValue=csng(HorribleKludgeWorkAround(0)) \ csng(HorribleKludgeWorkAround(1))
        else
          DecimalValue=csng(HorribleKludgeWorkAround(0))
        endif
      else 'its a null value
        'decide what to do with a null value... make it 0?
        DecimalValue=0
      endif
    Loop
    rs.Close
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Nov 2008
    Posts
    117
    Quote Originally Posted by healdem
    I'd suggest you sue the split function in place
    I don't understand why you retrieve the data, stuff it into a listbox and then start a for loop to process the data


    Code:
    dim HorribleKludgeWorkAround() as string
    dim DecimalValue as single
    rs.Open "check1", db, 3, 2
    Do While Not rs.EOF
      Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item(0).Value)
      rs.MoveNext
      if not isnull(  HorribleKludgeWorkAround) then
        HorribleKludgeWorkAround=split(rs.Fields.Item(0).Value,"/")
        if ubound(HorribleKludgeWorkAround.count) = 1 then ' we have 2 terms so we must have a fraction. note this cannot handle say 3/32/4
          DecimalValue=csng(HorribleKludgeWorkAround(0)) \ csng(HorribleKludgeWorkAround(1))
        else
          DecimalValue=csng(HorribleKludgeWorkAround(0))
        endif
      else 'its a null value
        'decide what to do with a null value... make it 0?
        DecimalValue=0
      endif
    Loop
    rs.Close
    Hello sir,
    This coding showing error as compile error:invalid qualifier , in the line which i specified as bold

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so investigate why there is a fault
    my guess wouldbe that the .count is surplus.. remove it
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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