• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

How do I pad a value, retrieved from a SQL database?

Friends,

How do I pad a value, retrieved from a SQL database?  In other words,  The value retireved is 41, but I need it to be held in a label as 41.0000?  How do I pad that number with extra zeros.  Also, How do I make it dynamic enough to pad it with one zero if the value is 41.111 to make it 41.1110?

Thanks in advance!

Here is the code I am working with:

    Public Sub UpdateDataInForm(ByVal dsn As String)

        Dim WUTime1 As Decimal
        Dim WUTime2 As Decimal
        Dim WUTime3 As Decimal
        Dim Lap1Time As Decimal
        Dim Lap2Time As Decimal
        Dim Lap3Time As Decimal
        Dim Lap4Time As Decimal
        Dim QualSpeed As Decimal
        Dim QualTime As Decimal

        Dim data As New DataSet
        Dim r As DataRow

        Dim ColumnCount As Integer

        Dim con As New SqlClient.SqlConnection(dsn)

        data = New DataSet

        Dim dr As SqlClient.SqlDataReader

        con = New SqlClient.SqlConnection(dsn)
        con.Open()

        Dim c As New SqlClient.SqlCommand("CurrentQualifierSP", con)
        dr = c.ExecuteReader(CommandBehavior.SingleResult)

        If dr.HasRows Then


            While dr.Read()
                lblCarNumber.Text = dr.Item("Car Number")
                lblDriver.Text = dr.Item("Driver")
                lblEquiptment.Text = dr.Item("Equipment")
                'lblEngine.Text = dr.Item("Engine")
                lblAttempt.Text = dr.Item("Attempt")
                Select Case NumberOfLapsToRun
                    Case 5
                        lblWarmUp1Speed.Enabled = True
                        lblWarmUp1Time.Enabled = True
                        lblWarmUp1Speed.Text = dr.Item("WarmUpLap1Speed") '<- This is an example of where this might need to be padded
                        lblWarmUp1Time.Text = dr.Item("WarmUpLap1Time")
                        lblWarmUp2Speed.Enabled = False
                        lblWarmUp2Time.Enabled = False
                        lblWarmUp3Speed.Enabled = False
                        lblWarmUp3Time.Enabled = False
                    Case 6
                        lblWarmUp1Speed.Enabled = True
                        lblWarmUp1Time.Enabled = True
                        lblWarmUp1Speed.Text = dr.Item("WarmUpLap1Speed")
                        lblWarmUp1Time.Text = dr.Item("WarmUpLap1Time")
                        lblWarmUp2Speed.Enabled = True
                        lblWarmUp2Time.Enabled = True
                        lblWarmUp2Speed.Text = dr.Item("WarmUpLap2Speed")
                        lblWarmUp2Time.Text = dr.Item("WarmUpLap2Time")
                        lblWarmUp3Speed.Enabled = False
                        lblWarmUp3Time.Enabled = False
                    Case 7
                        lblWarmUp1Speed.Enabled = True
                        lblWarmUp1Time.Enabled = True
                        lblWarmUp1Speed.Text = dr.Item("WarmUpLap1Speed")
                        lblWarmUp1Time.Text = dr.Item("WarmUpLap1Time")
                        lblWarmUp2Speed.Enabled = True
                        lblWarmUp2Time.Enabled = True
                        lblWarmUp2Speed.Text = dr.Item("WarmUpLap2Speed")
                        lblWarmUp2Time.Text = dr.Item("WarmUpLap2Time")
                        lblWarmUp3Speed.Enabled = True
                        lblWarmUp3Time.Enabled = True
                        lblWarmUp3Speed.Text = dr.Item("WarmUpLap3Speed")
                        lblWarmUp3Time.Text = dr.Item("WarmUpLap3Time")
                End Select

                lblLap1Time.Text = dr.Item("Lap1Time")
                Lap1Time = lblLap1Time.Text
                lblLap1Speed.Text = dr.Item("Lap1Speed")
                lblLap2Time.Text = dr.Item("Lap2Time")
                Lap2Time = lblLap2Time.Text
                lblLap2Speed.Text = dr.Item("Lap2Speed")
                lblLap3Time.Text = dr.Item("Lap3Time")
                Lap3Time = lblLap3Time.Text
                lblLap3Speed.Text = dr.Item("Lap3Speed")
                lblLap4Time.Text = dr.Item("Lap4Time")
                Lap4Time = lblLap4Time.Text
                lblLap4Speed.Text = dr.Item("Lap4Speed")

                If lblLap1Speed.Text = Nothing Or lblLap1Speed.Text = 0 Or lblLap1Speed.Text = "0" Then
                    lblQualifyingTime.Text = "No Time"
                    lblQualifyingSpeed.Text = "No Speed"
                Else
                    lblQualifyingTime.Text = dr.Item("QualifyingTime")
                    lblQualifyingSpeed.Text = dr.Item("QualifyingSpeed")
                End If


                QualificationStandings(dsn)

            End While
        Else
            'NoDataYet()
            QualificationStandings(dsn)
        End If
        con.Close()
        con = Nothing

    End Sub
0
indy500fan
Asked:
indy500fan
2 Solutions
 
softplusCommented:
function Padme$(value as Double)
   dim sPadded$
   sPadded = value.ToString("0.0000")
   if not sPadded.EndsWith("0") then sPadded &= "0"
   return sPadded
end function
Is that about what you were looking for?
0
 
wraith821Commented:
lblWarmUp2Time.Text = format(dr.Item("WarmUpLap2Time"),"#.0000")
0
 
indy500fanAuthor Commented:
I'm not sure what to do about the points guys...Softplus - I like your function, and I will probably use it in my next version, but right now I need something quick and wraith821's format works like I needed.

So how do I divey up the points?  

Eric
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Bob LearnedCommented:
Split, giving a little more to the solution that you like the best.

Bob
0
 
indy500fanAuthor Commented:
Hi Bob!  Yeah, that's what I wanted to do, but I never know how much to do for each.
0
 
Bob LearnedCommented:
Well, if they are both equally good solutions, then split evenly 250 per answer.  Fair and equitable.

Bob
0
 
indy500fanAuthor Commented:
Thanks!
0
 
indy500fanAuthor Commented:
And thank you to softplus and wraith821 for two great answers!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now