' several layers of dielectric
Type layer
    d As Double     ' layer thickness in metre
    er As Double    ' relative permittivity
    vpm As Double   ' dielectric strength, V/m
    c As Double     ' capacitance of this layer
    vbd As Double   ' breakdown voltage of this layer
    qx As Double    ' maximium charge on layer
End Type
Dim As Integer i, n = 3    ' number of layers
Dim layer( 1 To n ) As layer
' initialise
Dim As Double area = 0.01   ' area of dielectric
' for each layer    d        er    vpm   c vbd qx
layer( 1 ) = Type( 0.001 ,    2,   5e6,  0, 0, 0 )
layer( 2 ) = Type( 0.0015,    5,   1e5,  0, 0, 0 )
layer( 3 ) = Type( 0.0001,   22,   5e5,  0, 0, 0 )
Const As Double Eo = 8.8541878128e-12   ' Farad / metre
Dim As Double elast = 0     ' elastance = 1 / capacitance
Dim As Double d_total = 0   ' total thickness
Dim As Double q_min = 1e30  ' minimum breakdown charge
' compute each layer, sum and select
For i = 1 To 3
    With layer( i )
        ' compute for this layer
        .c = Eo * .er * area / .d   ' capacitance
        .vbd = .d * .vpm            ' breakdown voltage
        .qx = .c * .vbd             ' limiting Q, from C = Q / V
        ' gather for later
        If Q_min > .qx Then Q_min = .qx ' find lowest charge limit
        elast += 1 / .c             ' sum the elastance
        d_total += .d               ' sum of thickness
    End With
Next i
' final combined
Dim As Double c_total = 1 / elast
Dim As Double v_total = 0
For i = 1 To n
    v_total += Q_min / layer( i ).c
Next i
Print " Series capacitance ="; c_total; " farad "
Print " Breakdown voltage  ="; v_total; " volts "
Print
Print " Average dielectric strength ="; v_total / d_total; " V/m"
Print " Average dielectric constant ="; d_total * c_total / ( Eo * area )
Print