Vera writes:
I wondered why you'd used that 1-50 loop
at first don't forgot that bfitch have posted his .pl file as zip file look
http://purebasic.fr/english/viewtopic.p ... 25#p469648
the 50 loops is because i have used this code to call
Factor.exe from shamus sotware now available only from web.archive.org 2007 nov
http://web.archive.org/web/200711181716 ... factor.exe
there is also variations here:
http://home.netcom.com/~jrhowell49/math/software.htm search word shamus. but i prefer the original version from year 2007 in archive.org
it is needed to wait the outputs of Factor.exe one by one, we may need 50 or more or less but now i recognize that
While ProgramRunning(console) are better choice.
beware of numbers made from 2 very big prime numbers like used in the Banks the factor.exe may stay running for days.
here is the code for calling the factor.exe with a specific number using your loop version
Code: Select all
console.l = RunProgram("factor.exe"," -s 111111111111111111111111","",#PB_Program_Open|#PB_Program_Read|#PB_Program_Write)
While ProgramRunning(console)
If AvailableProgramOutput(console)
s.s = s.s + " " + ReadProgramString(console)
EndIf
Delay(10)
Wend
Debug s
i have found also on my old pc unexpected code seems strange to me and it contains even Goto function, it display the outputs of factor.exe to EditorGadget. so the same program can be adapted for calling perl to do regular expressions (or whatever) and returning the results back to EditorGadget, definitely i have copied parts of it from this forum (except Goto which are mostly from me), i provide it as it is. just put factor.exe in the same folder as the code
try number 11111111111111111111111111111111111111111111111111111111111
and it will factor it to 2559647034361 * 4340876285657460212144534289928559826755746751
we can check the results with
http://www.wolframalpha.com/ just write: factors of 11111111111111111111111111111111111111111111111111111111111
Edit: look here the post of klonk :
http://forums.purebasic.com/english/vie ... p?p=137416
Code: Select all
;{ ==========================================================================
;| EndProgram(processID.l)
;| Closes the application that was started with RunProgram. In difference
;| to KillProgram it allows the program to shut down properly and save e.g.
;| settings. The parameter "processID" is obtained by ProgramID(<result of
;| RunProgram(app$,option$,path$, #PB_Program_Open)>)
;} ==========================================================================
Procedure EndProgram(processID.l)
;***** End a program started with Runprogram, but give chance to save settings!
If OpenProcess_(#PROCESS_ALL_ACCESS,0,processID)<>0
CloseHandle_(processHandle)
Repeat ;searcht through all windows
win=FindWindow_(0,0)
While win<>0
GetWindowThreadProcessId_(win,@pid.l) ; get processID of found window
If pid=processID : WinHandle=win : Break : EndIf
win=GetWindow_(win,#GW_HWNDNEXT)
Delay(100)
Wend
Until WinHandle
PostMessage_(WinHandle,#WM_CLOSE,0,0) ; Now close the started application
EndIf
EndProcedure
Procedure factorize(number$)
s.s
number$ = " -d200 "+" -s "+number$
handle.l = RunProgram("factor.exe",number$,"",#PB_Program_Open|#PB_Program_Read|#PB_Program_Write|#PB_Program_Hide)
id.l = ProgramID(handle)
waitTime.l=20000 ;20000 milliseconds
Result = WaitProgram(handle.l,waitTime)
If Result=0
s = "the factoring time will exceed the waitTime specified, the process is halted "
CloseProgram(handle)
Sleep_(2000) ; Give it a couple of seconds to open.
EndProgram(id);End started program
Goto jmp
EndIf
While AvailableProgramOutput(handle)
s = s + ReadProgramString(handle) + " * "
Delay(10)
Wend
jmp:
s = Mid(s,1,Len(s)-4)
;SetGadgetText(0, s)
AddGadgetItem(0, -1, s+Chr(13)+Chr(10))
EndProcedure
If OpenWindow(0,0,0,550,460,"numbers factoring",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 230, 380, 210)
SendMessage_(GadgetID(0), #EM_SETTARGETDEVICE, #Null, 0)
StringGadget(1, 10, 80, 380, 60, "write number here", #PB_String_Numeric |#ESB_DISABLE_LEFT | #ESB_DISABLE_RIGHT | #ES_MULTILINE | #ES_AUTOVSCROLL | #WS_VSCROLL )
ButtonGadget(2, 420, 400, 120, 40, "Factorize" )
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 2 :
number$ = GetGadgetText(1)
factorize(number$)
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf