Sign in to follow this  
Followers 0
Dethredic

Help Combining Scripts

13 posts in this topic

I have a school project on math and computers.

For my project i am going to giver my teacher some example of how computers help us compute math very quickly.

I have one script, that i have found on the forums a while ago, and i want it to be combined with my very basic GUI.

So instead of writing the prime numbers to a .txt file on the desktop it puts them into the area in the GUI.


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Haha, I remember writing prime.au3:

http://www.autoitscript.com/forum/index.ph...st&p=238223

Yeah, i could integrate it with that GUI. Though i wrote a much faster one in C++. I will integrate it with a GUI, after all, it is my script and i guess it could use a GUI.

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Cool, i didn't know it was yours.

I would like it to be in Autoit (its fast to 1000000) which is big enough for me, but C++ is fine too


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

just linked the two

#include <file.au3>
#include <GUIConstants.au3>

Dim $numbertocalcto

$Form1 = GUICreate("Prime Generator", 525, 452, 266, 132)
Dim $Answer = GUICtrlCreateEdit("", 272, 8, 241, 425)
GUICtrlCreateLabel("Prime Generator", 56, 16, 182, 33)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Input = GUICtrlCreateInput("", 40, 160, 193, 21)
GUICtrlCreateLabel("Prime Numbers To Generate To", 40, 128, 196, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Generate = GUICtrlCreateButton("Generate Primes", 80, 200, 105, 33, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Generate
            $numbertocalcto = GUICtrlRead($Input)
            If IsInt(Number($numbertocalcto)) And $numbertocalcto < 2 Then
                MsgBox(64, "Error!", "You didn't enter a valid number.  Please try again.")
            Else
                Calc()
            EndIf
    EndSelect
WEnd

Func Calc()
    GUICtrlSetData($Answer, "")
    $counter = 1
    GUICtrlSetData($Answer, "Prime Numbers Calculater to " & $numbertocalcto & @CRLF, 1)
    For $Number = 3 To $numbertocalcto Step 2
        $divisor = 3
        While 1
            If $divisor * $divisor > $Number Or Mod($Number, $divisor) = 0 Then ExitLoop
            $divisor = $divisor + 2
        WEnd
        If $divisor * $divisor > $Number Then   ; are all divisor exhausted?
            $counter = $counter + 1              ; yes, this Number is a prime
            GUICtrlSetData($Answer, 'Prime number #' & $counter & ': ' & $Number & @CRLF, 1)
        EndIf
    Next
    GUICtrlSetData($Answer, "There were " & $counter & " primes found between 2 and " & $numbertocalcto & @CRLF, 1)
EndFunc   ;==>Calc

***********

Something strange to me was this..

If IsInt(Number($numbertocalcto)) And $numbertocalcto > 2 Then ExitLoop

i changed it to...

If IsInt(Number($numbertocalcto)) And $numbertocalcto < 2 Then

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks Val, exactly what i wanted :P

Changed

GUICtrlSetData($Answer, 'Prime number #' & $counter & ': ' & $Number & @CRLF, 1)

to

GUICtrlSetData($Answer, $Number & @CRLF, 1)

"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

Welcome

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Hmmm unexpected problem

The edit box only lets has room for about 42,000 primes

any way to make this bigger?


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Here is mine:

#include <GUIConstants.au3>
Opt("GUIOnEventMode",1)
;~ #include <Prime.au3>
$Form1 = GUICreate("Prime Generator", 525, 452, 266, 132)
$i_inputnumber = GUICtrlCreateInput("", 40, 160, 193, 21 )
$edit_results = GUICtrlCreateEdit("", 272, 8, 241, 425,$ES_READONLY + $ES_WANTRETURN + $WS_VSCROLL + $WS_HSCROLL + $ES_AUTOVSCROLL + $ES_AUTOHSCROLL)
GUICtrlSetBkColor ($edit_results,0xffffff)
GUICtrlCreateLabel("Prime Generator", 56, 16, 182, 33)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("Prime Numbers To Generate To", 40, 128, 196, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Generate = GUICtrlCreateButton("Generate Primes", 80, 200, 105, 33, 0)
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($Generate,"Start")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
While 1
    sleep(1000)
Wend
Exit

Func Start()
    GUICtrlSetData($edit_results,"")
    Local $i_number = Number(GUICtrlREad($i_inputnumber))
    GUICtrlSetData($i_inputnumber,$i_number)
    CalculatePrimes(GUICtrlREad($i_inputnumber),True)
EndFunc
Func CalculatePrimes($i_PrimeToCalcTo, $comments = True)
    Opt("GUIOnEventMode",1)
    $counter = 1
    If $comments = True Then
        GUICtrlSetData($edit_results,'Prime Number1: ' & 2 & @CRLF)
    Else
    GUICtrlSetData($edit_results,2 & @CRLF)
    EndIf
    For $Number = 3 To $i_PrimeToCalcTo Step 2
        $divisor = 3
        While 1
            If $divisor * $divisor > $Number Or Mod($Number, $divisor) = 0 Then ExitLoop
            $divisor = $divisor + 2
        WEnd
        If $divisor * $divisor > $Number Then   ; are all divisor exhausted?
            $counter = $counter + 1 
                         ; yes, this Number is a prime
            If $comments = True Then
;~         ConsoleWrite('Prime number #' & $counter  & ': ' & $Number & @LF)
                GUICtrlSetData($edit_results, "Prime Number:" & $counter & ":" & $Number & @CRLF & GUICtrlRead($edit_results))
;~         FileWrite($h_filehandle,'Prime number #' & $counter  & ': ' & $Number & @CRLF)
            Else
;~         ConsoleWrite($Number & @LF)
                GUICtrlSetData($edit_results, $Number & @CRLF & GUICtrlRead($edit_results))
;~          FileWrite($h_filehandle,$Number & @CRLF)
            EndIf
            
        EndIf
    Next
EndFunc   ;==>CalculatePrimes

Func SpecialEvents()
    Select
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
            Exit            
        Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
            
        Case @GUI_CTRLID = $GUI_EVENT_RESTORE
            
    EndSelect
    
EndFunc

EDIT: Fixed a few bugs in logic

EDIT:

Here is a prime calculator i wrote in c++. Much faster. It writes the primes it calculates to a text file called "primenuumbers.txt" in the same directory:

No, it isn't malicious. Only an idiot would make a virus and it would take someone truly insane to post one on a scripting/programming forum.

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Hmmm unexpected problem

The edit box only lets has room for about 42,000 primes

any way to make this bigger?

and just what are you going to do with more than 42,000 primes

?????

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

The number you input.... isn't the amount of primes, but instead the number closest to the prime number to stop at.


- Dan [Website]

Share this post


Link to post
Share on other sites

The number you input.... isn't the amount of primes, but instead the number closest to the prime number to stop at.

Yes, that would be correct.


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Thanks for the help guys, I think i am going to try to make it so that it will start at a predetermined number (if i have time).

Example, It will calculate from 10000 to 100000

The number you input.... isn't the amount of primes, but instead the number closest to the prime number to stop at.

Ya i knew that, just typed differently than i was thinking, but my point got across that it ran out of room.


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

Sorry, but i need one last thing.

Its probable out there, but i searched the forums and help file and could not find it.

I making a "stop" button for this generator so that if my teacher puts in 2000000 and she doesn't want to wait that long, she can stop.

I want it to stop a function and not exit the script.

How do i do this???


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0