 |
 |

08-07-2012, 01:08 PM
|
 |
Centurion
|
|
Join Date: Jun 2003
Location: New Jersey
Posts: 150
|
|
Create Class or Array?
|
I have a list of fields that need to be QC'd. I have 2 functions set up to QC for 2 different things. Each of the fields needs to be checked by either one or the other of these 2 functions. I'm trying to avoid coding an individual call for each of these fields.
I'm thinking I could split these fields into 2 groups (or classes? arrays?) and then I could call the functions using the subscript, something like:
For i = 0 to 10
Result = FunctionName(fieldName(i))
next i
I've tried doing this many different ways but I'm just making a big coding mess - really not sure what I'm doing to be honest. I've dabbled with programming for work for a while but nothing too intense, I've never had any formal training. Now they are giving me a big project to work on and I don't want to blow my chance at maybe a promotion or perhaps they'll see my potential and send me for training. I'm very overwhelmed, to say the least. I'm trying to break it down into little pieces and figure each part out one by one.
If anyone could shed come light and show me what I should do or at least point me in the right direction I would really appreciate it...
P.S. I know I've been posting here alot lately, you all have been great.. hope I"m not becoming a pest! Please know that I'm not just here to 'take the code and run', I really want/need to learn this.
Thanks! 
Joni
|
|

08-07-2012, 02:19 PM
|
 |
Bald Mountain Survivor
Super Moderator * Expert *
|
|
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,882
|
|
|
No worries Joni,
Anyone that wants to learn as much as you do is welcome here.
---
What do you mean by QC? Little fuzzy on what you want to do with your functions.
What determines one field type from another?
Do you need them in two lists for any other reason than checking them?
If not why not keep them in one list?
In your sample you have Result being returned. What do you want to do with it?
Is this something you need to store with each field?
|
__________________
Burn the land and boil the sea
You can't take the sky from me
~T
|

08-07-2012, 02:54 PM
|
 |
Centurion
|
|
Join Date: Jun 2003
Location: New Jersey
Posts: 150
|
|
Hi T
Sorry, by QC I mean Quality Control... I need to validate the data coming in to make sure it's what's expected. Certain fields need to have just digits and other fields need to not have any digits. There are other fields too that require other validations.. for instance, there are 2 fields that have to contain only the "-" symbol. There's another that should contain either a '1' or '2'. The whole purpose or all this validating is that once I know all the data is what it should be, I have to load it into a Visual FoxPro table and display it in a DataGrid on a form - but that's an entirely other story! LOL I've been trying to do that for close to 2 months now with no luck, so I've been skipping over it, getting other parts of the project done and then going back and trying again.
Anyway, back to the main purpose here
Thinking about it, I suppose they could be in one list. Instead of incrementing 'i' in the For/Next loop, is there a way to set up a list of subscripts to parse through? Something like:
For i = (2,5,8,11)
Result = FunctionName(fieldName(i))
next i
Would that work?
(Result is boolean and returns either true or false)
I've declared every field as a string since I won't be performing any calculations.. I just thought that would be easier and also because I know that integers need to be handled in a certain way to avoid errors. That's happened to me many times so I tend to stick with strings if I can.
|
|

08-07-2012, 03:13 PM
|
 |
Ultimate Contributor
Forum Leader * Expert *
|
|
Join Date: Nov 2003
Location: Wigan, UK
Posts: 1,676
|
|
|
It might be easier if you gave a more solid example of what you are trying to do and the kind of data involved, without knowing what the data looks like or how it is organised it is difficult to really have any decent advice to offer.
|
|

08-07-2012, 03:34 PM
|
 |
Centurion
|
|
Join Date: Jun 2003
Location: New Jersey
Posts: 150
|
|
|
I'm reading in a flat text file sequentially.
Here is an example of what the records look like:
1000712193 SUXXXXE DR UNIT 6F APPLETON NJ549148766 24914321003GLORIA LESDFDS 222-555-95550512
Each record contains the address, name, phone number and a couple other fields that contain digits that stand for something (ex. the last field in each record is for gender, '1' for male and '2' for female).
I'm not doing anything with the data other than validating it and then writing it out to a table after the file checks out okay. One thing that I forgot to mention earlier is that when I do find an error, I have to write the error to an error log (file) with a copy of the record and the field name causing the error for the user to view. There are certain instances when an error is acceptable. The user needs to see the log and determine whether to continue with the loading of the table or cancel the job all together until the file is fixed.
|
|

