Grr, encountering really annoying issues.

R

Robert

I am having a bunch of code which i am using to dimension a vessel
filled with water. It can be seen like this:

On the one side I calculate how much the level drops in the vessel in
a time interval (numerical integration).
On the other side I created loads of blue labels, which changes
colours when the vessel is emptying. I am so close to the solution. I
can smell it. But why oo why doesnt it go the way I want it.

The program executes by a commandbutton and click event. I want to
make this completely automatic so you only have to click once!

NOW then.. this is the siuation.

When the code executes. It calculates a value and puts it in a cell.
Then it checks the value and switches the colour of a label. WORKS
GREAT!!!

but it works great everytime I click the button and click the button.
When I click the button 900 times. my vessel is empty.

So this is the code what I came (and help from the
excelprogramminggroupies) with:

I tried it with a Do..Loop event but what happens then is that the
whole thing is calculating, and only check the labels @ the end.

Sub EmptyVessel()

dt = 100
dia_vat = 0.5
Hoogte_vat = 1.2
Pi = 355 / 113
Cd = 0.85
Ag = 0.00002
g = 9.81
x_t_0 = 0
N_0 = 1.2
N_1 = 1
N_2 = 0.75
N_3 = 0.5
N_4 = 0.25

H_0_0 = Application.WorksheetFunction.Max((N_0 - x_t_0), 0)
H_1_0 = Application.WorksheetFunction.Max((N_1 - x_t_0), 0)
H_2_0 = Application.WorksheetFunction.Max((N_2 - x_t_0), 0)
H_3_0 = Application.WorksheetFunction.Max((N_3 - x_t_0), 0)
H_4_0 = Application.WorksheetFunction.Max((N_4 - x_t_0), 0)

Q_0_0 = Cd * Ag * Sqr(2 * g * H_0_0)
Q_1_0 = Cd * Ag * Sqr(2 * g * H_1_0)
Q_2_0 = Cd * Ag * Sqr(2 * g * H_2_0)
Q_3_0 = Cd * Ag * Sqr(2 * g * H_3_0)
Q_4_0 = Cd * Ag * Sqr(2 * g * H_4_0)

q_tot_0 = Q_0_0 + Q_1_0 + Q_2_0 + Q_3_0 + Q_4_0

x_t_t = Cells(13, "B").Value + (q_tot_0 / Pi * ((dia_vat / 2) ^ 2) *
dt)
Cells(14, "B").Value = x_t_t

H_0_t = Application.WorksheetFunction.Max((N_0 - x_t_t), 0)
H_1_t = Application.WorksheetFunction.Max((N_1 - x_t_t), 0)
H_2_t = Application.WorksheetFunction.Max((N_2 - x_t_t), 0)
H_3_t = Application.WorksheetFunction.Max((N_3 - x_t_t), 0)
H_4_t = Application.WorksheetFunction.Max((N_4 - x_t_t), 0)

Q_t_t = (Cd * Ag * Sqr(2 * g * H_0_t)) + (Cd * Ag * Sqr(2 * g *
H_1_t)) + (Cd * Ag * Sqr(2 * g * H_2_t)) + (Cd * Ag * Sqr(2 * g *
H_3_t)) + (Cd * Ag * Sqr(2 * g * H_4_t))

dx = Q_t_t * ((dia_vat / 2) ^ 2) * dt
If x_t_t <= 1.2 Then Cells(13, "B").Value = x_t_t + dx

' the label color check:

Dim y As Integer

For y = 1 To 86
If x_t_t > (y / 86) * 1.2 Then
Me.Controls("Label" & CStr(y - 1)).BackColor = vbBlack
Me.Controls("Label" & CStr(y - 1)).BorderColor = vbBlack
End If
Next y

End Sub
 
P

paul.robinson

Hi
Try
Me.Repaint
after changing the controls.

If that doesn't work try
DoEvents
after changing the controls.
regards
Paul
 
R

Robert

WOW, OMG!!!

When I tried Me.Repaint my computer totally flipped out!!

However, the DoEvents works PERFECTTT!!!

Thanks friend. You helped me to get on step closer on graduating. =]

Regards,

Robert.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top