!! Reading character by character from a string and check it

S

Steve

hi folks,

i have a table, with 11 rows in a word doc.
i need to read Names and Dates from a Sentence.
Names are all in UPPERCASE as STEVE.
Dates are in different formats.
i need a routine to read character by character and check if Uppercase, using UCase or if Lowercase using LCase or any other character.
Using the same routine i need to recognise a date from the sentence.
These are then displayed in text boxes in visual basic.
In this table there is the following characters: text, integers, spaces " " and foward slashes /.

any comment appreciated. i need to start from somewhere!

Regards,
Steve
 
J

Jezebel

First, UCase and LCase don't check characters, they convert them.

You can do this sort of checking direct comparison

If char >= "A" and char <= "Z" then ...

or using the Like operator

If char Like "[A-Z]" then ...


But better still to use regular expressions and the Find function.
Experiment using the Find dialog. Check 'Use Wildcards' ... eg look for
<[A-Z]*> to find words entirely in upper case.






Steve said:
hi folks,

i have a table, with 11 rows in a word doc.
i need to read Names and Dates from a Sentence.
Names are all in UPPERCASE as STEVE.
Dates are in different formats.
i need a routine to read character by character and check if Uppercase,
using UCase or if Lowercase using LCase or any other character.
 
C

Chad DeMeyer

Although you could use something like

If sText = UCase(sText) Then
'sText is upper case
End If
If sText = LCase(sText) Then
'sText is lower case
End If

This could be performed on whole words rather than just characters, since
the Range and Selection object have a .Words property which returns a
collection of ranges, each member being what MSWord recognizes as a word.

The date part is harder. There is an IsDate function in VBA which tests the
argument supplied and returns True if the expression can be converted to a
date, but how do you know the start and end points of the range to test?
Perhaps you could test each occurrence of three consecutive words with
IsDate, assuming that whatever the format of your dates they always contain
month, date, and year.

Regards,
Chad


Jezebel said:
First, UCase and LCase don't check characters, they convert them.

You can do this sort of checking direct comparison

If char >= "A" and char <= "Z" then ...

or using the Like operator

If char Like "[A-Z]" then ...


But better still to use regular expressions and the Find function.
Experiment using the Find dialog. Check 'Use Wildcards' ... eg look for
<[A-Z]*> to find words entirely in upper case.






Steve said:
hi folks,

i have a table, with 11 rows in a word doc.
i need to read Names and Dates from a Sentence.
Names are all in UPPERCASE as STEVE.
Dates are in different formats.
i need a routine to read character by character and check if Uppercase,
using UCase or if Lowercase using LCase or any other character.
Using the same routine i need to recognise a date from the sentence.
These are then displayed in text boxes in visual basic.
In this table there is the following characters: text, integers, spaces
"
" and foward slashes /.
any comment appreciated. i need to start from somewhere!

Regards,
Steve
 
T

Trevor Lowing

Steve,

It sure sounds like a good time to use Regular Expressions. Below is an
example I used to do somthing similar. You can find additional
information here:

http://msdn.microsoft.com/library/default.asp?URL=/library/en-us/dnclinic/html/scripting051099.asp

And for example patterns peopel have already built:

http://www.regexlib.com




Private Function FindPattern(strSearch)
'----------------------------------------------------------
' Name : FindTasker
' Scope : Private
' Type : Function
' Input(s) :
' Returns : Pattern If Found
' Description : Searches input string for Pattern and returns the
first occurance.
'----------------------------------------------------------
On Error GoTo Err_Init
Dim strMatch As String
Dim colMatches As Object
Dim objMatch As Object
Dim objRegExp As Object

' Create regular expression. Late Binding to prevent version errors
Set objRegExp = CreateObject("VBScript.RegExp")

With objRegExp
.Pattern = "([a-zA-Z])+-?\d{6}-?(\d)*" ' Set pattern
.IgnoreCase = True ' Set case
insensitivity.
.Global = True ' Set global
applicability.
End With
Set colMatches = objRegExp.Execute(strSearch) ' Execute
search.
'Load the Tasker Number
If colMatches.Count > 0 Then
Set objMatch = colMatches(0)
strMatch = UCase(objMatch.Value)
FindTasker = strMatch
End If
Set colMatches = Nothing
Set objMatch = Nothing
Set objRegExp = Nothing
Exit Function

Err_Init:
Err.Clear
'HandleError CurrentModule, "FindTasker", Err.Number, Err.Description

End Function





hi folks,

i have a table, with 11 rows in a word doc.
i need to read Names and Dates from a Sentence.
Names are all in UPPERCASE as STEVE.
Dates are in different formats.
i need a routine to read character by character and check if Uppercase, using UCase or if Lowercase using LCase or any other character.
Using the same routine i need to recognise a date from the sentence.
These are then displayed in text boxes in visual basic.
In this table there is the following characters: text, integers, spaces " " and foward slashes /.

any comment appreciated. i need to start from somewhere!

Regards,
Steve


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top