Making own Function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi EveryBody,
I have a field field 'Daily Acitvity' in which the data is like this,

"Completion of punch list.Radiography of the modified joints.Review of valve
data sheet.Construction coordinattion is ongoing."....

I am making report in which i am trying to display each sentence in seperate
line (i.e i am trying to insert a new line after every 'full stop').

For this,
I make a custom function in module as below,

Function Test(Activity as string)

dim i,j as integer
i=len(Activity)
For j=1 to i

if Activity(j)="." then
Chr(13) & Chr(10)
end if
next j
end funtion

When i try to use this funtion it gives Error, like
"COMPILE ERROR"
EXPECTED ARRAY"

Where i am wrong , pls. help me.
if any other method to do this pls. advise.

Regards
Nad
 
Hi Nad,

Don't make life difficult for yourself.

Activity = Replace(Activity,". ","." & vbCrLf)

Regards,
Rod
 
thanks for your reply,
Actually i also want to add '*'(asterisk) before every sentence.

Please solve my function so that i can make other function also.
 
Hi Nad,

Activity = Replace(Activity,". ","." & vbCrLf & "*")

May I suggest that if you are doing a lot of text manipulation you read up
on the built-in string functions such as LEFT, RIGHT, MID, LEN, REPLACE,
INSTR, etc.

If you want help writing functions then there is not enough space here for a
tutorial. However let me make some comments about the code sample you
presented.

Your function declaration would be better written as

Function Test(Activity as string) as String

this declares the output of the function also to be a string.

Dim i,j as Integer

I'm not sure this is valid syntax. It's more conventional to write

Dim i as Integer, j as Integer

Your For/Next structure is OK but I find its use totally inappropriate here.

Activity is not an array and cannot be subscripted, so Activity(j) is
illegal. If you want to test each character of your string in turn use
something like the MID function.

The line containing Chr(13) & Chr(10) needs an assignment: set something
equal to Chr(13) & Chr(10). This by itself means nothing to the interpreter.

Finally may I suggest you adopt some naming conventions (like Reddick) and
use them consistently; strActivity is better than Activity and so on.

Regards,

Rod
 
Back
Top