Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb.net function in crystal

Status
Not open for further replies.

jpc

Programmer
Feb 5, 2002
8
US
Hi there. I have a vb.net function that converts a proprietary field type to a readable array. I am not sure if I should go the UFL route or if I should try to convert it into a crystal function. I am still using crystal 8.5. It seems as though the industry is moving away from UFL. Thoughts?

The vb.net function is below.
Public Function ParseDiaryField(ByVal fld As String) As String(,)
''' <summary>
''' The <code>ParseDiaryField</code> function is designed to parse out a Remedy Diary field object
''' The diary fields are separated by tab, space, and carriage return characters
''' The date format is also converted as the Remedy date format is epoch time so a conversion is used
''' <param name="args"></param>
''' <returns></returns>
'''
''' <see cref="link"/>
''' <seealso cref="link"/>
''' <list type="link"
''' Since:
''' Deprecated:
''' </summary>

Dim myArr(,) As String

Dim TAB_POS As Integer
Dim TAB_START As Integer
Dim TAB_LENGTH As Integer
Dim LF_POS As Integer
Dim LF_START As Integer
Dim LF_LENGTH As Integer
Dim CF_POS As Integer
Dim CF_START As Integer
Dim CF_LENGTH As Integer
Dim COUNT As Integer
Dim TOTLENGTH As Integer
Dim ExtractedDate As Double


TAB_POS = 0
TAB_START = 1
TAB_LENGTH = 1
LF_POS = 0
LF_START = 0
LF_LENGTH = 0
CF_POS = 0
CF_START = 0
CF_LENGTH = 0
COUNT = 1
TOTLENGTH = Len(fld)

While TAB_LENGTH < TOTLENGTH
ReDim Preserve myArr(3, COUNT)
'get position of carriage return
'THIS CHARACTER IS A TAB
'The tab is found after the time entry
TAB_POS = InStr(TAB_LENGTH, fld, "")
TAB_LENGTH = TAB_POS - TAB_START
LF_LENGTH = TAB_POS + 1
LF_START = TAB_POS + 1

LF_POS = InStr(LF_LENGTH, fld, "")
LF_LENGTH = LF_POS - LF_START
If LF_LENGTH < 0 Then LF_LENGTH = 0
CF_LENGTH = LF_POS + 1
CF_START = LF_POS + 1
'THIS CHARACTER IS A CARRIAGE RETURN
CF_POS = InStr(CF_LENGTH, fld, "")
If CF_POS = 0 Then
CF_LENGTH = TOTLENGTH - CF_START
Else
CF_LENGTH = CF_POS - CF_START
End If

ExtractedDate = Mid(fld, TAB_START, CDbl(TAB_LENGTH))
myArr(1, COUNT) = ConvertEpoch(ExtractedDate)
myArr(2, COUNT) = Mid(fld, LF_START, LF_LENGTH)
myArr(3, COUNT) = Mid(fld, CF_START, CF_LENGTH)

If CF_POS = 0 Then
TAB_LENGTH = TOTLENGTH
TAB_START = TOTLENGTH
COUNT = COUNT + 1
Else
TAB_LENGTH = CF_POS + 1
TAB_START = CF_POS + 1
COUNT = COUNT + 1
End If
End While
Return myArr

End Function

Jon Clayton
Senior Programmer Analyst
Montgomery, AL
 
Posting VB code will limit your responses to VB developers, which many of the experts here are not, plus it's the long way there.

Try posting:
Databse/connectivity used
Example data (show what's in the field including the proper delimiters)
Expected output

Posting a "" instead of for example a chr(13) doesn't help much and won't help subsequent coders with your code either.

A space is chr(32)
A Tab is chr(9)
A Carriage Return is chr(13)

Most coders would reference it's ascii number, not paste a literal character in.

Parsing data is pretty easy in Crystal.

You state: "The diary fields are separated by tab, space, and carriage return characters"

And then your code states:
'get position of carriage return
'THIS CHARACTER IS A TAB
'The tab is found after the time entry

The position of the carriage return is the tab?

Anyway, to break the following into an array (not sure why you want an array in Crystal, you can't display one, plus these are different data types and most languages won't allow for differing data types within an array). Here's an example of parsing fields:

Here's a field (you can paste this into a formula in Crystal for testing):

"Hello"+chr(9)+"there"+chr(32)+"12/1/04"+chr(13)

This extracts the elements:

First
left({@hello there},instr({@hello there},chr(9))-1)

Second
mid({@hello there},instr({@hello there},chr(9))+1
,
instr({@hello there},chr(32))-1)

Third
mid({@hello there},instr({@hello there},chr(32))+1
,
instr({@hello there},chr(13))-1)

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top