Results 1 to 4 of 4

Thread: list box returns empty string instead of "0.00"

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Location
    nonA
    Posts
    14

    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.

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    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
    -------------------------------

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Location
    nonA
    Posts
    14
    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 !

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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:
    1. 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:
    1. total = CInt(ctl.Column(3, varItm))
    2. total = CDbl(ctl.Column(3, varItm))
    3. total = CLng(ctl.Column(3, varItm))
    4. ...

Posting Permissions

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



Click Here to Expand Forum to Full Width