Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 . |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 ! |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 ! . |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . . |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 ! . |
#12
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 ! . . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Count digits before decimals and after decimals | Excel Worksheet Functions | |||
Textboxes | Excel Discussion (Misc queries) | |||
UserForm TextBoxes | Excel Discussion (Misc queries) | |||
tab between several textboxes | Excel Worksheet Functions | |||
Referencing Textboxes? | Excel Discussion (Misc queries) |