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 / March 2006

Tip: Looking for answers? Try searching our database.

A simple question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Charlie - 28 Mar 2006 03:04 GMT
How would I modify this code to check first to see that there is indeed
Phrases(0), Phrases(1), and Phrases(2) so I won't get an error if strSentence
does not have 2 tabs in the sentence?
thanks,
ck

Phrases = Split(strSentence, vbTab)
   str1 = Phrases(0) ' so you can see what they are
   str2 = Phrases(1)
   str3 = Phrases(2)
Greg Maxey - 28 Mar 2006 03:15 GMT
I suppose you could look for and count them first:

Sub Test()
Dim Phrases As Variant
Dim strSentence As String
Dim str1 As String, str2 As String, str3 As String
Dim i As Long
strSentence = Selection.Text
With Selection.Find
 .Text = vbTab
 While .Execute
  If .Found Then i = i + 1
 Wend
End With
If i = 2 Then
Phrases = Split(strSentence, vbTab)
   str1 = Phrases(0) ' so you can see what they are
   str2 = Phrases(1)
   str3 = Phrases(2)
End If
End Sub

Signature

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

> How would I modify this code to check first to see that there is
> indeed Phrases(0), Phrases(1), and Phrases(2) so I won't get an error
[quoted text clipped - 6 lines]
>    str2 = Phrases(1)
>    str3 = Phrases(2)
Jezebel - 28 Mar 2006 04:25 GMT
Phrases = Split(strSentence, vbTab)
For i = 0 to ubound(Phrases)
   Select case i
   Case 0
       str1 = Phrases(0)
   Case 1
       str1 = Phrases(1)
   Case 2
       str1 = Phrases(2)
   case else
   end select
Next

> How would I modify this code to check first to see that there is indeed
> Phrases(0), Phrases(1), and Phrases(2) so I won't get an error if
[quoted text clipped - 7 lines]
>    str2 = Phrases(1)
>    str3 = Phrases(2)
 
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.