08-07-2012, 04:13 PM
|
 |
Bald Mountain Survivor
Super Moderator * Expert *
|
|
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,882
|
|
Much clearer.
Okay I assume you are reading all the lines into an array of string. Right?
Are the fields of a fixed width or are you relying on spaces to define the fields?
If fixed width you could use the string.substring() method to examine fields,
otherwise you would use the string.split() method to parse each line.
Loop through each line breaking it into fields and validating each as you go.
Displaying your error log in a listbox might be appropriate.
I'd supply a button to copy the listbox contents to the windows clipboard
when the loop is complete.
Roughly
Code:
Private Enum eCols
'These are just sample enumerations for the fields.
'You would use your own of course
UserID = 0
UserName = 1
Address = 2
State = 3
Zip = 4
'Etc...
End Enum
Private Sub CheckFile(Filename as string)
Dim sLines() as string = System.IO.File.ReadAllLines(Filename)
For i as integer = 0 to sLines.count - 1
Dim sCols() as string = sLines(i).Split(" "c) 'Or a custom function to split by field width
CheckUserID(sCols(eCols.UserID), i)
CheckUserName(sCols(eCols.UserName), i)
CheckAddress(sCols(eCols.Address),i)
'Etc...
Next
End Sub
Private Sub CheckUserID(UserID as string, Row as integer)
if ContainsAlpha(UserID) then lstErrors.Items.Add(Row & " | UserID <> n")
End Sub
'Etc...
Or instead of a listbox perhaps you would want to use a Datagridview to display all the cells under each column header and place an "X" or simple Error code in the offending cells.
|
__________________
Burn the land and boil the sea
You can't take the sky from me
~T
Last edited by Gruff; 08-07-2012 at 04:20 PM.
|

08-07-2012, 07:42 PM
|
 |
Centurion
|
|
Join Date: Jun 2003
Location: New Jersey
Posts: 150
|
|
|
Thanks so much for your help.
I have a few questions if you don't mind...
the fields all have a fixed length, all are different. I have a list here from one of my many failed attempts to do this, just to give you an idea of what the fields look like:
cati_id = Mid(Clean_Rec, 1, 6)
address1 = Mid(Clean_Rec, 7, 35)
address2 = Mid(Clean_Rec, 42, 12)
city = Mid(Clean_Rec, 54, 25)
state = Mid(Clean_Rec, 79, 2)
zip = Mid(Clean_Rec, 81, 5)
zip4 = Mid(Clean_Rec, 86, 4)
filler1 = Mid(Clean_Rec, 90, 1)
geozip = Mid(Clean_Rec, 91, 5)
market = Mid(Clean_Rec, 96, 6)
resp_name = Mid(Clean_Rec, 102, 35)
areacode = Mid(Clean_Rec, 137, 3)
dash1 = Mid(Clean_Rec, 140, 1)
phonest = Mid(Clean_Rec, 141, 3)
dash2 = Mid(Clean_Rec, 144, 1)
phoneend = Mid(Clean_Rec, 145, 4)
age = Mid(Clean_Rec, 149, 3)
respgender = Mid(Clean_Rec, 152, 1)
rind = Mid(Clean_Rec, 153, 1)
You wrote that I should use a custom function to split by field width. I've been trying to figure out how to do this. Do you mean I should call a function to get these values (field widths)?
|
|

08-08-2012, 09:38 AM
|
 |
Bald Mountain Survivor
Super Moderator * Expert *
|
|
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,882
|
|
|
You do not have to use a custom function. What your doing above will work, but as I've said before you really should not be using VB6 tools in VB.NET.
Use the Substring Method instead of the Mid() Function.
cati_id = Clean_Rec.Substring(0, 6)
address1 = Clean_Rec.Substring(6, 35)
Etc...
|
__________________
Burn the land and boil the sea
You can't take the sky from me
~T
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|