[ Ero S Ovoga Sveta @ 27.09.2004. 22:35 ] @
Mogu li da natjeram procesor da u isto vrijeme obradjuje dvije procedure.

Objasnjenje:

Imam petlju "Do While Not" koja se vrti oko 0-3 minute dok ne izracuna zeljenu vrijednost.
E sad prije nje sam startovao Timer i podesio ga na Interval "10".
U Timer sam stavio brojac: "T = T + 1".
Iza petlje je kod da mi ispise u "Label1" Vrijednost "T" i zaustavi "Timer" .
Medjutim u ovom slucaju "Timer" uopste ne broji jer se procedura "Private Sub Timer1_Timer()"
ne izvrsava dok god ne zavrsi petlja "Do While Not", a meni je potrebno da znam tacno
vrijeme, u mS, koliko se dugo izvrsavala ova procedura.

Ako neko zna rjesenje ili na slican ili na neki potpuno drugi nacin bio bi zahvalan.
[ Marko_L @ 27.09.2004. 22:55 ] @
Uopšte ne moraju da se izvršavaju dve procedure u isto vreme.Možeš da iskoristiš sistemsko vreme pri računanju.Probaj ovako, pre nego započneš petlju, stavi
Code:
vreme = Time

a onda, po završetku petlje:
Code:
proteklo = DateDiff("s", vreme, Time) * 1000

I dobićeš vreme u milisekundama.
[ Vranac @ 28.09.2004. 05:15 ] @
stavi u petlju DoEvents().

Yields execution so that the operating system can process other events.

Syntax

DoEvents( )

Remarks

The DoEvents function returns anInteger representing the number of open forms in stand-alone versions of Visual Basic, such as Visual Basic, Professional Edition. DoEvents returns zero in all other applications.

DoEvents passes control to the operating system. Control is returned after the operating system has finished processing the events in its queue and all keys in the SendKeys queue have been sent.

DoEvents is most useful for simple things like allowing a user to cancel a process after it has started, for example a search for a file. For long-running processes, yielding the processor is better accomplished by using a Timer or delegating the task to an ActiveX EXE component.. In the latter case, the task can continue completely independent of your application, and the operating system takes case of multitasking and time slicing.

Caution Any time you temporarily yield the processor within an event procedure, make sure theprocedure is not executed again from a different part of your code before the first call returns; this could cause unpredictable results. In addition, do not use DoEvents if other applications could possibly interact with your procedure in unforeseen ways during the time you have yielded control.
[ mladenovicz @ 28.09.2004. 10:05 ] @
Citat:
MSDN:
The GetTickCount function retrieves the number of milliseconds that have elapsed since Windows was started.


Code:

Private Declare Function GetTickCount& Lib "kernel32" ()

Private Sub Form_Load()
    Dim Duration    As Long
    Dim i           As Long
    
    Duration = GetTickCount()
    For i = 1 To 10000
        Debug.Print i
    Next
      
    Debug.Print "Finished in " & GetTickCount - Duration & " ms"
End Sub
[ Ero S Ovoga Sveta @ 28.09.2004. 17:38 ] @
OK Hvala svima.

A dali je moguce da se ogranici zauzece procesora, posto dok se vrti u petlji ono je
100%? Znaci jel moguce da ogranicim procesor na npr. 50% zauzeca, dok se vrti u
petlji "Do While Not"???
[ VRKY @ 28.09.2004. 18:28 ] @
Mislim da se ne može...
Processor se drži na 100% dok ne odradi ovo (bar ja msilm) pa smanji taj broj (ako ti to tvoja aplikacija dopušta)

Code:

For i = 1 To 10000
        Debug.Print i
Next

P:S nisam čitao sve postove.. pa ne znam o čemu se točno radi..
[ mladenovicz @ 28.09.2004. 19:43 ] @
Mozda nesto moze da se napravi sa prioritetima, ali nisam siguran. Ako si dokon, probaj ;)

Code:

