在 VBA 中格式化文本框 4 位小数

发布于 2024-12-07 16:42:00 字数 215 浏览 0 评论 0原文

无论如何,您是否可以将文本框格式设置为始终具有四位小数?我知道如何使用 C# 和 Visual Basic 使用屏蔽文本框来完成此操作,但由于缺乏功能,vba 更具挑战性。任何帮助将不胜感激。谢谢

Public Sub UserForm_Initialize()
TextBox6.Text = Format(Number, "###.####")
End Sub

Is there anyway that you can format a textbox format to have four decimal places at all time? I know how to do it with C# and Visual Basic using a masked textbox, but vba is a bit more challeging due to the lack of function. Any help would be greatly appreciated. Thanks

Public Sub UserForm_Initialize()
TextBox6.Text = Format(Number, "###.####")
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终陌 2024-12-14 16:42:00

您只是格式字符串不正确。它应该看起来像这样:

Public Sub UserForm_Initialize()
    TextBox6.Text = Format(Number, "0.0000")
End Sub

You just have the format string incorrect. It should look like this:

Public Sub UserForm_Initialize()
    TextBox6.Text = Format(Number, "0.0000")
End Sub
厌味 2024-12-14 16:42:00

尝试:

Public Sub UserForm_Initialize()
     TextBox6.Text = Format(Number, "0.0000")
End Sub

Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If IsNumeric(TextBox6.Value) Then
        TextBox6.Text = Format(TextBox6, "0.0000")
    End If
End Sub

Private Sub TextBox6_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    '// Disregard keys other than 0-9/period/minus sign.
    If Shift Then KeyCode = 0
    Select Case KeyCode
    Case 8, 13, 46, 48 To 57, 96 To 105, 109, 110, 189, 190
    Case Else
        KeyCode = 0
    End Select
End Sub

Try:

Public Sub UserForm_Initialize()
     TextBox6.Text = Format(Number, "0.0000")
End Sub

Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If IsNumeric(TextBox6.Value) Then
        TextBox6.Text = Format(TextBox6, "0.0000")
    End If
End Sub

Private Sub TextBox6_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    '// Disregard keys other than 0-9/period/minus sign.
    If Shift Then KeyCode = 0
    Select Case KeyCode
    Case 8, 13, 46, 48 To 57, 96 To 105, 109, 110, 189, 190
    Case Else
        KeyCode = 0
    End Select
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文