Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I would like to learn how to make my code more sophisticated. Specifically, I want to learn how to store data in my code after processing, only to send the final output to either a cell in a worksheet or someother textbox object in a userform, after the calculations are complete. Currently, many of the codes I write store interm data/calculations in cells in a worksheet. Then later code grabs those interim numbers, uses them for further calculations, and then finally puts the finished calculation back into, say, range("A1").value. I do not want to "bounce" calculations off the worksheet. I want to store them (in a collection?) in memory. Following is code that finds all the relative prime numbers for a given modulus. To run the code you will need to use Range("E1") to input the relavant modulus. For example, MOD 26 has 12 relative prime numbers, 1,3,5,7,9,11,15,17,19,21,23 and 25. [Side Note-- the code places a "data table" in cells A5:C(x)....ignore this for the purposes of this e-mail...just know that it is completely unnecessary to have this data table put into the cells. I have it there so I can find the multiplicative inverses of each of the relative primes with another sub-routine] Here is the catch: (A) I want to learn how to store the relative prime outputs (in the code, the "p-1" numbers) in memory while the program runs, INSTEAD of printing them, one at a time, in Range("A1").Value, as the program loops; (B) After the last loop, I want the relative primes stored in memory to be sorted from smallest to largest; and (C) I want to then put all of the numbers (now stored in memory and sorted) into Range("A1").value. Here is the Code (Remember to put the mod in cell E6): _______________________________ Sub search_inverse2() ' 'Inverse_Function = (P*N)-D*INT((P*N)/D) 'd = range("e1").value ' 'Basic Mod Formula: MOD(n, d) = n - d*INT(n/d) 'Where n = number, d = modulus ' Range("A1:C10000").Value = "" Dim n As Double Dim d As Double Dim p As Double Dim Inverse_function As Double ' count_num = 3 n = 0 d = Range("e1").Value Do Do Until Inverse_function = 1 Or p = d Inverse_function = (p * n) - d * Int((p * n) / d) p = p + 1 count_num = count_num + 1 Sheet1.Cells(count_num, 1).Value = p - 1 Sheet1.Cells(count_num, 2).Value = Inverse_function Loop If Inverse_function = 1 Then If Range("A1").Value < "" Then Range("A1").Value = Range("A1").Value & ", " & p - 1 Else Range("A1").Value = p - 1 End If End If p = 0 Inverse_function = 0 n = n + 1 Loop Until n = d End Sub __________________________ Any help will be appreciated! -- jasonsweeney ------------------------------------------------------------------------ jasonsweeney's Profile: http://www.excelforum.com/member.php...fo&userid=5222 View this thread: http://www.excelforum.com/showthread...hreadid=397484 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Finding primes | Excel Discussion (Misc queries) | |||
storing data | Excel Worksheet Functions | |||
Storing data | New Users to Excel | |||
Storing various data in .ID property | Excel Programming | |||
Storing data between sessions | Excel Programming |