Const THREAD_BASE_PRIORITY_IDLE = -15
Const THREAD_BASE_PRIORITY_LOWRT = 15
Const THREAD_BASE_PRIORITY_MIN = -2
Const THREAD_BASE_PRIORITY_MAX = 2
Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN
Const THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX
Const THREAD_PRIORITY_BELOW_NORMAL = (THREAD_PRIORITY_LOWEST + 1)
Const THREAD_PRIORITY_ABOVE_NORMAL = (THREAD_PRIORITY_HIGHEST - 1)
Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE
Const THREAD_PRIORITY_NORMAL = 0
Const THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRT
Const HIGH_PRIORITY_CLASS = &H80
Const IDLE_PRIORITY_CLASS = &H40
Const NORMAL_PRIORITY_CLASS = &H20
Const REALTIME_PRIORITY_CLASS = &H100
Private Declare Function SetThreadPriority Lib "kernel32" _
(ByVal hThread As Long, ByVal nPriority As Long) As Long
Private Declare Function SetPriorityClass Lib "kernel32" _
(ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
Private Declare Function GetThreadPriority Lib "kernel32" _
(ByVal hThread As Long) As Long
Private Declare Function GetPriorityClass Lib "kernel32" _
(ByVal hProcess As Long) As Long
Private Declare Function GetCurrentThread Lib "kernel32" () As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    Dim hThread As Long, hProcess As Long
    'retrieve the current thread and process
    hThread = GetCurrentThread
    hProcess = GetCurrentProcess
    'set the new thread priority to "lowest"
    SetThreadPriority hThread, THREAD_PRIORITY_LOWEST
    'set the new priority class to "idle"
    SetPriorityClass hProcess, IDLE_PRIORITY_CLASS
    'print some results
    Me.AutoRedraw = True
    Me.Print "Current Thread Priority:" + Str$(GetThreadPriority(hThread))
    Me.Print "Current Priority Class:" + Str$(GetPriorityClass(hProcess))
End Sub



Citat:
Parameters:
· hProcess
Identifies the process.
Windows NT: The handle must have the PROCESS_SET_INFORMATION access right. For more information, see Process Objects.

· dwPriorityClass
Specifies the priority class for the process. Specify one of the following values:
HIGH_PRIORITY_CLASS
Specify this class for a process that performs time-critical tasks that must be executed immediately. The threads of the process preempt the threads of normal or idle priority class processes. An example is Windows Task List, which must respond quickly when called by the user, regardless of the load on the operating system. Use extreme care when using the high-priority class, because a high-priority class application can use nearly all available CPU time.
IDLE_PRIORITY_CLASS
Specify this class for a process whose threads run only when the system is idle. The threads of the process are preempted by the threads of any process running in a higher priority class. An example is a screen saver. The idle-priority class is inherited by child processes.
NORMAL_PRIORITY_CLASS
Specify this class for a process with no special scheduling needs.
REALTIME_PRIORITY_CLASS
Specify this class for a process that has the highest possible priority. The threads of the process preempt the threads of all other processes, including operating system processes performing important tasks. For example, a real-time process that executes for more than a very brief interval can cause disk caches not to flush or cause the mouse to be unresponsive.
[ Ero S Ovoga Sveta @ 28.09.2004. 21:33 ] @
Citat:
VRKY: Mislim da se ne može...
Processor se drži na 100% dok ne odradi ovo (bar ja msilm) pa smanji taj broj (ako ti to tvoja aplikacija dopušta)

Ne mogu da smanjim broj Objasnicu o cemu se radi...
Citat:
mladenovicz: Mozda nesto moze da se napravi sa prioritetima, ali nisam siguran. Ako si dokon, probaj ;)

Prejednostavan je ovo program da bi ga toliko komplikovao.

Evo o cemu se radi: Na formi je 1 TextBox, 1 CommandButton i 1 Label.U TextBox Upisete neki cijeli broj u TextBox
i pritiskom na dugme program treba da u Label ispise prvi sledeci, cijeli, PROSTI broj. Ako neko ne zna:
>>Broj je PROST ako nije djeljiv ni sa jednim cijelim brojem osim sa 1 i sa samim sobom<<
Ja i kolega se takmicimo ko ce da napravi brzi program za izracunavanje. To je inace zadatak sa
nekog faksa. Ako je neko dokon da vjezba, evo lijepog zadatka. Zakacio sam moj program uz ovu
poruku. Ako neko uspije da napravi brze Neka javi.
Pomoc:
Broj X je prost ako nije djeljiv sa prvih X/2 Brojeva. Znaci Ostale ne morate provjeravati.
Ja sam program ogranicio na 9 cifara.
Nije tako jednostavno kao sto Izgleda!!!
[ mladenovicz @ 29.09.2004. 10:11 ] @
1. Deljivost sa 2 bi trebalo brze da se ispituje ovako:
Code:

If (MyNumber And 1) = 0 Then ' nije paran


2.
Citat:

Broj X je prost ako nije djeljiv sa prvih X/2 Brojeva


ako se dobro secam, dovoljno je proveravati samo prvih Sqr(X) brojeva
[ Ero S Ovoga Sveta @ 30.09.2004. 01:45 ] @
Citat:
mladenovicz

ako se dobro secam, dovoljno je proveravati samo prvih Sqr(X) brojeva

Upravu si.

Sa petlje Do While Not presao sam na petlju For Next Step 2 i promvjeravam samo
neparne brojeve, cime se duplo ubrza.