![]() |
decimals in textboxes
I am trying to limit the decimals in a textbox to 2 can
anyone help me with this ? the fixeddecimals etc. does not work. Thanks JdJ |
decimals in textboxes
JdJ
many hours have been spent by programmers because MS was too lazy to implement a few often needed properties to the textbox object in msforms. shall we say it allows for flexibility? Following works for me (Excel97+), also with non-english regional settings Option Explicit Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) KeyAscii.Value = FilterInput(TextBox1.Text, KeyAscii.Value) End Sub Function FilterInput(s As String, ByVal k As Integer) As Integer Dim sDec As String, sKey As String, number As Variant On Error GoTo TheEnd With Application sDec = .International(xlDecimalSeparator) #If VBA6 Then If Not .UseSystemSeparators Then sDec = .DecimalSeparator #End If End With sKey = Chr(k) If sKey = "." And sKey < sDec Then sKey = sDec If s = "" And (sKey = "-" Or sKey = sDec) Then FilterInput = Asc(sKey) ElseIf sKey Like "[0123456789" & sDec & "]" Then number = CDec(s & sKey) If number = WorksheetFunction.Round(number, 2) Then FilterInput = Asc(sKey) End If End If TheEnd: End Function cheerz! keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "jdj" wrote: I am trying to limit the decimals in a textbox to 2 can anyone help me with this ? the fixeddecimals etc. does not work. Thanks JdJ |
decimals in textboxes
Hi keepITcool
Tried it, but still no results. Thanks anyway !! JdJ -----Original Message----- JdJ many hours have been spent by programmers because MS was too lazy to implement a few often needed properties to the textbox object in msforms. shall we say it allows for flexibility? Following works for me (Excel97+), also with non-english regional settings Option Explicit Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) KeyAscii.Value = FilterInput(TextBox1.Text, KeyAscii.Value) End Sub Function FilterInput(s As String, ByVal k As Integer) As Integer Dim sDec As String, sKey As String, number As Variant On Error GoTo TheEnd With Application sDec = .International(xlDecimalSeparator) #If VBA6 Then If Not .UseSystemSeparators Then sDec = .DecimalSeparator #End If End With sKey = Chr(k) If sKey = "." And sKey < sDec Then sKey = sDec If s = "" And (sKey = "-" Or sKey = sDec) Then FilterInput = Asc(sKey) ElseIf sKey Like "[0123456789" & sDec & "]" Then number = CDec(s & sKey) If number = WorksheetFunction.Round(number, 2) Then FilterInput = Asc(sKey) End If End If TheEnd: End Function cheerz! keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "jdj" wrote: I am trying to limit the decimals in a textbox to 2 can anyone help me with this ? the fixeddecimals etc. does not work. Thanks JdJ . |
decimals in textboxes
are u working with an embedded control or a textbox on a userform?
keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "JdJ" wrote: Hi keepITcool Tried it, but still no results. Thanks anyway !! JdJ |
decimals in textboxes
Userform.
Johann -----Original Message----- are u working with an embedded control or a textbox on a userform? keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "JdJ" wrote: Hi keepITcool Tried it, but still no results. Thanks anyway !! JdJ . |
decimals in textboxes
While you'r helping me, and I am grateful for your
effort, I have another problem ; Activating a form that contains multipages, how can I get the first page to always show? It normally opens the page where you exited. Thanks again Maistro ! Johann -----Original Message----- are u working with an embedded control or a textbox on a userform? keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "JdJ" wrote: Hi keepITcool Tried it, but still no results. Thanks anyway !! JdJ . |
decimals in textboxes
check the sequence of any other eventshandlers running on the box? no conflicts there? Set breakpoints to see where the code exits (and if it gets there in the first place). Preferably use e few debug.print lines : This proc works with keyboard buffer. Using mouse in VBE is okay but typing (editing) will interfere with that buffer. keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "JdJ" wrote: Userform. Johann -----Original Message----- are u working with an embedded control or a textbox on a userform? keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "JdJ" wrote: Hi keepITcool Tried it, but still no results. Thanks anyway !! JdJ . |
decimals in textboxes
multipage1.value=1 keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "Johann" wrote: While you'r helping me, and I am grateful for your effort, I have another problem ; Activating a form that contains multipages, how can I get the first page to always show? It normally opens the page where you exited. Thanks again Maistro ! |
decimals in textboxes
Thanks - working !
Johann -----Original Message----- multipage1.value=1 keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "Johann" wrote: While you'r helping me, and I am grateful for your effort, I have another problem ; Activating a form that contains multipages, how can I get the first page to always show? It normally opens the page where you exited. Thanks again Maistro ! . |
decimals in textboxes
Well all that I did was to when the form activates to
read the value of a range eg. textbox1.value = range("B123").value But I follow your suggestions as well, don't really have time today, but I'll keep you posted. Thanks hey ! J -----Original Message----- check the sequence of any other eventshandlers running on the box? no conflicts there? Set breakpoints to see where the code exits (and if it gets there in the first place). Preferably use e few debug.print lines : This proc works with keyboard buffer. Using mouse in VBE is okay but typing (editing) will interfere with that buffer. keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "JdJ" wrote: Userform. Johann -----Original Message----- are u working with an embedded control or a textbox on a userform? keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "JdJ" wrote: Hi keepITcool Tried it, but still no results. Thanks anyway !! JdJ . . |
decimals in textboxes
Actually I believe it should be
Multipage1.Value = 0 for the first page since the pages count is zero based. from help on the Value property from the MS forms 2.0 help: MultiPage An integer indicating the currently active page. Zero (0) indicates the first page. The maximum value is one less than the number of pages. -- Regards, Tom Ogilvy JdJ wrote in message ... Thanks - working ! Johann -----Original Message----- multipage1.value=1 keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "Johann" wrote: While you'r helping me, and I am grateful for your effort, I have another problem ; Activating a form that contains multipages, how can I get the first page to always show? It normally opens the page where you exited. Thanks again Maistro ! . |
decimals in textboxes
You're dead right
At least I've got the right stuff now Thanks !!!! J -----Original Message----- Actually I believe it should be Multipage1.Value = 0 for the first page since the pages count is zero based. from help on the Value property from the MS forms 2.0 help: MultiPage An integer indicating the currently active page. Zero (0) indicates the first page. The maximum value is one less than the number of pages. -- Regards, Tom Ogilvy JdJ wrote in message ... Thanks - working ! Johann -----Original Message----- multipage1.value=1 keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "Johann" wrote: While you'r helping me, and I am grateful for your effort, I have another problem ; Activating a form that contains multipages, how can I get the first page to always show? It normally opens the page where you exited. Thanks again Maistro ! . . |
All times are GMT +1. The time now is 04:07 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com