formatting with decimal places

bones

Well-known member
Joined
Aug 23, 2014
Messages
143
Programming Experience
Beginner
I've looked at numerous formatting examples...some with minimal code...some not...
Thinking if I can nail this formatting here then I can eliminate all the code to format the DGV cells that I have been using.

VB.NET:
'Valve Diameter Change
        Dim vdiam = Val(Me.TextBox1.Text)  
        Dim varea = vdiam * vdiam * 0.7854
        Dim count = Val(Me.TextBox7.Text) 
        Dim factor = vdiam * 3.14


        For Each r As DataGridViewRow In Me.DGV1.Rows


            'Populates Valve Cd Column using formula Cd = CFM / (Valve Diameter * 3.14 * lift) * 146
            r.Cells(5).Value = CDbl(r.Cells(2).Value) / ((factor * CDbl(r.Cells(0).Value)) * 146) ----------<<<<<< want the result in r.cells(5) formatted for 3 decimal places


            'Populates Effective Flow Area Column using formula EFA = Cd * (3.14 * lift)
            r.Cells(6).Value = CDbl(r.Cells(5).Value) * (factor * CDbl(r.Cells(0).Value))


            'Populates Actual Flow Area Column using Formula AFE = (vdiam * 3.14 * lift) 
            r.Cells(7).Value = factor * CDbl(r.Cells(0).Value)


            'Populates CFM -Sq.In Column using formula = CFM / Valve Area 
            r.Cells(4).Value = CDbl(r.Cells(2).Value) / varea


            'Calculations Valve Area
            Me.TextBox9.Text = CStr(varea * count) -----<<<<<<<<< I want the value in this textbox  to have 3 decimal places.  Have tried Cdbl instead of Cstr and fiddled with code..no luck
 
You're assigning to TextBox.Text property that is type String. Whatever you assign there must be converted to String first. In your code you convert the number with CStr function, instead use value.ToString and format the string as requested.
 
You're assigning to TextBox.Text property that is type String. Whatever you assign there must be converted to String first. In your code you convert the number with CStr function, instead use value.ToString and format the string as requested.


Cstr was no in my code originally. That was the result of turning on that wonderful Option Strict feature :eek:range:

When I hover Cstr or Cdbl I get the definition... Both are objects. So am I to understand that a textbox is not an object??
 
Back
Top