Hello Guys,
I'm trying to simulate first fit and best fit simulation algorithm (memory management) using macro and I'm having a problem with the function I created.
The function has no bug but it only works once and once it's done, it will no longer scan the four labelbox I added and the "winner" integer will remain "0"
I'm trying to simulate first fit and best fit simulation algorithm (memory management) using macro and I'm having a problem with the function I created.
The function has no bug but it only works once and once it's done, it will no longer scan the four labelbox I added and the "winner" integer will remain "0"
Code:
Private Sub BF_Btn_Add_Click()
Dim x As Integer
Dim proname As String
Dim prosize As Double
Dim winner As Double
'For my iteration to get the lowest value possible
winner = 1E+308
Dim result() As Double
'Prompts------------
proname = LCase(InputBox("Please enter the name of your process", "What's the name of your process?"))
prosize = InputBox("Please enter the size of your process", "What's the size of your process?")
'Loop will store the values of four textboxes and subtract the prosize. If the given process box (labelbox) has &HBF00& color, then it means that there is already a process occupied there
For x = 1 To 4
If Controls("BF_lbl_Process" & x).BackColor <> &HBF00& Then
ReDim Preserve result(x)
result(x) = CDbl(Controls("BF_Text" & x).Text) - prosize
End If
Next x
'Loop will check the array and store the lower to "winner"
For x = 1 To UBound(result)
If result(x) < winner And result(x) >= 0 Then
winner = result(x)
End If
Next x
'Check if it is the lowest
MsgBox ("Winner: " & winner)
'Loop will then look for the specific process box where the winner was found based from winner and change the labelbox property to make sure that it will not be included in the next loop
For x = 1 To 4
MsgBox (CDbl(Controls("BF_Text" & x).Text) & vbCrLf & prosize & vbCrLf & CDbl(Controls("BF_Text" & x).Text) + prosize)
If CDbl(Controls("BF_Text" & x).Text) - prosize = winner Then
MsgBox ("True")
If Controls("BF_lbl_Process" & x).BackColor <> &HBF00& Then
With Controls("BF_lbl_Process" & x)
.Caption = proname
.BackColor = &HBF00&
End With
Controls("BF_lbl_IF" & x).Caption = CDbl(Controls("BF_Text" & x).Text) - prosize
Exit For
End If
End If
Next x