+ Reply to Thread
Results 1 to 4 of 4

Splitting a number into individual digits

  1. #1
    Registered User
    Join Date
    03-09-2014
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    15

    Splitting a number into individual digits

    I have to split a number, at most 3 digits in length, to singular digits. I then need to store them within arrays F() and C(). My code has my main program calling a sub program to accomplish this. I need to store the Tens and Hundreds digits into array element C(I+1) and C(I+2) respectively. The code I have is the one I learned, but it does not seem to be working. Maybe some could point me in the right direction. Here's my code so far, my main program is not complete, but the important parts are prior to calling the subprogram and the sub program itself. BTW, this is code for a Large Factorial Calc.

    Please Login or Register  to view this content.
    Last edited by cdesantis01; 04-21-2014 at 11:04 PM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Splitting a number into individual digits

    Hi,

    I can see several issues here. Let me address first few of them
    - you declare F, C, split1 and others as single while they are integers by nature if you plan to use large numbers instead of integer type long could be used
    - you declare mult as string - again it's an integer number (or long)
    - split1 and split2 will always be equal to 1, unless mult is an empty string
    - anyway split1 will be always equal to split2 because both follow the same InStr(mult, "") and mutl does not change in meanwhile (between assigning value to split1 and split2
    - in the inner loop (control variable i) you call split (by the way - bad idea because there is a standard function called split). But you do not pass i to this function so i is an empty variable in this functions scope.
    - if it would be passed (sone i0) then you would assingn C(i0+1) and C(i0+2) but in a moment i is incremented (equal ti i0+1) and in split you would assign C(i0+2) and C(i0+3) overwriting previous C(i0+2) value.
    - etc.

    So a long way to go. A tip: start from easier tasks, and read about types of variables, their declaring and scope of declaration.
    Last edited by Kaper; 04-22-2014 at 02:16 AM.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    03-09-2014
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Splitting a number into individual digits

    Thanks Kaper for responding. I have been working on it and I basically scrapped my initial attempt at that splitting code. I used a select case instead. But the output is always Zero. I think I know what I am doing wrong, but I do not know how to translate it into code. I need to loop the summation of the array cells AFTER I multiply each array cell by the current J loop integer, and split the product into their respective array cells. Also, I probably need to make another split sub for the sums, which I haven't done yet. Anyway, here's the updated code:

    Please Login or Register  to view this content.
    Last edited by cdesantis01; 04-22-2014 at 11:37 AM.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Splitting a number into individual digits

    still far far away:
    1) mult still as string. If you want use a number (not string) for select case you can consider construction like:
    Please Login or Register  to view this content.
    2) after a loop
    Please Login or Register  to view this content.
    you calculate sum
    Please Login or Register  to view this content.
    as it is just after the abave referred loop you calculate:
    Please Login or Register  to view this content.
    3)
    Please Login or Register  to view this content.
    part will never be executed it would be only if first criteria is not met but if sum is not >9 then for sure is not >99
    4)
    Please Login or Register  to view this content.
    again I is equal 29 here

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Storing individual digits to Array Cells
    By cdesantis01 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-13-2014, 09:23 PM
  2. [SOLVED] Splitting phone bill into individual sheets
    By Christopher135 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2013, 01:52 AM
  3. Replies: 7
    Last Post: 02-11-2012, 10:11 AM
  4. Sum of individual digits (just for fun)
    By Hans Knudsen in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-10-2006, 03:29 AM
  5. Count individual digits
    By James in forum Excel General
    Replies: 11
    Last Post: 04-28-2005, 03:06 PM

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