hello please help me on this...i have txt1.text that can input only pcs and ream ..my problem that if the user will use the uppercase PCS it will not accept because my trapping is..

if Trim(txt1.text) <> "pcs" and Trim(txt1.text) <> "ream" then
msgbox "please input pcs and ream"
exit sub
end if


please help me on this how to accept "PCS" or "pcs" and "REAM" or "ream"....hoping for your positive responds..does the vb6.0 has a built in function just like java ignorecase?

Dani AI

Generated

A few concise options that avoid repeating the exact code already posted by and build on 's UI suggestion.

For a simple, robust case‑insensitive check use StrComp with vbTextCompare so the comparison ignores case without changing the textbox contents:

Dim s As String
s = Trim$(txt1.Text)

If StrComp(s, "pcs", vbTextCompare) <> 0 And StrComp(s, "ream", vbTextCompare) <> 0 Then
    MsgBox "Please enter 'pcs' or 'ream'."
    txt1.SetFocus
    Exit Sub
End If

If you might add more allowed units later, keep them in an array and loop with a case‑insensitive compare:

Dim allowed
allowed = Array("pcs", "ream")

Dim i As Integer, ok As Boolean
s = Trim$(txt1.Text)

For i = LBound(allowed) To UBound(allowed)
    If StrComp(s, allowed(i), vbTextCompare) = 0 Then
        ok = True
        Exit For
    End If
Next

If Not ok Then
    MsgBox "Please enter 'pcs' or 'ream'."
    txt1.SetFocus
    Exit Sub
End If

Practical tips:

  • Prefer validating on the button click or LostFocus event so the user experience is predictable.
  • Use Trim$ (shown above) to remove accidental spaces and be slightly faster than Trim.
  • If you want to prevent typing mistakes entirely, use a ComboBox (DropDownList) or list so the user must pick a correct value (as suggested).
  • Make the message clear (use "or" not "and") and optionally normalize the stored value to a standard form before saving.

This handles "PCS", "pcs", "ReAm", etc., safely and keeps the code easy to extend.

Recommended Answers

All 3 Replies

Hi jemz,
you can use the ucase function which stands for the upper case(Returns the uppercase of a string) or
the lcase which stands for the lower case(returns the lower case of a string)...
For example:

if Trim(UCASE(txt1.text)) <> "PCS" and Trim(UCASE(txt1.text)) <> "REAM" then

OR

if Trim(LCASE(txt1.text)) <> "pcs" and Trim(LCASE(txt1.text)) <> "ream" then

Good luck..

hi Jemz,

one way of doing this is how KSS told, the other way is to restrict the user to select the values from a list box... in this case you may not even require aditional validation if it is some specific value.

this is applicable only if the values constant set of values.

oki thank you for helping me i will try this...more power to you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.