我需要在一个文本框中保持前导零,用于将数据输入到数据库中。它用于SKU编号。我需要能够键入前导零(例如001234567890),然后将它们输入数据库。
但是,我想不出如何将前导零保持为双精度。我不需要字符串格式,而是双精度格式。有没有办法在保留数字而不是字符串的同时做到这一点?
例如。
txtProductBarcode.Text = Format(txtProductBarcode.Text, "############")
'This does not work发布于 2018-05-26 13:50:12
试试看这就是其中之一。您可以将整数num转换为双精度。
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim num As Integer
Dim temp As String = ""
Try
If Regex.IsMatch(TextBox1.Text, "^[0-9 ]+$") Then
num = Integer.Parse(TextBox1.Text)
If num <> 0 then
TextBox1.Text = num.ToString("D6")
temp = num
else
TextBox1.ReadOnly = False
End If
If num.Length = 6 Then
TextBox1.ReadOnly = True
TextBox1.BackColor = Color.White
ElseIf num = 0 Then
TextBox1.ReadOnly = False
End If
TextBox1.SelectionStart = TextBox1.Text.Length
End If
Catch ex As Exception
Msgbox(ex.Message)
End Try
End Subhttps://stackoverflow.com/questions/12592739
复制相似问题