PDA

View Full Version : Line Graph



versegi
03-21-2009, 07:45 AM
Hello,

I am complete beginner in VBA, any kind of help is welcome.

I am trying to create program which will calculate water level inside of the tank based on inflow and outflow, and to graph tank water level. This will be simple line graph showing Water Level Vs. Time.
So far I started creating my input and variables but I am completely lost when it comes to creating graph.

This is what I have so far:


Private Sub CommandButton1_Click()
Dim Inflow As Integer
Dim PumpCapacity As Integer
Dim SumpLength As Integer
Dim SumpWidth As Integer
Dim SumpDiameter As Integer
Dim SumpHeight As Integer
Dim TreatmentPlantCapacity As Integer
Dim TreatmentTankVolume As Integer
Dim PumpOn As Integer
Dim PumpOff As Integer
Dim IntervalBetweenPumpOnAndOff As Integer
Dim SumpPumpVolume As Integer
Inflow = TextBox1.Text
PumpCapacity = TextBox2.Text
SumpLength = TextBox3.Text
SumpWidth = TextBox4.Text
SumpDiameter = TextBox5.Text
SumpHeight = TextBox6.Text
TreatmentPlantCapacity = TextBox7.Text
TreatmentTankVolume = TextBox8.Text
PumpOn = SumpHeight - 2
PumpOff = 2
If OptionButton11 Then
IntervalBetweenPumpOnAndOff = ((PumpOn - PumpOff) * SumpLength * SumpWidth) * 7.44 / PumpCapacity
SumpPumpVolume = SumpHeight * SumpLength * SumpWidth * 7.55
Else
IntervalBetweenPumpOnAndOff = ((PumpOn - PumpOff) * 3.14 * 0.25 * SumpDiameter * SumpDiameter) * 7.44 / PumpCapacity
SumpPumpVolume = SumpHeight * 3.14 * 0.25 * SumpDiameter * SumpDiameter * 7.5
End If
TextBox9 = PumpOn
TextBox10 = PumpOff
TextBox11 = IntervalBetweenPumpOnAndOff
TextBox12 = SumpPumpVolume
End Sub

Thank you.

Bob Phillips
03-21-2009, 09:30 AM
Hi versegi,

Welcome to VBA.

I think we need more to help.

Can you post a workbook with the graph you want based upon some worksheet data, it should be straight-forward after that.

mdmackillop
03-21-2009, 09:31 AM
Welcome to VBAX
You need to create some spreadsheet output from your userform, which would be the DataSource for your Chart. In this case Time is one of your Chart axes, so you would need include this variable in your calculation. I've applied it in a simple fashion to your code. Time could also be read in from a column of data if appropriate.
Regards
MD


Dim Tim As Long
For Tim = 1 To 60

If OptionButton11 Then
IntervalBetweenPumpOnAndOff = ((PumpOn - PumpOff) * SumpLength * SumpWidth) * 7.44 / PumpCapacity * Tim
SumpPumpVolume = SumpHeight * SumpLength * SumpWidth * 7.55

Else
IntervalBetweenPumpOnAndOff = ((PumpOn - PumpOff) * 3.14 * 0.25 * SumpDiameter * SumpDiameter) * 7.44 / PumpCapacity * Tim
SumpPumpVolume = SumpHeight * 3.14 * 0.25 * SumpDiameter * SumpDiameter * 7.5
End If
Cells(Tim, 1) = Tim
Cells(Tim, 2) = IntervalBetweenPumpOnAndOff
Next

versegi
03-21-2009, 10:33 AM
Attached is spreadsheet and graph that I would like to get using VBA programm.

I created this, but would love to be able to make it more sophisticated.

Thank you all for help and inputs.

Goran