|
-
Jun 29th, 2004, 03:43 AM
#1
Thread Starter
New Member
list box returns empty string instead of "0.00"
hello all.
I have a listbox contains a culomn of numbers (column 3).
When the list box contains any number the command
total = ctl.Column(3, varItm)
works fine !
But .
When the list box contains 0.00 or simple 0 , the
return value is ""
i get "data type conversion error"
i need to get a total of the column and 0 is a valid
data for me .
it makes me alittle crazy i hope you can explain !
i don't wand to use
if ctl.Column(3, varItm) = "" then
couse it rotten programming.
-
Jun 29th, 2004, 05:08 AM
#2
Addicted Member
Couldn't reproduce your problem (using XL97), but not sure where your listbox is. Bear in mind that list boxes only contain text, so we sometimes need to convert (eg. to format numbers)
Try adding this to your code, which in my case converts "" to 0 :-
Dim total As Integer
This is a good way to get Excel to do conversions without additional code.
Regards
BrianB
-------------------------------
-
Jun 29th, 2004, 09:22 AM
#3
Thread Starter
New Member
Originally posted by BrianB
Couldn't reproduce your problem (using XL97), but not sure where your listbox is. Bear in mind that list boxes only contain text, so we sometimes need to convert (eg. to format numbers)
Try adding this to your code, which in my case converts "" to 0 :-
Dim total As Integer
This is a good way to get Excel to do conversions without additional code.
**************************************************
my total is "double"
so basically its the same as integer .
but i checked it also and no can do !!
it doesn't format me to integer is say type mismatch.
so i used if bla bla ="" then total = 0 whice is
not so nice but work !
tnx for your replay !
-
Jun 29th, 2004, 09:27 AM
#4
You can use the Val function to always return a number (it will return 0 if there is no number in the expression):
VB Code:
total = Val(ctl.Column(3, varItm))
Or if you want to convert to a specific data type (Integer/Double/etc) you can use one of the other conversion functions provided:
VB Code:
total = CInt(ctl.Column(3, varItm))
total = CDbl(ctl.Column(3, varItm))
total = CLng(ctl.Column(3, varItm))
...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|