Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Error check with optional space

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
corky_guy@yahoo.com - 30 Jan 2008 04:48 GMT
So, I've tried this every way that I (in my limited mind) know how and
I am unable to do what I need to do.
Basically, I have a textbox in which users will enter either a single
digit or a range of  digits from 0-7 separated by a single space
(i.e., 0 1 2 3 or 4 6 7)

The two problems I cannot overcome are:
1) The error checking that I'm currently using cannot distinguish
between "11" and "1".  In other words, the error checking is looking
at each digit (11 = two ones) instead of the entire number (eleven)
and, thus, it's not triggering the error that an 11 is outside of the
valid range (0-7).

2) I cannot figure out how to allow spaces in the textbox while
maintaining the error checking

Any help you can provide is sincerely appreciated.

Thank you!
Greg Maxey - 30 Jan 2008 05:52 GMT
Corky,

I don't know exactly what you mean by "textbox," but whatever it is it has a
range.

Selection has a range also. If I type   1  3  11 4 7 6  and select it, I
could then run code like this:

Sub ScratchMacro()
Dim myRng() As String
Dim i As Long
myRng = Split(Selection.Range, " ")
For i = LBound(myRng) To UBound(myRng)
 If Val(myRng(i)) > 7 Then Debug.Print "To Big"
Next i
End Sub

Basicly Split returns a zero base one dimensional array usig " " (space) as
the delimiter.  Then you compare each subscript of the array to your
condition.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> So, I've tried this every way that I (in my limited mind) know how and
> I am unable to do what I need to do.
[quoted text clipped - 15 lines]
>
> Thank you!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.