hello In vba forms , we are controling the numeric input with the keypress evenment. The control is good for decimal input . How can we do the same , but in inches input (decimal and/or fractionnal) ? If everyone has a dvb project , or a module , or an ocx , or explainations , please help us -- Cesi2d Luc Vallot Chemin du Bassard 38121 Chonas l ' amballan France Tel: 04 74 58 95 68
Hi... Hmmm, you may convert of inches to decimal and next do the control... Finaly again do the convert of decimal to inches. Just is a idea... Un saludo de SpeedCAD... CHILE FORO: http://www.hispacad.com/foro
Luc, In my opinion the best way from both a user and programming viewpoint is to separate the different unit types into their own entry boxes. That way the user does not have to bother with entering in a unit type. He would just know that one entry box was for the major unit and the next entry box was for the minor unit. You as programmer would not need to develop the entry parsing routine for all the variations of unit type ( ' or " or mm or MM or M etc.) It helps to provide instant feedback to the user as to what his entries equate to. This would be simply a Label in the userform that represents the entry inputs in a formatted form. So for example a 24.5 in the foot entry and a 27 in the inches entry would feedback as " 26' - 9" ". In otherwords it is much easier to feedback a single style formatted result than to parse a formatted entry that might be entered many different ways. Allowing fractions to uccur in the entry complicates the task. Here is one crude method that was suited a specific task. It may not be suitable for you. tbTH is a Textbox, lbPTSis the feedback Label Private Sub tbTH_Change() Me.lbPTS = Format(Parse2VAl(Me.tbTH), "#.00000") End Sub Function Parse2VAl(str As String) As Variant Dim x As Integer Dim nom As Double Dim dem As Double On Error GoTo limbo If IsNumeric(str) Then Parse2VAl = str Else x = InStr(1, str, "/") If x > 0 Then nom = Val(Left(str, x - 1)) End If dem = Val(Right(str, Len(str) - x)) Parse2VAl = nom / dem End If Exit Function limbo: On Error GoTo 0 Parse2VAl = "???" End Function With much respect for your bilinguality, AKS
The usage of fractionnal part is a customer specification In europa , the input unit is millimeters all the times, but come a special case !. The problem of parsing the input , is the need of : have different forms depending of the unit or, a complex form gestion to parse or not depending of the unit. Parsing need 4 controls (foot + inche + numerator + fractionnal unit) The problem using the DistanceToReal and RealToString , is the control of the input each time the user press a key , (for exemple , if the user press the "A" key , refuse it , but if he press the ' key , accep it only then the unit is inches) , this is the best way in an user point of vue (It is my opinion) than controling after the input . Thanks for all your explanations form. So for example a 24.5 in the foot entry and a 27 in the inches entry would feedback as " 26' - 9" ". In