Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert VFP class to C# class Help (Arrays)
Message
From
14/01/2009 18:59:32
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01373708
Message ID:
01373823
Views:
13
>I'm having a hard time rewriting this into c#. Arrays in .net are much more difficult than in Foxpro. Can anyone help me get started?
>
>The parameter passed would be something similar to: "XYZ222, SC, 2007, 120 MAIN ST"
> In that example, XYZ222 would be this.vl, SC would be this.vlstate, and 2007 should go into this.vlYear and the rest should go into this.location.
>
>
>DEFINE CLASS parseclass AS custom
> 
> 
>       Name = "parseclass"
> 
> 
>       PROCEDURE parse
>              LPARAMETERS tcText
>              LOCAL ix
>              LOCAL ARRAY aWork[1]
>              lnLines = ALINES(aWork,m.tcText)
>              THIS.ADDPROPERTY('aWorked['+TRANSFORM(m.lnLines)+']')
> 
>              palias = ALIAS()
>              CREATE CURSOR _dummy_ (ID I,vl I,vlState I,vlYEar I,Location I,Comments I)
>              FOR ix=1 TO ALINES(aWork,m.tcText)
>                     SCATTER NAME THIS.aWorked[m.ix] BLANK
>                     IF TYPE('aWork(m.ix)') = "C"
>                           THIS.aWorked[m.ix].ID = ALLTRIM(aWork[m.ix])
>                     ELSE
>                           THIS.aWorked(m.ix).ID = ''
>                     ENDIF
>                     THIS.ProcessLine(aWork[m.ix],m.ix)
>              ENDFOR
>              USE IN _dummy_
>              IF !EMPTY(palias) .AND. USED(palias)
>                     SELECT (palias)
>              ENDIF
>       ENDPROC
> 
> 
>       PROCEDURE processline
>              LPARAMETERS tcLine, tnObjectID
>              LOCAL lcParsePhrase,lnWords,ix
>              IF TYPE('tcLine') = "C"
>                     m.lcParsePhrase = UPPER(ALLTRIM(tcLine))
>              ELSE
>                     m.lcParsePhrase = ''
>              ENDIF
>              lnWords = GETWORDCOUNT( m.lcParsePhrase,',' )
>              LOCAL ARRAY aWorkings[Max(m.lnWords,5)]
>              aWorkings = ''
>              FOR ix=1 TO m.lnWords
>                     aWorkings[m.ix] = ALLTRIM(GETWORDNUM( m.lcParsePhrase,m.ix,',' ))
>              ENDFOR
>              THIS.parseItems(@aWorkings,m.tnObjectID)
>       ENDPROC
> 
> 
>       PROCEDURE parseitems
>              LPARAMETERS taValues, tnObjectID
> 
>              WITH THIS.aWorked[m.tnObjectID]
>                     .vlYEar = THIS.GetYear(@taValues)
>                     .vlState = THIS.GetState(@taValues)
>                     .Location = THIS.GetLocation(@taValues)
>                     .vl = THIS.GetLicenseTag(@taValues)
>                     .Comments = THIS.GetComments(@taValues)
>              ENDWITH
>       ENDPROC
> 
> 
>       PROCEDURE getyear
>              LPARAMETERS taValues
>              LOCAL ix,lnYear
>              IF TYPE('alen(taValues,1)') = "N" .and. ALEN(taValues,1) > 0
>                     FOR ix=1 TO ALEN(taValues,1)
>                           IF THIS.IsYear(taValues[m.ix])
>                                  lnYear = YEAR(CTOD('1/1/'+taValues[m.ix]))
>                                  ADEL(taValues,m.ix)
>                                  IF Alen[taValues] > 1 
>                                         DIMENSION taValues[Alen(taValues)-1]
>                                  ENDIF
>                                  lcYear = ALLTRIM(STR(m.lnYear))
>                                  RETURN m.lcYear
>                           ENDIF
>                     ENDFOR
>              ENDIF
>              RETURN 0
>       ENDPROC
> 
> 
>       PROCEDURE getstate
>              LPARAMETERS taValues
> 
>              LOCAL ix,lcState
>              m.lcState = ''
> 
>              IF TYPE('alen(taValues,1)') = "N" .and. ALEN(taValues,1) > 0
>                     FOR ix=1 TO ALEN(taValues,1)
>                     IF TYPE('taValues[m.ix]') = "C"
>                           taValues[m.ix]=ALLTRIM(UPPER(taValues[m.ix]))
>                           IF LEN(taValues[m.ix]) = 2 .AND. VAL(taValues[m.ix]) = 0 .AND. Statever(taValues[m.ix])
>                                  lcState = taValues[m.ix]
>                                  ADEL(taValues,m.ix)
>                                  IF Alen[taValues] > 1 
>                                         DIMENSION taValues[Alen(taValues)-1]
>                                  ENDIF
>                           ENDIF
>                     ENDIF
>                     ENDFOR
>              ENDIF
>              RETURN m.lcState
>       ENDPROC
> 
> 
>       PROCEDURE getlocation
>              LPARAMETERS taValues
>              LOCAL ix,lcLocation
> 
>              IF TYPE('alen(taValues,1)') = "N" .and. ALEN(taValues,1) > 0
>                     FOR ix=1 TO ALEN(taValues,1)
>                           IF TYPE('taValues[m.ix]') = "C"
>                                  IF ( ISDIGIT(LEFT(taValues[m.ix],1)) AND OCCURS(' ', taValues[m.ix]) > 0 ) OR ;
>                                         ( '/' $ taValues[m.ix] ) OR ( '\' $ taValues[m.ix] )
>                                         lcLocation = taValues[m.ix]
>                                         ADEL(taValues,m.ix)
>                                         IF Alen[taValues] > 1 
>                                                DIMENSION taValues[Alen(taValues)-1]
>                                         ENDIF
>                                         RETURN m.lcLocation
>                                  ENDIF
>                           ENDIF
>                     ENDFOR
>              ENDIF
>              RETURN ''
>       ENDPROC
> 
> 
>       PROCEDURE getlicensetag
>              LPARAMETERS taValues
> 
>              LOCAL ix,lcTag
>              IF TYPE('alen(taValues,1)') = "N" .and. ALEN(taValues,1) > 0
>                     FOR ix=1 TO ALEN(taValues,1)
>                           IF ( OCCURS(' ', taValues[m.ix]) = 0 )
>                                  lcTag = taValues[m.ix]
>                                  ADEL(taValues,m.ix)
>                                  IF Alen[taValues] > 1 
>                                         DIMENSION taValues[Alen(taValues)-1]
>                                  ENDIF
>                                  RETURN m.lcTag
>                           ENDIF
>                     ENDFOR
>              ENDIF
>              RETURN ''
>       ENDPROC
> 
> 
>       PROCEDURE getcomments
>              LPARAMETERS taValues
> 
>              LOCAL ix,lcComments
>              lcComments = ''
>              IF TYPE('alen(taValues,1)') = "N" .and. ALEN(taValues,1) > 0
>                     FOR ix=1 TO ALEN(taValues,1)
>                           IF ( !EMPTY(taValues[m.ix]) )
>                                  lcComments = lcComments + taValues[m.ix] + SPACE(1)
>                           ENDIF
>                     ENDFOR
>              ENDIF
>              RETURN TRIM(m.lcComments)
>       ENDPROC
> 
> 
>       PROCEDURE isalldigit
>              LPARAMETERS tcValue
>              RETURN EMPTY(CHRTRAN(tcValue,'0123456789',''))
>       ENDPROC
> 
> 
>       PROCEDURE isyear
>              LPARAMETERS tcValue
>              RETURN THIS.IsAllDigit(tcValue) AND ;
>                     INLIST(LEN(tcValue),2,4) AND ;
>                     BETWEEN(YEAR(CTOD('1/1/'+tcValue)),YEAR(DATE())-3,YEAR(DATE())+1)
>       ENDPROC
> 
> 
>ENDDEFINE
>*
>*-- EndDefine: parseclass
>
Janet,
I would do this using regular expressions in VFP (VBScript.RegExp). In .Net regular expression support is better IMHO (System.Text.RegularExpressions.Regex).

IsAllDigit, IsYear type parsings could be easily done with .Net's specialized Parse, TryParse on structures like int, DateTime.

And you have Linq you may utilize Linq expressions. to select, transform, project the 'records' (check www.linqPad.net for a great utility that would help you in that matter).

PS: If you ever have curioisty about it, I think F# would be cool parser for this (especially when you think about its interactive console ability).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform