If p1at.Text = 0 Then
p1ts = p1at.Text
p1tc = p1bt.Text
t1.Text = p1ts
t2.Text = p1tc
If p1tc > p2at.Text Then
p2tc = Val(p1tc) + Val(p2bt.Text)
t3.Text = p2tc
Else
p2tc = Val(p1tc - p2bt.Text) + Val(p2bt.Text)
t3.Text = p2tc
If p2tc > p2at.Text Then
p3tc = Val(p2tc) + Val(p3bt.Text)
t4.Text = p3tc
Else
p3tc = Val(p2tc - p3bt.Text) + Val(p3bt.Text)
t4.Text = p2tc
end if
end if
end if

there is a problem with my code. help. ..

Dani AI

Generated

is implementing FCFS scheduling and was right to ask for clearer code. The robust approach is: parse numeric inputs into a process list, sort by arrival time, then simulate the timeline. For each process i compute the start time as the later of its arrival and the previous completion, then completion = start + burst. Waiting and turnaround follow directly from those two values.

Key formulas (use integers or doubles, not raw Text strings):
Start[i] = Max(Arrival[i], Completion[i-1])
Completion[i] = Start[i] + Burst[i]
Waiting[i] = Start[i] - Arrival[i]
Turnaround[i] = Completion[i] - Arrival[i]
Idle between processes occurs when Arrival[i] > Completion[i-1] (idle = Arrival[i] - Completion[i-1]).

A concise VB.NET implementation keeps logic separate from UI, validates inputs with TryParse, and uses a stable sort so equal arrival times preserve input order. Example core routine:

Class Job
    Public Property Id As Integer
    Public Property Arrival As Integer
    Public Property Burst As Integer
    Public Property StartTime As Integer
    Public Property CompletionTime As Integer
    Public Property Waiting As Integer
    Public Property Turnaround As Integer
End Class

Function CalculateFCFS(jobs As List(Of Job)) As List(Of Job)
    jobs = jobs.OrderBy(Function(j) j.Arrival).ToList()
    Dim current As Integer = 0
    For Each j In jobs
        j.StartTime = Math.Max(j.Arrival, current)
        j.CompletionTime = j.StartTime + j.Burst
        j.Waiting = j.StartTime - j.Arrival
        j.Turnaround = j.CompletionTime - j.Arrival
        current = j.CompletionTime
    Next
    Return jobs
End Function

Troubleshooting: validate conversions with Integer.TryParse, avoid VB6-era Val for user input, and check off-by-one mistakes when updating current. Test with several arrival-order and tie cases to confirm idle-time handling and averages. For a quick theory reference see .

Recommended Answers

All 2 Replies

Yep there is a problem. It's not enclosed in code tags, nor does it come with anything to explain what it is trying to accomplish.

commented: could not agree more. :D +1

Yep there is a problem. It's not enclosed in code tags, nor does it come with anything to explain what it is trying to accomplish.

cpu scheduling FCFS
the user can input 3 process state
this is the logic : smallest time + burst time = sum1
if the next arrival time is less than the sum1 then add the next burst time
but if the next arrival time is greater than the sum1 then subtract the sum1 to the arrival time so you will get the difference1. after that the difference1 must be added to the sum1 then add the burst time. that is the cycle.

what do you think is the appropriate formula with this. hope you can help me

at - arrival time
bt - burst time
I - idle
for example the user input 3 process
process 1 - at = 5
bt - 5
process 2 - at - 2
bt - 2
process 3 - at - 12
bt - 3
I P2 P1 P3
0 2 4 10 15

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.