I Have these Programming Project In School Using Visual Basic 2005 Express, we were assigned to do a First Come First Serve Simulator however it's just my Second Year in College and I'm No good in Programming cause I'm not majoring in IT.. Any one can help me on how to start?
QUADCOREDELUX 0 Newbie Poster
Dani AI
Generated
began with an FCFS simulator and later posted an SJF attempt that fails at runtime. 's advice to break the task into the smallest pieces is exactly the right approach. The notes below point out the most likely causes of the runtime errors and give a compact, correct non‑preemptive SJF pattern that is easier to test and maintain than manual ReDim/Preserve array juggling.
Common mistakes found in the posted code: wrong fields used when sorting and swapping (which corrupts the array and causes index errors); arrays like sjf/npp used before they are initialized; mixing 1‑based loop logic with VB.NET’s 0‑based arrays; and swapped formulas for turnaround/waiting time. Correct formulas are: TAT = CompletionTime - ArrivalTime, and WT = TAT - BurstTime. Also, Gantt logic gets fragile if the scheduler does not explicitly advance current time when the CPU is idle.
A robust approach: load inputs into a List(Of Job) with properties ID, AT, BT; keep a single currentTime and repeatedly pick from jobs with AT <= currentTime the job having the smallest BT (tie-break by AT then ID). If none are available, set currentTime to the next job arrival. For each selected job: Start = currentTime; Finish = Start + BT; FT/TAT/WT as above; mark done and set currentTime = Finish. Use LINQ (.OrderBy/.ThenBy) or List.Sort instead of hand-coded swaps — it eliminates most index bugs and makes testing straightforward.
A minimal VB.NET pattern to implement the loop (replace fragile arrays with this):
Class Job
Public Property ID As Integer
Public Property AT As Integer
Public Property BT As Integer
Public Property FT As Integer
Public Property TAT As Integer
Public Property WT As Integer
Public Property Done As Boolean
End Class
Dim current = jobs.Min(Function(j) j.AT)
While jobs.Any(Function(j) Not j.Done)
Dim avail = jobs.Where(Function(j) Not j.Done AndAlso j.AT <= current) _
.OrderBy(Function(j) j.BT).ThenBy(Function(j) j.AT).ToList()
If avail.Count = 0 Then
current = jobs.Where(Function(j) Not j.Done).Min(Function(j) j.AT)
Continue While
End If
Dim sel = avail.First()
sel.FT = current + sel.BT
sel.TAT = sel.FT - sel.AT
sel.WT = sel.TAT - sel.BT
sel.Done = True
current = sel.FT
End While Test with small, hand‑calculated cases and log Start/Finish per job in a ListBox; that makes bugs obvious and keeps the GUI work separate from the scheduling logic.
Recommended Answers
Jump to Post— rapture 134I would start with reading your textbook and then break your project down to the smallest piece you can figure out on your own and if you get stuck post back as to what your problem is.
Jump to Post— Reverend Jim 6,665We appreciate your willingness to contribute but please check the dates on posts before you respond to them This thread is more than three years old and it is likely that the original poster (OP) no longer needs help with this issue. Reviving this thread pushes more recent threads further …
All 8 Replies
rapture 134 Posting Whiz in Training
I would start with reading your textbook and then break your project down to the smallest piece you can figure out on your own and if you get stuck post back as to what your problem is.
chirayu 0 Newbie Poster
can you be more specific and give details of ur college project? that would help.
QUADCOREDELUX 0 Newbie Poster
I'm totally Screwed with these:'( I can show the Screen
It's somewhat like the uploaded Image
It calculates a Job Inputed and shows out an output
QUADCOREDELUX 0 Newbie Poster
Sorry for the Second Post here's the exact Screen Sample
QUADCOREDELUX 0 Newbie Poster
Sorry for the Second Post here's the exact Screen Sample
QUADCOREDELUX 0 Newbie Poster
I Manage to do that FCFS Codes now My Next Problems is with the Shortest Job First
I Have these Code but at Runtime it's totally Screwed. anyone who can help me with Shortest Job First CPU Sceduling :
Public Class Form7
Private j() As Label
Private b() As NumericUpDown
Private a() As NumericUpDown
Private p() As NumericUpDown
Private t() As TextBox
Private w() As TextBox
Private g() As TextBox
Private job() As job
Dim ans As Integer
Dim i As Integer
Dim num As Integer
Dim r As Random
Dim rbt As Integer
Dim rat As Integer
Dim rp As Integer
Dim rq As Integer
Dim type As String
Dim tbt As Integer
Dim cpuu As Double
Dim ttat As Integer
Dim twt As Integer
Dim atat As Double
Dim awt As Double
Dim tp As Double
Dim i2 As Integer
Dim i3 As Integer
Dim n As Integer
Dim max As Integer
Dim gant() As String
Dim temp() As job
Dim temp2() As job
Dim sjf() As job
Dim npp() As job
Dim turn As Integer
Dim et As Integer
Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
GroupBox1.Controls.Clear()
GroupBox2.Controls.Clear()
GroupBox3.Controls.Clear()
GroupBox4.Controls.Clear()
GroupBox5.Controls.Clear()
GroupBox6.Controls.Clear()
GroupBox14.Controls.Clear()
num = Val(ComboBox1.Text)
For i = 1 To num
ReDim Preserve j(i)
j(i) = New Label
j(i).Top = i * 28
j(i).Text = "Job " & i
GroupBox1.Controls.Add(j(i))
ReDim Preserve b(i)
b(i) = New NumericUpDown
b(i).Top = i * 28
b(i).Left = 7
b(i).Width = 85
b(i).TextAlign = HorizontalAlignment.Center
GroupBox2.Controls.Add(b(i))
ReDim Preserve a(i)
a(i) = New NumericUpDown
a(i).Top = i * 28
a(i).Left = 12
a(i).Width = 90
a(i).TextAlign = HorizontalAlignment.Center
GroupBox3.Controls.Add(a(i))
ReDim Preserve p(i)
p(i) = New NumericUpDown
p(i).Top = i * 28
p(i).Left = 6
p(i).Width = 85
p(i).TextAlign = HorizontalAlignment.Center
GroupBox4.Controls.Add(p(i))
ReDim Preserve t(i)
t(i) = New TextBox
t(i).Top = i * 28
t(i).Left = 9
t(i).Width = 55
t(i).TextAlign = HorizontalAlignment.Center
GroupBox5.Controls.Add(t(i))
ReDim Preserve w(i)
w(i) = New TextBox
w(i).Top = i * 28
w(i).Left = 9
w(i).Width = 55
w(i).TextAlign = HorizontalAlignment.Center
GroupBox6.Controls.Add(w(i))
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
r = New Random()
num = Val(ComboBox1.Text)
For i = 1 To num
rbt = r.Next(1, 15)
rat = r.Next(0, 10)
rp = r.Next(1, 5)
rq = r.Next(1, 7)
b(i).Value = rbt
a(i).Value = rat
p(i).Value = rp
NumericUpDown1.Value = rq
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
ListBox2.Items.Clear()
ListBox3.Items.Clear()
ListBox4.Items.Clear()
ListBox5.Items.Clear()
ListBox6.Items.Clear()
TextBox1.Clear()
TextBox21.Clear()
TextBox22.Clear()
TextBox23.Clear()
TextBox24.Clear()
GroupBox5.Visible = True
GroupBox6.Visible = True
GroupBox7.Visible = True
GroupBox8.Visible = True
GroupBox10.Visible = False
GroupBox14.Controls.Clear()
tbt = 0
ttat = 0
twt = 0
num = Val(ComboBox1.Text)
For i = 1 To num
Dim bt = b(i).Value
Dim at = a(i).Value
Dim pr = p(i).Value
Dim id = i
Dim ft = 0
Dim tat = 0
Dim wt = 0
Dim t = 0
Dim bto = b(i).Value
ReDim Preserve job(i)
ReDim Preserve temp(i)
ReDim Preserve temp2(i)
temp(i) = New job(bt = 0, at = 0, pr = 0, id = 0, ft = 0, tat = 0, wt = 0, t = 0, bto = 0)
job(i) = New job(bt, at, pr, id, ft, tat, wt, t, bto)
ListBox1.Items.Add(a(i).Value)
Next
sortAT()
For i = 1 To num
ListBox2.Items.Add(job(i).getAT)
ListBox3.Items.Add(job(i).getID)
Next
'SJF routine
For i = 1 To num
If i = 1 Then
job(i).ft = job(i).getBT + job(i).getAT
ElseIf job(i).getBT > job(i - 1).ft Then
job(i).ft = job(i).getAT + job(i).getBT
Else
job(i).ft = job(i - 1).getFT + job(i).getAT
End If
ListBox4.Items.Add(job(i).ft)
ListBox5.Items.Add(job(i).getAT)
Next
For i = 1 To num
job(i).tat = job(i).ft - job(i).getBT
t(job(i).getID).Text = job(i).tat
job(i).wt = job(i).tat - job(i).getAT
w(job(i).getID).Text = job(i).wt
Next
totBT()
totTAT()
totWT()
aveTAT()
aveWT()
util()
tru()
TextBox23.Text = cpuu
TextBox21.Text = atat
TextBox24.Text = tp
TextBox22.Text = awt
'max slots in gant chart and turn of jobs to enter micro
max = num
turn = 1
For i = 1 To num
If i = 1 Then
If job(i).getBT <> 0 Then
max = max + 1
job(i).t = turn + 1
turn = turn + 1
Else
job(i).t = turn
End If
End If
If i > 1 Then
If job(i).getBT > job(i - 1).getAT Then
max = max + 1
job(i).t = turn + 1
turn = turn + 1
Else
job(i).t = turn
End If
End If
turn = turn + 1
ListBox6.Items.Add(job(i).t)
Next
TextBox1.Text = max
TextBox2.Text = turn - 1
'gant chart
GroupBox14.Visible = True
For i2 = 1 To max
ReDim Preserve g(i2)
g(i2) = New TextBox
g(i2).TextAlign = HorizontalAlignment.Center
g(i2).Left = i2 * 40 - 30
g(i2).Width = 40
g(i2).Top = 20
GroupBox14.Controls.Add(g(i2))
Next
For i2 = 1 To max
For i = 1 To num
If job(i).t = i2 Then
g(i2).Text = "Job " & job(i).getID
End If
Next
If g(i2).Text = "" Then
g(i2).Text = "Idle"
End If
Next
End Sub
Public Sub sortAT()
For i2 = 1 To num
For i = 1 To num - 1
If job(i).getBT < job(i + 1).getAT Then
temp(i) = job(i)
job(i) = job(i + 1)
job(i - 1) = temp(i)
End If
Next
Next
End Sub
Public Sub sortPR()
For i2 = 1 To ListBox5.Items.Count()
For i = 1 To ListBox5.Items.Count() - 1
If (npp(i).getPR > npp(i + 1).getPR) Then
temp(i) = npp(i)
npp(i) = npp(i + 1)
npp(i + 1) = temp(i)
End If
Next
Next
End Sub
Public Sub totBT()
For i = 1 To num
tbt = tbt + job(i).bto
Next
End Sub
Public Sub totTAT()
For i = 1 To num
ttat = ttat + job(i).tat
Next
End Sub
Public Sub util()
cpuu = (tbt / job(num).ft) * 100
End Sub
Public Sub aveTAT()
atat = ttat / num
End Sub
Public Sub tru()
tp = (num / job(num).ft)
End Sub
Public Sub aveWT()
awt = (twt / num)
End Sub
Public Sub totWT()
For i = 1 To num
twt = twt + job(i).wt
Next
End Sub
Public Sub sortBT()
For i2 = 1 To ListBox5.Items.Count()
For i = 1 To ListBox5.Items.Count() - 1
If (sjf(i).getAT > sjf(i + 1).getBT) Then
temp(i) = sjf(i)
sjf(i) = sjf(i + 1)
sjf(i + 1) = temp(i)
End If
Next
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GroupBox1.Visible = True
GroupBox2.Visible = True
GroupBox3.Visible = True
GroupBox4.Visible = False
GroupBox5.Visible = False
GroupBox6.Visible = False
GroupBox7.Visible = False
GroupBox8.Visible = False
GroupBox10.Visible = False
GroupBox13.Visible = False
GroupBox14.Visible = False
End Sub
Private Sub GroupBox4_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox4.Enter
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
End Class pAnUwAy -1 Newbie Poster
can i see the form of this program?
TnTinMN commented: do you really think that someone who has not visited the site in 3 yrs is going to respond? -1
Reverend Jim 6,681 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
We appreciate your willingness to contribute but please check the dates on posts before you respond to them This thread is more than three years old and it is likely that the original poster (OP) no longer needs help with this issue. Reviving this thread pushes more recent threads further down the list. If you continue to revive old threads you may be hit with an infraction.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.