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 20:52:04
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:
01373859
Views:
11
>Thank you for your ideas. I will research them. I step through the array and check each char in the item to see if it is 2 or 4 digits only and if so, I loop through every char in the item to see if everyone is a digit using isdigit(). If it is true for every char, I assume it is a date. I created an isdate() method that checks if a date is valid by passing the whole string to it or if only 2 digits are entered (07) then adding it to "01/01/" and passing it. It seems to work. Now I need to check to see if the valid date is older than 3 years from the current date or in a future year (anytime in the future since a license tag cannot have a future date). After a valid year is found, I replace the item's value with "" so it cannot be used again (and you cannot delete items in an array).
>
>Next I need to check for any 2 digit item in the array and see if it matches a valid state abbreviation. I plan to check for the values in the same order the vfp class did.
>
>I'm working my way through year, state, license tag, and location. I have a rule that it can only be a license tag if it is at least 3 characters. Anything less is assumed to be a state. After the year, state and license tag are checked, any item remaining will be put in the location property.
>
>The biggest problem is that the string can be passed in any order. The items in the array may change their order each time. The state could be passed as the 2nd item and then later as the 3rd item.
>
>I didn't write the VFP code. It was written by another programmer who no longer is in our company so I am reading their code and trying to rewrite it. I am just learning C# and working on functions like these to learn it.

This is a quick rough sample summarizing part of the ideas:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

class VFPDatabaseDiscovery
{
    static void Main()
    {
        var linesQuery =
                from l in
                    @"XYZ222, SC, 2007, 120 MAIN ST
XYZ333, AR, 2007, 500 MAIN ST"
                                .Split('\n')
                let w = l.Split(',')
                select new { line = l, words = w.Select(word => word.Trim()).ToArray() };

        List<Worked> worked = new List<Worked>();
        foreach (var curLic in linesQuery)
        {
            Worked w = new Worked();
            w.ID = curLic.line;

            // assumed parsed here - Worked constructor could get the 'line'
            // and parse during init
            // then it could directly go into Linq query;)

            w.vl = curLic.words[0];
            w.vlState = curLic.words[1];

            w.vlYear = curLic.words[2];
            w.Location = curLic.words[3];
            worked.Add(w);
        }

        Form f = new ShowDataForm(worked, "Quick Parse");
        f.ShowDialog();
    }
}

public class Worked
{
    public string ID { get; set; }
    public string Location { get; set; }
    public string vl { get; set; }
    public string vlState { get; set; }
    public string vlYear { get; set; }
    public string Comments { get; set; }
}

public class ShowDataForm : Form
{
  public ShowDataForm(Object tbl, string caption)
  {
     this.dgv = new System.Windows.Forms.DataGridView();
     this.dgv.Location = new System.Drawing.Point(0, 0);
     this.dgv.Dock = DockStyle.Fill;
     this.dgv.DataSource = tbl;
     this.Text = caption;
     this.Controls.Add(this.dgv);
     this.ClientSize = new System.Drawing.Size(1024, 768);
  }
  private System.Windows.Forms.DataGridView dgv;
}
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
Reply
Map
View

Click here to load this message in the networking platform