LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Storing Data in code? (relative primes to MOD as example)


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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding primes Dave Excel Discussion (Misc queries) 3 November 18th 08 07:56 PM
storing data JK57 Excel Worksheet Functions 3 May 1st 06 12:16 AM
Storing data Bob Mckenzie New Users to Excel 3 July 30th 05 07:33 PM
Storing various data in .ID property Thorsten Walenzyk Excel Programming 10 December 9th 04 08:27 PM
Storing data between sessions BowMag Excel Programming 1 September 17th 04 12:26 AM


All times are GMT +1. The time now is 12:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"