Results 1 to 10 of 10

Thread: [RESOLVED] Listbox Run Time Error 13

  1. #1

    Thread Starter
    Lively Member Yumby's Avatar
    Join Date
    Feb 2009
    Posts
    120

    Resolved [RESOLVED] Listbox Run Time Error 13

    I have two listboxes. The 1st listbox has the numbers 1 to 10 in it. The 2nd listbox has the numbers 1.00 to 10.00 (increasing by 0.01) in it. And when I calculate these numbers everything is fine. But as soon as I increase the 1st listboxes' numbers to 100,000 (1 to 100,000) and I do a calculation using the number 100,000 I get a run time error 13.

    Questions...

    I shouldn't be able to do a calculation even when the numbers are low (1 to 10) because these numbers are strings and therefore you can't calculate strings, but it does, so the first question is... How is this possible?

    My second question is, how can I calculate the 100,000 number without creating a run time error 13?

    Many thanks.

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: Listbox Run Time Error 13

    Could you post the code you are using to fill the listboxes, and to perform the calculations?

    Are you, by any fat chance, displaying your numbers as "100,000", with the comma included? If so, that might be the cause of the problem. Try to remove the comma and then convert them to numbers and then do the calculations.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3

    Thread Starter
    Lively Member Yumby's Avatar
    Join Date
    Feb 2009
    Posts
    120

    Re: Listbox Run Time Error 13

    In the General Declarations section I have...

    Code:
    Dim secondvalue(100)
    Dim thirdvalue(100)
    To fill the listboxes I do...

    Code:
    For x = 1 To 10
    z = Format(x, "##,##0.00#")
    listsecond.AddItem z
    Next x
    
    For x = 1.0 To 10 Step 0.01
    z = Format(x, "##,##0.00#")
    listthird.AddItem z
    Next x
    To perform the calculations I get the numbers by doing...

    Code:
    secondvalue(1) = listsecond.List(listsecond.ListIndex)
    thirdvalue(1) = listthird.List(listthird.ListIndex)
    And then I do the calculations...

    Code:
    x = secondvalue(1) * (thirdvalue(1) / 100)
    y = x / 365
    amountvalue = y / 86400
    Thanks for the reply.

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: Listbox Run Time Error 13

    Yep definitely the commas are causing a problem. Remove them from the listbox entries before you process them.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  5. #5

    Thread Starter
    Lively Member Yumby's Avatar
    Join Date
    Feb 2009
    Posts
    120

    Re: Listbox Run Time Error 13

    I took out all the commas but the error still kept appearing. The error occurred at this line....

    Code:
    x = (secondvalue(1)) * (thirdvalue(1) / 100)
    In the above code.....

    x = Empty
    secondvalue(1) = ""
    thirdvalue(1) = "4.5"

    And when I increased the 2nd listbox so that it's numbers were 1 to 100000. The same error appeared and I got the following results...

    x = Empty
    secondvalue(1) = ""
    thirdvalue(1) = ""

    So it looks like the strings are the problem. With a listbox, is there a function that will convert the string to a number? The val and int functions can't do it. So, any ideas?

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Listbox Run Time Error 13

    The problem is that a Null string cannot be converted to a number. For secondvalue(1) to be null either the code to set it has not been executed, or no item in listsecond was selected when the assignment was made.

  7. #7
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: Listbox Run Time Error 13

    Quote Originally Posted by Doogle View Post
    The problem is that a Null string cannot be converted to a number. For secondvalue(1) to be null either the code to set it has not been executed, or no item in listsecond was selected when the assignment was made.
    Yumby, if your strings are not convertible to numbers, you will keep getting these errors. So the basic rule of thumb you should remember is the strings you are trying to use in calculations must be convertible to numbers. This means the strings cannot be empty, they cannot contain anything other than digits and a decimal symbol. You may have a positive or negative sign before the number, but that's basically all. Any commas, special characters, spaces, or empty strings are a strict NO NO.

    That said, to fix the problem with empty strings, try prefixing them with "0". For e.g.

    Code:
    x = ("0" & secondvalue(1)) * ("0" & thirdvalue(1) / 100)
    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  8. #8

    Thread Starter
    Lively Member Yumby's Avatar
    Join Date
    Feb 2009
    Posts
    120

    Re: Listbox Run Time Error 13

    Thanks for the replies guys. Thanks to your help I seem to be getting closer to solving this problem. But it's going to take me a while. The only other information I can add is.....

    When the listsecondlist has the numbers 1 to 100000 in it, and the number 1 is selected, a couple of message boxes tell me that the listindex of this listbox is 0 and that the number selected is 1. This is of course good.

    But when the listsecondlist has the numbers 1 to 100000 in it, and the number 100000 is selected, a message box tells me that the listindex of this listbox is -31073. And then another message box tells me that nothing has been selected. In other words, the latter message box does not display the listbox's list item.

  9. #9
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Listbox Run Time Error 13

    The problem is that the ListIndex property of a ListBox is Integer, so if you have more than 32,767 entries (ie 0 to 32,766) it will go negative. Do you really want a list of 100,000 items for the user to select from ?

  10. #10

    Thread Starter
    Lively Member Yumby's Avatar
    Join Date
    Feb 2009
    Posts
    120

    Re: Listbox Run Time Error 13

    Sorry for the late reply. Okay understood. Don't use commas and so on and don't go more than 32,767 entries. Problem solved. Thanks for the help guys.

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