Question To pad a numeric value with leading zeros to a specific length

Rishad Hasan

Member
Joined
Feb 1, 2013
Messages
8
Programming Experience
Beginner
Hello Everyone,

I know the help I am asking for probably very easy but I tried in several ways, didn't work properly. I have a AC database where I stored partnumbers with dash behind it.I have a textbox in windows form. If user's input is more than 4, say 5,then it'll show up in output csv file like that: 510424-005, if 17, then 510424-017. But I am only getting 510424-7 or 510424-17. I tried with fmt with ToString, didn't work. I am attaching my code. Please suggest me in this code. Thanks.

Private Sub ButtonOutputCSV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOutputCSV.Click

out = My.Computer.FileSystem.OpenTextFileWriter(file, False)



Dim op As Integer
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
dbProvider = "Provider=Microsoft.ace.oledb.12.0;"
dbSource = "Data Source=U:\TRatul\JB3 Configurator\JB3.accdb"


con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT*FROM Head"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Head")
con.Close()
Dim t1 As DataTable = ds.Tables("Head")

Dim i As Integer

For i = 0 To 7


If TextBoxNoseLength.Text > 4 Then

If Not IsDBNull(t1.Rows(i).Item("Lo_Input")) Then
findPartNumberforHead()
op = 10
If partNumber <> "0" Then WR(partNumber + Str(Val(TextBoxNoseLength.Text)), 1, op, "Head")
End If
Else

If Not IsDBNull(t1.Rows(i).Item("Lo_Input")) Then
findPartNumberforHead()
op = 10
If partNumber <> "0" Then WR(partNumber, 1, op, "Head")
End If
End If

Exit For


Next i

out.Close()

Shell("notepad C:\Webster\Test.txt")


End Sub


 
Hello JohnH, I went to that link but didnot work for me because I am having trouble to implement that idea. I already pasted my code here. Would you mind looking at my last part of this code and help me to rewrite it with implementing that padleft method.

Thanks.
 
Hello JohnH, I went to that link but didnot work for me because I am having trouble to implement that idea. I already pasted my code here. Would you mind looking at my last part of this code and help me to rewrite it with implementing that padleft method.

Thanks.

How about you show us how you tried to use PadLeft so we can see what you did wrong.
 
Back
Top