1. Registered User
Join Date
Nov 2008
Posts
117

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

Join Date
Nov 2004
Location
out on a limb
Posts
13,692
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```

3. Registered User
Join Date
Nov 2008
Posts
117
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

Join Date
Nov 2004
Location
out on a limb
Posts
13,692