Hi,
I am using Visual Basic, not Java.
Sending the code so you can see what I do.
--------------------------------------------------------------------
Sub Show_status(cab_opt_eff, cab_pen_tot, i, improv, nmx, nummx)
Dim Status As Object
Dim NewLabel As MSForms.Label
Dim tit(1 To 10) As String
Dim X As Integer
Dim pr(1 To 5) As Double
'This is to stop screen flashing while creating form
Application.VBE.MainWindow.Visible = False
Set Status = ThisWorkbook.VBProject.VBComponents.Add(3)
'Create the User Form
With Status
.Properties("Caption") = "Optimisation Status"
.Properties("Width") = 800
.Properties("Height") = 300
End With
Set NewLabel = Status.designer.Controls.Add("Forms.label.1")
With NewLabel
.Name = "FieldLabel" & X + 1
.Caption = "Performance"
.Top = 20
.Left = 20
.Width = 100
.Height = 16
.Font.Size = 8
.Font.Name = "Arial"
.Font.Bold = True
.Font.Underline = True
End With
'Create year titles
For X = 2012 To 2018
Set NewLabel = Status.designer.Controls.Add("Forms.label.1")
With NewLabel
.Name = "FieldLabel" & X + 1
.Caption = X
.Top = 20
.Left = 200 + (X - 2012) * 75
.Width = 75
.Height = 16
.Font.Size = 8
.Font.Name = "Arial"
.Font.Bold = True
.Font.Underline = True
End With
Next X
'Create performance titles
tit(1) = "Optimisation efficiency"
tit(2) = "Total cabinet penalty"
tit(3) = "Number of iterations"
tit(4) = "Number of improvements"
tit(5) = "Maximum number"
For X = 1 To 6
Set NewLabel = Status.designer.Controls.Add("Forms.label.1")
With NewLabel
.Name = "FieldLabel" & X + 1
.Caption = tit(X)
.Top = 20 + X * 25
.Left = 20
.Width = 150
.Height = 16
.Font.Size = 8
.Font.Name = "Arial"
.Font.Bold = True
End With
Next X
For y = 2012 To 2018
' pr(1) = Format((cab_opt_eff
- cab_pen_tot
) / cab_pen_tot
, "#.##%")
pr(1) = (cab_opt_eff
- cab_pen_tot
) / cab_pen_tot
pr(2) = Format(cab_pen_tot
, "###,###,###")
pr(3) = i
pr(4) = improv
pr(5) = nummx
For r = 1 To 5
Set NewLabel = Status.designer.Controls.Add("Forms.label.1")
With NewLabel
' .Name = "FieldLabel" & r + 1
.Caption = pr(r)
.Top = 20 + r * 25
.Left = 200 + (y - 2012) * 75
.Width = 150
.Height = 16
.Font.Size = 8
.Font.Name = "Arial"
' .Font.Bold = True
End With
Next r
Next y
'Show the form
If improv(2012) = 1 Then
VBA.UserForms.Add(Status.Name).Show vbModeless
DoEvents
Else
VBA.UserForms.Add(Status.Name).Repaint vbModeless
DoEvents
End If
End Sub
----------------------
I also have problems with format numbers in the userform, see commented line after the for statement.
Stefan