Consulting

Results 1 to 4 of 4

Thread: Line Graph

  1. #1
    VBAX Newbie
    Joined
    Mar 2009
    Posts
    2
    Location

    Line Graph

    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:

    [VBA]
    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
    [/VBA]
    Thank you.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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

    [VBA]
    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

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Newbie
    Joined
    Mar 2009
    Posts
    2
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •