Input Format

I have a lot of textboxes for data input.
According with the user choice, i can input in the textbox values in millimeters (and this is not hte problem) or in inches, in the format:
"3/8" or
"1" or
"2 13/32" (this are only example).
Then i must convert this values in mm.
How to "force" this Inches input method?



parduzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Erick37Commented:
Use a Masked Edit Box instead of a TextBox to force a particular format:

mskInput.Mask = "### ##/##" 'Using inches and fraction

mskInput.Mask = "" 'Using any input
0
manojaminCommented:
I don't think you can force that! If you decide to let the user provide input in inches, it is hard to distinguish that from mm or cm or foot or for that matter any other matric/british numeric input. All you can do is prevent the user entering any character but the numeric, ., and /

If the user selects the input method in inches and enters (300, thinking this as mm) it will be treated as 300 inches not mm! how can you predict users behaviour???

I am curious to know...
0
parduzAuthor Commented:
Erick37:
i can use only "standard" control in this app, so I dont need OCX install.

manojamin:
1) Whats a name! ;)
2) if the user select the English measure system (inches, feets, ...)
and put a value thinking in mm, what can i make? He must be coherent with the choice he makes!
I only ask a method (function) to "understand" that strings like "1 3/8", "2", "5/16" are good to convert in mm and a string like "/3", "3 1" or somewhat else are no good.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

SiM99Commented:
use instr(number, "/")
this will tell you if there's a / in there, assuming you will always have something like '1 3/4"'
0
AnswerTheManCommented:
playing with the user interface can lead to simple soulution for you and for the user as well :

1. first control will be a combobox that
   the user will have to select between
   'mm' or 'inch' . set one of this
   2 to be the default.

2. the values will be inserted into 2
   textboxes. one for 'full Units' and
   the other for 'remainings'.
 
3. having the combobox value will make it simpler to calculate the rest.
0
manojaminCommented:
'I think this is what you are looking for...

Private Function isValidFormat(ByVal Mystr As String) As Boolean
    Dim strTemp As String
    Dim iTemp As Integer
    strTemp = Trim(Mystr)
    isValidFormat = False
    iTemp = InStr(strTemp, " ")
    If (iTemp > 0 And InStr(iTemp + 1, strTemp, " ") > 0) Then Exit Function
    iTemp = InStr(strTemp, "/")
    If (iTemp > 0 And InStr(iTemp + 1, strTemp, "/") > 0) Then Exit Function
    If (InStr(strTemp, " ") > 0 And InStr(strTemp, "/") = 0) Then
        Exit Function
    ElseIf (InStr(strTemp, " ") > 0 And InStr(strTemp, "/") > 0 And _
           (InStr(strTemp, " ") + 1 = InStr(strTemp, "/") Or _
           InStr(strTemp, "/") = Len(strTemp))) Then
        Exit Function
    ElseIf (InStr(strTemp, "/") > 0 And _
           (InStr(strTemp, "/") = 1 Or _
           InStr(strTemp, "/") = Len(strTemp))) Then
        Exit Function
    Else
        isValidFormat = True
    End If
End Function

Private Sub Command1_Click()
    MsgBox isValidFormat(Text1.Text)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
    If ((KeyAscii < vbKey0 Or KeyAscii > vbKey9) And _
        (KeyAscii <> 47 And _
        KeyAscii <> vbKeySpace And _
        KeyAscii <> vbKeyDelete And _
        KeyAscii <> vbkkeyback)) Then
        KeyAscii = 0
    End If
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
parduzAuthor Commented:
BINGO!

Full working code, and fast answer.
What can i ask more?

Thanks!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.