vb中是的文本框输入数字自动以千为分隔加逗号

vb中是的文本框输入数字自动以千为分隔加逗号,第1张

概述添加个输入框text1,然后复制下面代码即可。 Private Sub Text1_Change() setFormat Text1End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) If Not ((KeyAscii > 48 And KeyAscii < 57) Or KeyAscii = 8 Or KeyAscii

添加个输入框text1,然后复制下面代码即可。


Private Sub Text1_Change()    setFormat Text1End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)    If Not ((KeyAscii > 48 And KeyAscii < 57) Or KeyAscii = 8 Or KeyAscii = 46 Or ((KeyAscii = 43 Or KeyAscii = 45) And Text1.SelStart = 0)) Then KeyAscii = 0End SubPrivate Sub setFormat(objTxt As TextBox)    Dim v,strNew$,s1$,intSelStart%    Dim reg As Object    Set reg = CreateObject("vbscript.regExp")    reg.Global = True    If objTxt.Text = "" Then Exit Sub    v = Split(objTxt.Text,".")    s1 = v(0)    v(0) = Replace(v(0),","")    reg.Pattern = "(\d{3})"    v(0) = StrReverse(reg.Replace(StrReverse(v(0)),",")) '每隔3数字加逗号    reg.Pattern = "^([^\d]*?),"    v(0) = reg.Replace(v(0),"")    intSelStart = objTxt.SelStart    objTxt.Text = Join(v,".")    objTxt.SelStart = intSelStart + Len(v(0)) - Len(s1)End Sub
总结

以上是内存溢出为你收集整理的vb中是的文本框输入数字自动以千为分隔逗号全部内容,希望文章能够帮你解决vb中是的文本框输入数字自动以千为分隔加逗号所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1265963.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存