+ Reply to Thread
Results 1 to 9 of 9

CSng <Subscript out of range> - Completely Stumped

  1. #1
    Registered User
    Join Date
    05-08-2013
    Location
    Terre Haute, Indiana
    MS-Off Ver
    Excel 2010
    Posts
    13

    CSng <Subscript out of range> - Completely Stumped

    The program I'm writing is going to parse a file and extract certain data and then sync 2 files (attention and heart rate).

    here is the string causing the problem:
    Look 1 (Center) -- Start Time: 0.2 sec, End Time: 2.6, Duration: 2.4 sec
    Yes, the spaces in the front are standard, and there are 15, I used word and displayed hidden characters.

    /edit - there ARE 15 leading spaces, it doesn't show it though...


    Here is the code causing the problem:

    Please Login or Register  to view this content.

    I need to extract the "0.2" from the string, and place it into an array, however, it tosses an error, and while debugging, siStartLk(iTrialctr, iLkctr) shows siStartLk(iTrialctr, iLkctr) = <Subscript out of range>. Where iTrialctr and iLkctr are both 1 (first trial, first look, so it essentially gets caught instantly). I've checked and counted the indexes correctly, I THINK.
    When the program breaks these are the following values:
    iStartLoc = 38 (index of "S") (the + 12 gives 50, '0' in '0.2')
    iTimeLen = 3 (which it should be, '0.2')
    iCommaALoc = 57 (-5, is '2' in '0.2'

    Am I missing something?

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: CSng <Subscript out of range> - Completely Stumped

    try
    Please Login or Register  to view this content.
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    05-08-2013
    Location
    Terre Haute, Indiana
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: CSng <Subscript out of range> - Completely Stumped

    I'm still gettting
    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: CSng <Subscript out of range> - Completely Stumped

    As the conversion of the 0,2 works fine for me when I assign it to a variable my next guess would be that the array is too small.

    You are starting your arrays with the index 1 but iTrialctr = 0 ^^

    Regards

  5. #5
    Registered User
    Join Date
    05-08-2013
    Location
    Terre Haute, Indiana
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: CSng <Subscript out of range> - Completely Stumped

    iTrialctr starts at 0, but is incremented by 1 in the first if statement.
    While debugging, and hovering over the variable - it says the value of both variables in siStartLk() are 1,1.
    :/

  6. #6
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: CSng <Subscript out of range> - Completely Stumped

    Mhh, I can do that without a problem, please insert "Option Explicit" at the top of the code module and click "Debug" -> "Compile VBA Peoject". Then you are forced to declare all your variables but I guess you are using an array which wasnt declared at all

  7. #7
    Registered User
    Join Date
    05-08-2013
    Location
    Terre Haute, Indiana
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: CSng <Subscript out of range> - Completely Stumped

    The code is much, much longer. This was only a snippet of the code, I do have Option Explicit - always. So that the macro doesn't slow down .

    Are you using 2010? That's the version of Excel I use at work.

  8. #8
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: CSng <Subscript out of range> - Completely Stumped

    I am using 2013.

    1. Try to assign the 0,2 to a variable instead of the array

    2. make sure you are using the correct array, "iStartLk" is re-sized at the beginning of the snipped but "siStartLk" is used in the problematic line

    3. debug the code (F8) and check the size of the array and the index variables in the locals window

    cannot say any more as it works fine for me in 2013.

    Regards

  9. #9
    Registered User
    Join Date
    05-08-2013
    Location
    Terre Haute, Indiana
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: CSng <Subscript out of range> - Completely Stumped

    I've added to the code:

    Please Login or Register  to view this content.
    and debugvar holds the correct value, and the same problem error '9' :/
    Anyone have any idea?

    I must have skipped over suggestion 2. After working on posting a book to StackOverflow, I realized the arrays weren't the same. Thanks tehneXus
    Last edited by skania; 05-10-2013 at 08:27 AM. Reason: Facepalmed

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1