Function As Decimal and How to OutPut to TextBox or Label

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Basically This Is a Calculator which I really need help with as you can tell, here is the code for
Water Based Mud Retort Analysis
I want to take the result of Each Function and Output to the Form, then Be able to Take Data Fill Excel SpreadSheet and Print Pretty simple yet my knowledge or lack thereof is hindering my abilities
If Someone can help me simplify this and maybe do a If Catch Try on Equation for errors that would help me out a lot thanks, just need a little more direction, getting errors on equations not sure if they are right...
ThanksPublic Class WaterBasedMudRetort
Objective Calculate Low Gravity Solids Content
Calculate High Gravity Solids Content
Send To Excel, Preview and Print with or without saving
Might Need Location Name input if Save Option Created
Dim WaterWeight = 8.34 Pounds Per Gallon
High Gravity Solids Density Range usually 4.1-4.2
Dim HGSDensity = 4.1 Pounds Per Gallon
Low Gravity Solids Density, Bentonite = 2.6
Dim LGSDensity = 2.6 Pounds Per Gallon
Specific Gravity of Specified Oil I.E. Diesel or Synthetic may way 0.75
Dim SGOil = 0.84 Pounds Per Gallon
Not Sure How to Convert 1000Mg/l to Decimal So I used 0.1grams
Dim ChloridesDensity = 0.1
Dim RWeightDry As Decimal Retort Sample Empty But With Steel Wool In Grams
Dim RWeightWet As Decimal Retort Sample With Sample in Grams
Dim RWeightCooked As Decimal Retort Sample After Cooking In Grams
Dim CorrectedSolids As Decimal Total Corrected Solids In Grams
Dim GBeakerDry As Decimal Weight Of Glass Beaker In Grams Empty, g
Dim GBeakerWet As Decimal Weight Of Glass Beaker After Cooking Retort, g
Dim MlsWater As Decimal Mls of Water In Glass Beaker, g
Dim Density As Decimal Mud Weight Denisty, ppg
Dim Chlorides As Decimal Total Chlorides in mg/l, I dont think this variable is required
Find Specific Gravity Of Saltwater Content
Dim SGSaltWater As Func(Of Decimal, Decimal) = Function(t As Decimal) (1 + (1.94 * (10 ^ -6)) * ChloridesDensity ^ 0.95)
Average Specific Gravity
Dim ASG As Func(Of Decimal, Decimal) = Function(t As Decimal) (((12 * Density) - (SaltWaterContent * 1) - (SGOil * OilContent))) / CorrectedSolids
Total Oil Content, Water Based Mud Should Result In 0% +-0.5%
Dim OilContent As Func(Of Decimal, Decimal) = Function(t As Decimal) ((GBeakerWet - GBeakerDry) - MlsWater)
Total Saltwater Conter In Percent
Dim SaltWaterContent As Func(Of Decimal, Decimal) = Function(t As Decimal) (RWeightCooked * ((1 + 5.88) * (10 ^ -8)) * (ChloridesDensity ^ 1.2))
Total LowGravity Solids Content
Dim LGSContent As Func(Of Decimal, Decimal) = Function(t As Decimal) (CorrectedSolids * (HGSDensity - ASG)) / (HGSDensity - LGSDensity)
Total High Gravity Solids Content, Can Be A Negative Number As Per Specific Gravity Barite is 4.1 and Bentonite is 2.6
Dim HGSContent As Func(Of Decimal, Decimal) = Function(t As Decimal) (CorrectedSolids - LGSContent)
Having The User Input Density

Public Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "" Then MsgBox("Please Enter Value of Mud Weight")
TextBox1.Text = Density
Density = Decimal.Parse(TextBox1.Text)
End Sub

Having User Input Retort Weight With Steel Wool But Empty

Private Sub TextBox2_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox2.TextChanged
If TextBox2.Text = "" Then MsgBox("Please Enter Weight Of Dry Retort With Steel Wool")
TextBox2.Text = RWeightDry
End Sub
Having User Input Retort Weight With Sample
Private Sub TextBox3_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox3.TextChanged
If TextBox3.Text = "" Then MsgBox("Please Enter Weight Of Retort With Sample")
TextBox3.Text = RWeightWet
End Sub
Having User Input Weight of Glass Beaker
Private Sub TextBox4_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox4.TextChanged
If TextBox4.Text > "" Then MsgBox("Please Enter Weight Of Dry Glass Beaker")
TextBox4.Text = GBeakerDry
End Sub
Having User Input Ml of Water After Retort Cooks
Private Sub TextBox5_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox5.TextChanged
If TextBox5.Text > "" Then MsgBox("Please Enter Mls Water")
TextBox5.Text = MlsWater

End Sub
Calculate End Result
Display End Result in a percentage
Export To Excel
Show Print Preview for Excel Spread Sheet
Print Document
End Class

View the full article
 
Back
Top