Welcome to Dream.In.Code
Become a VB Expert!

Join 137,233 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,754 people online right now. Registration is fast and FREE... Join Now!




about looping

 
Reply to this topicStart new topic

about looping

pau-pau
24 Feb, 2007 - 04:49 AM
Post #1

New D.I.C Head
*

Joined: 30 Jan, 2007
Posts: 24


My Contributions
CODE
Sub quantum8()
'Round Robin q8
    If jobq1(t) <= 8 Then
        Do Until jobq1(t) = 0
        guanttchart.TextMatrix(tiktak, 1) = Q1.TextMatrix(t, 0)
        Loop
        t = t + 1
    ElseIf jobq1(t) > 8 Then
        Do While quantum <= 8
        guanttchart.TextMatrix(tiktak, 1) = Q1.TextMatrix(t, 0)
        quantum = quantum + 1
        Loop
        t = t + 1
    End If
End Sub


this is taken from the cpu scheduling MLFQ i'm making in VB 6

i'm having problems with my loop, can someone give me suggestions or revision to my code
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: About Looping
24 Feb, 2007 - 06:40 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Can you specify the problem?
User is online!Profile CardPM
+Quote Post

NickDMax
RE: About Looping
24 Feb, 2007 - 08:40 PM
Post #3

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,859



Thanked: 50 times
Dream Kudos: 550
My Contributions
Well I just learnd what a Multilevel Feedback Queue is, and I assume that this bit of code is for the bottom level where processes are put when they are bad (i.e don't finnish while in a higher priority queue). But I don't really see what you are looking for, or how your code work, or what your problem is. We need more information to help you.
User is offlineProfile CardPM
+Quote Post

pau-pau
RE: About Looping
26 Feb, 2007 - 05:57 AM
Post #4

New D.I.C Head
*

Joined: 30 Jan, 2007
Posts: 24


My Contributions
CODE

Dim size As Integer, txtText As String
Dim Tburst As Integer
Dim mem As Integer
Dim t As Integer
Dim tt As Integer
Dim ttt As Integer
Dim i As Integer
Dim Time As Integer
Dim o
Dim a As Integer
Dim q1ctr As Integer
Dim q2ctr As Integer
Dim tiktak As Integer
Dim quantum As Integer
Dim quantumq1 As Integer
Dim quantumq22 As Integer
Dim quantumq2 As Integer
Dim leftburst As Integer
Dim jobq1(0 To 6) As Integer
Dim jobq2(0 To 6) As Integer
Dim jobq3(0 To 6) As Integer
                        
Private Sub Command1_Click()
Timer1.Enabled = False
End Sub

Private Sub Command2_Click()
Timer1.Enabled = True
End Sub

Private Sub fast_Click()
Timer1.Interval = 100
End Sub

Private Sub Form_Load()
    grid.TextArray(0) = "Job ID"
    grid.TextArray(1) = "Arrival Time"
    grid.TextArray(2) = "Job Type"
    grid.TextArray(3) = "Memory Size"
    grid.TextArray(4) = "CPU Burst"
    grid.TextArray(5) = "Waiting Time"
    grid.TextArray(6) = "Turn Around"
    grid.TextArray(7) = "Finished Time"
    grid.Cols = 8
    memorygrid.TextArray(0) = "Size"
    memorygrid.TextArray(1) = "Job #"
    memorygrid.TextMatrix(1, 0) = "16K    "
    memorygrid.TextMatrix(2, 0) = "16K    "
    memorygrid.TextMatrix(3, 0) = "8K    "
    memorygrid.TextMatrix(4, 0) = "8K    "
    memorygrid.TextMatrix(5, 0) = "8K    "
    memorygrid.TextMatrix(6, 0) = "4K    "
    memorygrid.TextMatrix(7, 0) = "4K    "
    guanttchart.TextArray(0) = "Time"
    guanttchart.TextArray(1) = "Job"
End Sub

Sub initialize()
Dim i%, temp(100)
For i = 1 To size
      grid.Rows = grid.Rows + 1
Next i
charsinfile% = Len(txtText)
X = 0
charsinfile% = Len(txtText)
For i% = 1 To charsinfile%
    letter$ = Mid(txtText, i%, 1)
    If letter$ = Chr$(60) Then
        temp(X) = Mid(txtText, i% + 1, 2)
        X = X + 1
    End If
Next i%
Y = 1
For X = 1 To size
   grid.TextMatrix(X, 0) = temp(Y)
   grid.TextMatrix(X, 1) = temp(Y + 1)
   grid.TextMatrix(X, 2) = temp(Y + 2)
   grid.TextMatrix(X, 3) = temp(Y + 3)
   grid.TextMatrix(X, 4) = temp(Y + 4)
Y = Y + 5
Next X
End Sub

Sub memalloc()
'memory
If i <= size + 1 Then
If mem <> 64 And q1ctr <= 6 Then
'memory size of job is <=4K
    If grid.TextMatrix(i, 3) <= 4 And memorygrid.TextMatrix(7, 1) = "" Then
        memorygrid.TextMatrix(7, 1) = "Job " & grid.TextMatrix(i, 0)
        Q1.TextMatrix(q1ctr, 0) = memorygrid.TextMatrix(7, 1)
        jobq1(q1ctr) = grid.TextMatrix(i, 4)
        q1ctr = q1ctr + 1
        mem = mem + 4
    ElseIf grid.TextMatrix(i, 3) <= 4 And memorygrid.TextMatrix(6, 1) = "" Then
        memorygrid.TextMatrix(6, 1) = "Job " & grid.TextMatrix(i, 0)
        Q1.TextMatrix(q1ctr, 0) = memorygrid.TextMatrix(6, 1)
        jobq1(q1ctr) = grid.TextMatrix(i, 4)
        q1ctr = q1ctr + 1
        mem = mem + 4
'memory size of job is <=8k
    ElseIf grid.TextMatrix(i, 3) <= 8 And memorygrid.TextMatrix(5, 1) = "" Then
        memorygrid.TextMatrix(5, 1) = "Job " & grid.TextMatrix(i, 0)
        Q1.TextMatrix(q1ctr, 0) = memorygrid.TextMatrix(5, 1)
        jobq1(q1ctr) = grid.TextMatrix(i, 4)
        q1ctr = q1ctr + 1
        mem = mem + 8
    ElseIf grid.TextMatrix(i, 3) <= 8 And memorygrid.TextMatrix(4, 1) = "" Then
        memorygrid.TextMatrix(4, 1) = "Job " & grid.TextMatrix(i, 0)
        Q1.TextMatrix(q1ctr, 0) = memorygrid.TextMatrix(4, 1)
        jobq1(q1ctr) = grid.TextMatrix(i, 4)
        q1ctr = q1ctr + 1
        mem = mem + 8
    ElseIf grid.TextMatrix(i, 3) <= 8 And memorygrid.TextMatrix(3, 1) = "" Then
        memorygrid.TextMatrix(3, 1) = "Job " & grid.TextMatrix(i, 0)
        Q1.TextMatrix(q1ctr, 0) = memorygrid.TextMatrix(3, 1)
        jobq1(q1ctr) = grid.TextMatrix(i, 4)
        q1ctr = q1ctr + 1
        mem = mem + 8
'memory size of job is <=16K
    ElseIf grid.TextMatrix(i, 3) <= 16 And memorygrid.TextMatrix(2, 1) = "" Then
        memorygrid.TextMatrix(2, 1) = "Job " & grid.TextMatrix(i, 0)
        Q1.TextMatrix(q1ctr, 0) = memorygrid.TextMatrix(2, 1)
        jobq1(q1ctr) = grid.TextMatrix(i, 4)
        q1ctr = q1ctr + 1
        mem = mem + 16
    ElseIf grid.TextMatrix(i, 3) <= 16 And memorygrid.TextMatrix(1, 1) = "" Then
        memorygrid.TextMatrix(1, 1) = "Job " & grid.TextMatrix(i, 0)
        Q1.TextMatrix(q1ctr, 0) = memorygrid.TextMatrix(1, 1)
        jobq1(q1ctr) = grid.TextMatrix(i, 4)
        q1ctr = q1ctr + 1
        mem = mem + 16
    End If
End If
End If
End Sub

Private Sub mnuExit_Click()
End
End Sub

Private Sub mnuLoad_Click()
    Wrap$ = Chr$(13) + Chr$(10)
    cdlcommon.Filter = "Text files (*.TXT)|*.TXT"
    cdlcommon.ShowOpen
    If cdlcommon.FileName <> "" Then
        Open cdlcommon.FileName For Input As #1
        Do Until EOF(1)
            Line Input #1, LineOfText$
            AllText$ = AllText$ & LineOfText$ & Wrap$
        Loop
    txtText = AllText$
linecount% = 0
charsinfile% = Len(txtText)
For i% = 1 To charsinfile%
    letter$ = Mid(txtText, i%, 1)
    If letter$ = Chr$(13) Then
        linecount% = linecount% + 1
        i% = i% + 1
    End If
Next i%
size = linecount% - 1
Call initialize
CleanUp:
        Close #1
    End If
    Exit Sub
End Sub

Private Sub mnuRun_Click()
mem = 0
t = 0
tt = 0
ttt = 0
a = 0
q2ctr = 0
quantumq1 = 1
quantum = 1
quantumq2 = 1
quantumq22 = 1
leftburst = 1
i = 2
q1ctr = 0
grid.Col = 1
grid.Sort = 3
For o = 2 To size + 1
    Tburst = Tburst + grid.TextMatrix(o, 4)
Next
guanttchart.Rows = Tburst + 2
Time = 0
Timer1.Enabled = True
End Sub

Private Sub normal_Click()
Timer1.Interval = 500
End Sub

Private Sub slow_Click()
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Label6.Caption = Val(Time)
If i <= size + 1 Then
If grid.TextMatrix(i, 1) = Val(Time) And grid.TextMatrix(i, 7) = "" Then
    Call memalloc
    i = i + 1
End If
End If

Call timeline

If a <= 6 Then
    If Q1.TextMatrix(a, 0) <> "" And t <= 7 Then
    Call quantum8
    ElseIf Q1.TextMatrix(a, 0) = "" And Q2.TextMatrix(a, 0) <> "" And tt <= 7 Then
    Call quantum4
    ElseIf Q2.TextMatrix(a, 0) = "" And Q3.TextMatrix(a, 0) <> "" And ttt <= 7 Then
    Call FCFS
    End If
End If
cpu.Caption = guanttchart.TextMatrix(tiktak, 1)
Time = Time + 1
If Time = Tburst + 1 Then
Timer1.Enabled = False
End If
End Sub

Sub timeline()
tiktak = Val(Label6.Caption) + 1
guanttchart.TextMatrix(tiktak, 0) = Val(Label6.Caption)
End Sub

Sub quantum8()
'Round Robin q8
    If jobq1(t) <= 8 And quantumq1 <= jobq1(t) Then
        guanttchart.TextMatrix(tiktak, 1) = Q1.TextMatrix(t, 0)
        quantumq1 = quantumq1 + 1
            If quantumq1 > jobq1(t) Then
            'i = 2
            'If Q1.TextMatrix(t, 0) = memorygrid.TextMatrix(i, 1) Then
            ' Call calculate
            'End If
             jobq1(t) = 0
             Q1.TextMatrix(t, 0) = ""
            End If
    ElseIf jobq1(t) > 8 And quantum <= 8 Then
        guanttchart.TextMatrix(tiktak, 1) = Q1.TextMatrix(t, 0)
        quantum = quantum + 1
        Q2.TextMatrix(q2ctr, 0) = Q1.TextMatrix(t, 0)
        If quantum > 8 And Q2.TextMatrix(q2ctr, 0) = Q1.TextMatrix(t, 0) Then
            jobq2(q2ctr) = jobq1(t) - 8
            Q2.TextMatrix(q2ctr, 0) = Q1.TextMatrix(t, 0)
            Q1.TextMatrix(t, 0) = ""
            q2ctr = q2ctr + 1
        End If
    End If
    If quantumq1 > jobq1(t) Or quantum > 8 Then
    t = t + 1
    a = a + 1
    quantumq1 = 1
    quantum = 1
    End If
    If a > 6 Then
        a = 0
    End If
End Sub

Sub quantum4()
'Round Robin q4
    If jobq2(tt) <= 4 And quantumq2 <= jobq2(tt) Then
        guanttchart.TextMatrix(tiktak, 1) = Q2.TextMatrix(tt, 0)
        quantumq2 = quantumq2 + 1
            If quantumq2 > jobq2(tt) Then
            'i = 2
            'If Q2.TextMatrix(tt, 0) = memorygrid.TextMatrix(i, 1) Then
            ' Call calculate
            'End If
             Q2.TextMatrix(tt, 0) = ""
             jobq1(tt) = 0
            End If
    ElseIf jobq2(tt) > 4 And quantumq22 <= 4 Then
        guanttchart.TextMatrix(tiktak, 1) = Q2.TextMatrix(tt, 0)
        quantumq22 = quantumq22 + 1
        jobq3(tt) = jobq2(tt) - 4
        Q3.TextMatrix(tt, 0) = Q2.TextMatrix(tt, 0)
        If quantumq22 > 4 And Q3.TextMatrix(tt, 0) = Q2.TextMatrix(tt, 0) Then
            Q3.TextMatrix(tt, 0) = Q2.TextMatrix(tt, 0)
            Q2.TextMatrix(tt, 0) = ""
        End If
    End If
    If quantumq2 > jobq2(tt) Or quantumq22 > 4 Then
    tt = tt + 1
    a = a + 1
    quantumq2 = 1
    quantumq22 = 1
    End If
        If a > 6 Then
        a = 0
    End If
End Sub

Sub FCFS()
'first come fisrt serve
    If leftburst <= jobq3(ttt) Then
        guanttchart.TextMatrix(tiktak, 1) = Q3.TextMatrix(ttt, 0)
        leftburst = leftburst + 1
            If leftburst > jobq3(ttt) Then
            'i = 2
            'If Q3.TextMatrix(ttt, 0) = memorygrid.TextMatrix(i, 1) Then
            ' Call calculate
            'End If
             Q3.TextMatrix(ttt, 0) = ""
             jobq3(ttt) = 0
             ttt = ttt + 1
             a = a + 1
             leftburst = 1
            End If
    End If
End Sub

Sub calculate()
'finished time
grid.TextMatrix(i, 7) = Val(Label6.Caption)
'wating time
grid.TextMatrix(i, 5) = Val(Label6.Caption) - grid.TextMatrix(i, 1) - grid.TextMatrix(i, 4)
'turn around time
grid.TextMatrix(i, 6) = Val(Label6.Caption) - grid.TextMatrix(i, 1)
End Sub

Sub removemem()
If i <= size + 1 Then
If mem <> 0 Then
'memory size 4K
    If grid.TextMatrix(i, 3) <= 4 And grid.TextMatrix(i, 7) <> "" And memorygrid.TextMatrix(7, 1) <> "" Then
        memorygrid.TextMatrix(7, 1) = ""
        mem = mem - 4
    
    ElseIf grid.TextMatrix(i, 3) <= 4 And grid.TextMatrix(i, 7) <> "" And memorygrid.TextMatrix(6, 1) <> "" Then
        memorygrid.TextMatrix(6, 1) = ""
        mem = mem - 4
    
'memory size 8k
    ElseIf grid.TextMatrix(i, 3) <= 8 And grid.TextMatrix(i, 7) <> "" And memorygrid.TextMatrix(5, 1) <> "" Then
        memorygrid.TextMatrix(5, 1) = ""
        mem = mem - 8
    
    ElseIf grid.TextMatrix(i, 3) <= 8 And grid.TextMatrix(i, 7) <> "" And memorygrid.TextMatrix(4, 1) <> "" Then
        memorygrid.TextMatrix(4, 1) = ""
        mem = mem - 8
    
    ElseIf grid.TextMatrix(i, 3) <= 8 And grid.TextMatrix(i, 7) <> "" And memorygrid.TextMatrix(3, 1) <> "" Then
        memorygrid.TextMatrix(3, 1) = "Job " & grid.TextMatrix(i, 0)
        mem = mem - 8

'memory size 16K
    ElseIf grid.TextMatrix(i, 3) <= 16 And grid.TextMatrix(i, 7) <> "" And memorygrid.TextMatrix(2, 1) <> "" Then
        memorygrid.TextMatrix(2, 1) = ""
        mem = mem - 16
    
    ElseIf grid.TextMatrix(i, 3) <= 16 And grid.TextMatrix(i, 7) <> "" And memorygrid.TextMatrix(1, 1) <> "" Then
        memorygrid.TextMatrix(1, 1) = ""
        mem = mem - 16
    End If
End If
End If
End Sub


my iput textfile:
<20>
<01><11><01><04><20>
<02><07><02><04><20>
<03><03><03><08><20>
<04><04><01><16><20>
<05><05><03><16><20>
<06><06><02><04><20>
<07><17><03><04><20>
<08><08><01><08><20>
<09><09><02><16><20>
<10><10><01><16><20>
<11><01><01><04><20>
<12><12><02><04><20>
<13><15><03><08><20>
<14><14><02><16><20>
<15><13><01><16><20>
<16><16><02><04><20>
<17><02><02><04><20>
<18><18><01><08><20>
<19><19><02><16><20>
<20><20><03><16><20>

here is my whole code as for now, i can load the first 7 jobs in my memory and process it in my que, and i'm having a hard time deloading those jobs, when their process(burst time) ends, in my memory to give way to other jobs. also i can't figure out how to call the pending jobs that i skipped when my memory is full..

hope for your help...

This post has been edited by pau-pau: 26 Feb, 2007 - 06:02 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:45PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month