'count' is not a member of 'System.Array'??

Answered 'count' is not a member of 'System.Array'??

  • 8. srpna 2012 1:09
     
     

    I'm trying to count the number of lines in a file and I'm getting the error "'count' is not a member of 'System.Array'??"

    This is the code generating the error:

    Dim sLines() As String = System.IO.File.ReadAllLines(Dat_FILE)
            For i As Integer = 0 To sLines.count - 1

    What am I doing wrong?

    TIA! :)

    Joni

Všechny reakce

  • 8. srpna 2012 1:16
     
     Navržená odpověď

    "What am I doing wrong?"

    "'count' is not a member of 'System.Array'??"

    Do you want the Length?


  • 8. srpna 2012 1:17
     
     
    Right, Count is not a member of Array.  Use Length, as in s.Lines.Length - 1.
     

    --
    Mike
  • 8. srpna 2012 1:19
     
      Obsahuje kód

    Another idea:

        Private Function GetNumberOfLines(ByVal filePath As String, ByVal includeBlankLines As Boolean) As Integer
            Dim retVal As Integer
            If My.Computer.FileSystem.FileExists(filePath) Then
                If includeBlankLines Then
                    Using rdr As New System.IO.StreamReader(filePath)
                        Do While rdr.Peek() >= 0
                            Dim itm As String = rdr.ReadLine
                            retVal += 1
                        Loop
                    End Using
                Else
                    Using rdr As New System.IO.StreamReader(filePath)
                        Do While rdr.Peek() >= 0
                            Dim itm As String = rdr.ReadLine
                            itm = itm.Trim
                            If itm <> "" Then
                                retVal += 1
                            End If
                        Loop
                    End Using
                End If
            Else
                Throw New Exception("The file could not be located.")
            End If
            Return retVal
        End Function


    Please call me Frank :)

  • 8. srpna 2012 1:24
     
     

    Yes you're correct.. don't know why I wrote that I wanted to count the number of lines... I think I'm losing my mind! lol

    Do you see a problem with that code?  

  • 8. srpna 2012 1:35
     
     

    Yes you're correct.. don't know why I wrote that I wanted to count the number of lines... I think I'm losing my mind! lol

    Do you see a problem with that code?  


    Then what is it that you're trying to get?

    Please call me Frank :)

  • 8. srpna 2012 2:19
     
     

       Hi Frank :)

    Not really sure anymore.. feel like I'm coding myself into a corner :)

    My main purpose is to validate data.  I'm reading a flat text file and I have to check fields to see if the data is what's expected.  All fields are strings and are fixed lengths (all different lengths), also they have different criteria I need to check for so I have a function for each field.  Here's the condensed version of my code that I have so far.. would you mind taking a look at it?

    Please keep in mind that I am just a 'programmer in training', so to figure this out I'm searching online to find examples of what I think I need to do and then trying to edit them to fit my needs.

    Private Enum eCols
            UserID = 0
            UserName = 1
            Address = 2
            State = 3
            Zip = 4
        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)

    CheckUserID(sCols(eCols.UserID), i)

    CheckUserName(sCols(eCols.UserName), i)

    CheckAddress(sCols(eCols.Address),i)

    Next

    End Sub

    Private Sub CheckUserID(UserID as string, Row as integer)

    if ContainsAlpha(UserID) then lstErrors.Items.Add(Row & " | UserID <> n")

    End Sub



  • 8. srpna 2012 2:24
     
     

       Hi Frank :)

    Not really sure anymore.. feel like I'm coding myself into a corner :)

    My main purpose is to validate data.  I'm reading a flat text file and I have to check fields to see if the data is what's expected.  All fields are strings and are fixed lengths (all different lengths...

    So there's no delimiter at all? Is this your choice of how the file is formatted or is this just something that you've been given?

    You might want to click on the "<>" button to post code (much as I hate using it) - that last bit isn't really readable.


    Please call me Frank :)

  • 8. srpna 2012 2:28
     
     

    I see that you've reformatted it. :)

    Lose the "For i As Integer ..."

    First, check that the line contains the space character, and then if so, simply split it like you're doing. Now you can get the the count of the elements in the resultant array using the ".Length".

    Does that help?


    Please call me Frank :)

  • 8. srpna 2012 2:32
     
     

    Slowly I'm catching on here ...

    Use what I showed initially to read each line. Per line, do your validation.


    Please call me Frank :)

  • 8. srpna 2012 4:07
     
      Obsahuje kód

    thanks Frank :)

    Right now I have it working.. kind of.  Only problem I'm having now is I can't figure out how to define the location of each field.  

    For testing purposes, I just used:

    Dim sCols() As String = sLines(i).Split(" "c)

    What I really need to use, I think, is the string.substring() function but I don't know how to get this into the loop.  Does that make sense?

    For example, this is how I would define UserID if I could just hard code it in:

    Dim UserID As String = sLines(i).Substring(1, 6)

    I know it's late but I'm hoping your still around!  I have a big cup of coffee next to my laptop... think I'm gonna be pulling an all-nighter to get this done.. status meeting in the morning and I got nothing! lol

    Thanks for you help.. I appreciate your time :)



  • 8. srpna 2012 4:12
     
     

    I know it's late but I'm hoping your still around!  I have a big cup of coffee next to my laptop... think I'm gonna be pulling an all-nighter to get this done.. status meeting in the morning and I got nothing! lol

    Thanks for you help.. I appreciate your time :)



    Not sure how much longer I'll be around but let's see how it goes.

    I wish I understood more of the bigger picture. You have a text file; In that text file you have multiple lines. Per line you have ... what?

    Just a whole big long line full of letters and numbers and you have some special secret decoder ring that tells you how many characters to count to mean such and such?

    I don't mean to sound snarky ;-)

    Seriously though, can you explain it better or maybe copy/paste a few lines of this text file then explain what (per line) you need to get from it?


    Please call me Frank :)

  • 8. srpna 2012 4:30
     
      Obsahuje kód

    You don't sound snarky at all.. no worries :)

    Here are a couple of lines from the file (records are not exactly lined up as they are before I pasted but I guess this gives you a better idea):

    100021701 KEXXX ST                                   MENASHA                  NJ549523411 24952321003DORIS ANN SZYMAsssI                222-555-15550782
    100a231181 HXXXEN RD                     APT 2-D     GREEN BAY                NJ543045951 24304321003ANGELINE JdkZ                      222-555-25550912
    1000281792 FXXXTA LN                                 GREEN BAY                NJ543022238 24302321003MICHELLE Bdsd                      222-555-35550432

    Here are the locations of the different fields:

    userid = 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)


  • 8. srpna 2012 4:34
     
     

    We're much closer to done now, but you're making this much too difficult (I'll explain in a bit).

    Is that a tab-delimited file or just random spaces? We can make it work - and I suspect you're closer to answer than you know (but uhh, not the way you're doing it!)

    :)


    Please call me Frank :)

  • 8. srpna 2012 4:42
     
     

    I retract my earlier statement about being close to done ... I just dropped that into a text file - what a mess!

    This looks like some output that's meant for print or something maybe? - and you have to decipher it, not even knowing if there's anything IN a particular field, am I right?

    Do you have any control over the output of that originating file?


    Please call me Frank :)

  • 8. srpna 2012 4:54
     
     

    I don't think it's as much of a mess as you may think.. or maybe that' just wishful thinking on my part! lol

    I wish I could attach a file to show you exactly what it looks like.. everything is pretty neat and lined up, all fields are exactly as I defined a couple posts ago.

    I actually need to load the file into a datagridview and I was going to add a column for 'ERROR' and just put an 'X" in the rows that didn't pass validation, but I was saving that for the end because I don't know how to do it so I"m just outputting the errors into a listbox so I can see if the errors are being caught.

    I'm not validating all the fields, just the ones that should contain all number or no numbers... also, a couple others that should contain only '-' (for phone number) and the last field for gender should be either a '1' or '2'.

    Hope this makes sense... I know I'm all over the place

    I just feel that if I could somehow replace the Split with a Substring that it would work...
  • 8. srpna 2012 5:05
     
     

    I don't think it's as much of a mess as you may think.. or maybe that' just wishful thinking on my part! lol

    I wish I could attach a file to show you exactly what it looks like.. everything is pretty neat and lined up, all fields are exactly as I defined a couple posts ago.

    I actually need to load the file into a datagridview and I was going to add a column for 'ERROR' and just put an 'X" in the rows that didn't pass validation, but I was saving that for the end because I don't know how to do it so I"m just outputting the errors into a listbox so I can see if the errors are being caught.

    I'm not validating all the fields, just the ones that should contain all number or no numbers... also, a couple others that should contain only '-' (for phone number) and the last field for gender should be either a '1' or '2'.

    Hope this makes sense... I know I'm all over the place

    I just feel that if I could somehow replace the Split with a Substring that it would work...

    This may or may not get you any closer, but I see it as an issue in that it's not reliably anything - or so it seems with the three lines that you showed.

    Here's the text file that I used and the code is on a page of my site here.

    The line of code that you'll see the word "Stop" in, will cause the program to halt right there. First, note that I'm using a TextFieldParser and I've set the delimter to two (2) space characters cojoined (ergo: "  ").

    That whittles it down some. Hover your mouse over the variable and note the count. Even in just three lines of text, it may be either of two values. Now expand each one - each may or may not contain spaces, and how many and what they mean seems indeterminate. As an example "APT 2-D" is one logical entry, but how could you know if you only have the space character to go by?

    Now right-click on the word "Stop" and select "Run To Cursor".

    Now it's different than the last line was. Do that again and it's changed again.

    Do you have any control at all over the text file that's being generated that you're trying to use? Putting it all together in to a DGV won't be hard if we can absolutely figure out what's what and where it needs to go.


    Please call me Frank :)

  • 8. srpna 2012 5:22
     
     

    Wow you're amazing!  I'm impressed, that the first time I copied someone's code and didn't receive an error, not even a warning :)

    I know what you're saying... there's absolutely no way to use a delimiter on separate the fields, sometimes a field will have some type of text, sometime it will just be completely blank.. sometimes address will have 20 character, sometimes 10.  One thing that is consistent though is the position of each field.  For instance, address1 will always start in the 7th column for a length of 35, address2 will always start in column 42 for a length of 12, etc.   

    There has to be a way to define the location of each field..?

    I have to say over the file.. it is what it is, that's how we get it :(
  • 8. srpna 2012 5:25
     
     

    Wow you're amazing!  I'm impressed, that the first time I copied someone's code and didn't receive an error, not even a warning :)

    I know what you're saying... there's absolutely no way to use a delimiter on separate the fields, sometimes a field will have some type of text, sometime it will just be completely blank.. sometimes address will have 20 character, sometimes 10.  One thing that is consistent though is the position of each field.  For instance, address1 will always start in the 7th column for a length of 35, address2 will always start in column 42 for a length of 12, etc.   

    There has to be a way to define the location of each field..?

    I think I need more beer ........

    Well maybe, if it's consistent then I think so. :)

    Can you tell me a list of how many characters (from the start of the line) and what that "field" is at that position?


    Please call me Frank :)

  • 8. srpna 2012 5:29
     
     

    I think what you're asking for is in my post above where I pasted a few line of the file.  Am I right?  If not, I'm not sure what you're asking.

    ... More BEER!  You can drink AND code... You're the man!! LOL

  • 8. srpna 2012 5:34
     
     

    I think what you're asking for is in my post above where I pasted a few line of the file.  Am I right?  If not, I'm not sure what you're asking.

    ... More BEER!  You can drink AND code... You're the man!! LOL

    ...all at 12:34 AM on an early Wednesday morning, but that aside ...

    Anyway, aside from using Mid (let's move away from that, but not now if it's working?), what happens when you run that? What is the function "Clean_Rec"? Have you put a breakpoint in if it's not working? Where does it fail?


    Please call me Frank :)

  • 8. srpna 2012 5:40
     
      Obsahuje kód

    I'm in Jersey.. an hour ahead of you, it's 1:34 here :)

    I"m not actually using that code anymore, that's one of my desperate earlier attempts that didn't work, but the locations are correct for the fields.  

    Clean_Rec is what I was calling the string that contained the record, I was reading each line one at a time.

    Here's the code I'm NOT using.. can you tell I don't know what I"m doing???

    Dim Clean_FILE As String = "C:\Dev\VendorBuilderPro\VendorBuilderPro\output_files\qctest.dat"
    
            If System.IO.File.Exists(Clean_FILE) = True Then
                Dim RptReader As New System.IO.StreamReader(Clean_FILE)
                Dim Clean_Rec As String
                Dim cati_id As String, address1 As String, address2 As String, city As String, state As String
                Dim zip As String, zip4 As String, filler1 As String, geozip As String, market As String
                Dim resp_name As String, areacode As String, dash1 As String, phonest As String
                Dim dash2 As String, phoneend As String, age As String, respgender As String, rind As String
                Do While RptReader.Peek() <> -1
                    Dim CleanCheck As String = "PASS"
                    Clean_Rec = RptReader.ReadLine() & vbNewLine
                    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)

  • 8. srpna 2012 5:42
     
     

    I think I'm a little more clear now.

    Would you agree, then, that each line is exactly 154 characters or, if not, it's a malformed line of data?


    Please call me Frank :)

  • 8. srpna 2012 5:44
     
     
    You are correct Sir! :)
  • 8. srpna 2012 5:46
     
     
    You are correct Sir! :)

    Give me thirty minutes - let's see what I can come up with.

    Please call me Frank :)

  • 8. srpna 2012 5:47
     
     
    The way I'm validating the data is certain fields will only contain numeric data, others will only contain alpha characters, others (like dash2 and dash1) must be a "-"., respgenders need to be either a '1' or '2'
  • 8. srpna 2012 5:50
     
     
    The way I'm validating the data is certain fields will only contain numeric data, others will only contain alpha characters, others (like dash2 and dash1) must be a "-"., respgenders need to be either a '1' or '2'

    Let's see if we can get the stuff at all first, then we'll get to validation, then we'll get to a dataset and from there, a short leap to a DGV.

    Patience Danielson, patience...


    Please call me Frank :)

  • 8. srpna 2012 6:00
     
     
    Right about now I'm guessing you're wondering what the heck you got yourself into... based on the title of my thread it seemed like a pretty easy question to answer :)  I really do appreciate all the help you're giving me, you've really going above and beyond!  The world would be a better place if there were more people like you
  • 8. srpna 2012 6:03
     
     
    You are correct Sir! :)

    I'm coming up with 152 characters per line for each of the three sample lines.

    We need to recalibrate or something?

    Please look again at the text file in the link I posted - and tell me the positions of the items?


    Please call me Frank :)

  • 8. srpna 2012 6:06
     
     

    the last field, rind, is blank.. that's something, I'm told, will be added later (don't ask me why).  So 1 blank is okay there, or we could just ignore it all together for now if that's easier

    I'm not validating that field, I just need to have a column shown for it in the table, even if it is just all blanks

  • 8. srpna 2012 6:08
     
     
    the last field, rind, is blank.. that's something, I'm told, will be added later (don't ask me why).  So 1 blank is okay there, or we could just ignore it all together for now if that's easier

    So far there's nothing easy about this!

    ... ok ... bear with me then.


    Please call me Frank :)

  • 8. srpna 2012 6:27
     
     

    Joni,

    This isn't working out right. Have a look at the code here. I took a chance on thinking that you weren't aware that the functions we're using (whether Mid or SubString) are zero-based, am I right? At any rate, I changed the starting point back exactly one, but it's still not working right.

    Run that code on my example text file and when it gets to "Stop", have a look at the instance of the class created ("thisUI"). Hover your mouse over it and expand each field.

    Let me know please?


    Please call me Frank :)

  • 8. srpna 2012 6:35
     
     
    I just did what you asked and it looks correct to me...  I'm not sure what you're seeing that's not okay

    -Joni :)

  • 8. srpna 2012 6:36
     
     
    I just did what you asked and it looks correct to me...  I'm not sure what you're seeing that's not okay

    -Joni :)

    Oh!

    Ok - then I'll continue. I wasn't sure, honestly, what it was supposed to look like.

    Be back shortly then...


    Please call me Frank :)

  • 8. srpna 2012 6:38
     
     
    I thought you were messing with me for a second.. it's perfect!! :)

    -Joni :)

  • 8. srpna 2012 6:44
     
     
    I thought you were messing with me for a second.. it's perfect!! :)

    -Joni :)


    Ok, have a look at this one then. Change the path to your "real" file and then when it gets to "Stop", hover your mouse over the class-level variable called "uiList" near the top. Click each to expand it and let's see how that looks?

    Please call me Frank :)

  • 8. srpna 2012 6:51
     
     
    I'm so sorry.. I'm not sure where you want me to click.  I see the  Private uiList As New List(Of UserInfo) but nothing  under.. am I looking in the correct place?

    -Joni :)

  • 8. srpna 2012 6:54
     
     
    I'm so sorry.. I'm not sure where you want me to click.  I see the  Private uiList As New List(Of UserInfo) but nothing  under.. am I looking in the correct place?

    -Joni :)

    You changed the path to wherever your real file is, right?

    If so, when it got to Stop and you hovered your mouse over the variable up top called "uiList", did it show 0 for the count?


    Please call me Frank :)

  • 8. srpna 2012 6:55
     
     
    nevermind... I figured it out. It looks awesome!  You're like a  magician :)

    -Joni :)

  • 8. srpna 2012 6:59
     
     
    nevermind... I figured it out. It looks awesome!  You're like a  magician :)

    -Joni :)

    Ha!

    Hardly so - and I'll explain every part of it in time, but right now, there's a deadline looming. I have to be "back up" in four hours but I'll stick it out as far as I can.

    What's next? Data validation? I already see things that need to be modified (in time) but to get you something workable, tell me what's next.


    Please call me Frank :)

  • 8. srpna 2012 7:04
     
     

    The fields that can be validated are:

    cati_id - 6 digits

    city - all alpha

    state - 2 alpha characters

    zip = 5 digits

    zip4 = 4 digits

    filler - 1 blank

    geozip - 5 digits

    market - 6 digits

    areacode - 3 digits

    dash1 and dash2 - should be "-"

    phoneend - 4 digits

    age - 3 digits

    respgender - must be either a '1' or '2'


    -Joni :)

  • 8. srpna 2012 7:10
     
     
    Ok - this will take a bit. Give me another 30 minutes or so...

    Please call me Frank :)

  • 8. srpna 2012 7:12
     
     
    I'm with you as long as you'll hang in there with me

    -Joni :)

  • 8. srpna 2012 7:32
     
     
    I'm with you as long as you'll hang in there with me

    -Joni :)

    Ok, this late at night, function over form right? ;-)

    We can modify it later but this should work:

    http://www.fls-tech.com/VBNet_Forum/08-08-12/Example_Code_03.htm

    Let me know if it does or if not, where it stalled.


    Please call me Frank :)

  • 8. srpna 2012 7:37
     
     

    It ran all the way through without stalling :)

    Is there something I should be looking at/checking when it hits 'stop'?


    -Joni :)

  • 8. srpna 2012 7:40
     
     

    It ran all the way through without stalling :)

    Is there something I should be looking at/checking when it hits 'stop'?


    -Joni :)

    No, but you can see that it did test each entry prior to letting it be added to the list. We can improve a LOT of this later - but for now "it'll do".

    Ok, what's next?


    Please call me Frank :)

  • 8. srpna 2012 7:44
     
     

    What's next.. your still with me??!  You're a trooper :)

    After the validation I have to put the whole file into a datagridview and add a column for "ERROR".  When there's a records where any of the fields fails the validation, I need to put an "X" in the "Error" column for that row to flag it for the user when they view the table.  



    -Joni :)


  • 8. srpna 2012 7:47
     
     

    What's next.. your still with me??!  You're a trooper :)

    After the validation I have to put the whole file into a datagridview and add a column for "ERROR".  When there's a records where any of the fields fails the validation, I need to put an "X" in the "Error" column for that row to flag it for the user when they view the table.  



    -Joni :)


    If there's an error, it won't be added to the list (in the last step).

    There's a better way to handle it anyway though, can we just skip that part for now?


    Please call me Frank :)

  • 8. srpna 2012 7:52
     
     

    That's pretty much the last thing I need to do for now.

    No worries though... it is really late (or should I say 'early'? lol)

    You've really helped me more than I would have ever expected!  I can try to figure out the rest... you should go and get some sleep :)

    THANK YOU SOOOOOOOOOOOO MUCH!  Words can't express how thankful I am!!

    Sweet Dreams :)


    -Joni :)

  • 8. srpna 2012 7:56
     
     

    That's pretty much the last thing I need to do for now.

    No worries though... it is really late (or should I say 'early'? lol)

    You've really helped me more than I would have ever expected!  I can try to figure out the rest... you should go and get some sleep :)

    THANK YOU SOOOOOOOOOOOO MUCH!  Words can't express how thankful I am!!

    Sweet Dreams :)


    -Joni :)

    I won't argue!


    Please call me Frank :)

  • 8. srpna 2012 8:17
     
     Odpovědět

    I hate to leave anything incomplete - you said DataGridView, so here ya go!

    http://www.fls-tech.com/VBNet_Forum/08-08-12/Example_Code_04.htm

    ...and with that, I'll shut off the lights.

    Please call me Frank :)

    • Označen jako odpověď Joanie Brows 8. srpna 2012 17:07
    •  
  • 8. srpna 2012 8:19
     
     

    You're my hero!!  How did you know I was struggling??

    YOU ROCK FRANK!!!! :)


    -Joni :)

  • 8. srpna 2012 16:48
     
     

    You're my hero!!  How did you know I was struggling??

    YOU ROCK FRANK!!!! :)


    -Joni :)

    :)

    I'll be curious to know how you made out with it in the meeting.


    Please call me Frank :)

  • 8. srpna 2012 18:51
     
      Obsahuje kód

    It went well... they didn't even look at it in too much detail, just basically wanted to see that I had something.  Kind of disappointing, after all that I expected a parade with balloons and fireworks!! lol   

    I was actually able to add another column to the table for 'ERROR' and place an 'X' in the row where a record doesn't pass the validation.  I also changed a couple of the validating 'if' statements.  I created a bunch of test data to make sure all exceptions would be caught and came across a few that were passing when they shouldn't.  I didn't understand how a few of them worked so I tried to simplify them a little so I would understand.  For example:

    This wasn't catching non-numeric instances

    If thisUI.CATI_ID.Length = 6 Then
        For Each c As Char In thisUI.CATI_ID.ToLower
              If Not Asc(c) >= 97 AndAlso Not Asc(c) <= 122 Then
                       okToAdd = False
              End If
         Next
    Else
    okToAdd = False
    End If
     

    I wasn't sure how the above worked so I replaced it with:

    If thisUI.CATI_ID.Length = 6 Then
       For Each c As Char In thisUI.CATI_ID.ToLower
             If Not Char.IsDigit(c) Then
                   thisUI.ErrorMark = "X"
              End If
        Next
    Else
    thisUI.ErrorMark = "X"
    End If
    

    That seems to be working.

    I really appreciate all the help you've given me... looking at the code I can't imagine being able to come up with it myself in such a short amount of time.  There are some parts I don't understand and I plan to research them more to figure out how they all work, not today though, too tired - it was 7am here when I finally called it quits, I woke up at 8:30, working from home today :)  

    What we worked on last night was just one piece of a project I was put on.. my first big project so I'm trying to break it down into little pieces.  Not sure if I mentioned this, but I'm not a programmer, or maybe I should say I'm not a very good programmer?? lol   I took a quickie 9 month programming course at a trade school 13 years ago where they taught mostly COBOL.  When I finished the course I started working at the company that I'm at now where I coded in COBOL for a couple years and then they gave me VB6 to work with. I've used that for about 10 years.  Programming has never been my main responsibility so I never had to do anything too intense as far as code goes.. but I did enjoy it, was fun trying to figure things out, kind of like doing puzzle :)  Anyway, around 2 months ago I started reporting to a new supervisor.  He put me on this project with another programmer (who has TONS more experience than me and a degree in computer science) and wants it done in VB.net , not to mention other areas of the project that deal with Visual FoxPro, both of which I've never used in my life.  I expressed to him that I was uncomfortable being on this project, that I really don't know VB.net or FoxPro and that I didn't want to hold anyone else up.  He says he looked at my VB6 code and thinks I can handle it.  I do agree, I know I can do it, eventually, just not when there are deadlines and no time for training.  It's like he expects me to jump in and code without first learning.. 

    Anyway, not sure why I just told you all that.. guess I just feel like I can talk to you...that's what you get for being so super nice! lol

    ...or maybe it's just my lack of sleep - that combined with the fact that I can't remember the last time I pulled an all-niter with a complete stranger! Lmao :)

    Well, enough about me.  Hope you're doing okay today.  I felt so bad last night that you were up so late helping me but I had no where else to turn.  It was like you were an angel sent from above to help me in my time of need.  Thanks again.. you've helped me more than you know :)


    -Joni :)

  • 8. srpna 2012 19:01
     
     

    Joni,

    It was late - I was in a hurry, so I don't doubt that it doesn't work properly. I'm glad you tested it - in "the real world" that's the only way to know.

    I see several issues with the way that I do it, but the first thing is an exception being thrown at a level higher than validation. If that happens, then *bang* - game over - it won't continue.

    A better way would be to create a function wherein we send it a given line and ask it to send us back an instance of the class that was created. In that function we do validation and if it fails (or a level higher than that fails), then we could do one of two things:

    1) Return nothing (and in the calling code, test that it's not nothing before adding to the list)

    2) Create "dummy text" that goes in those fields to indicate that the line couldn't be parsed, along with keeping a log (separately, using another class and list of class).

    Then if a particular line blows up, it doesn't stop the entire thing.

    Other things that I would change - but of course it's your specification, not mine - would be things like gender being a number? No - make it "Male" or "Female". It would be easy. And age - I was 52 last year, but I've never been "052". ;-)

    Setting each up for strings last night was a quick and easy thing - but long term, it's not great. It would make things like sorting and finding/filtering difficult.

    Lastly, will this eventually go into a database? I have no idea about FoxPro either - my choice would be SQL CE. Is that not an option?

    Anyway, I'm glad it helped. :)


    Please call me Frank :)

  • 9. srpna 2012 23:09
     
     

    Frank,

    Unfortunately it has to be FoxPro, but the other programmer I'm working with is a wiz with FoxPro and she offered to give me a hand with that portion :)

    As far as the format of the file, I can't change any of that.  Once all is said and done the file gets sent out to third party processors who also work with that format so to change it would be a big deal.  The file is used for alot of different things, so alot of other programs would have to be changed to look for 'male' or 'female' rather than '1' or '2'.  As far as age goes, I guess it's set up that way in case there's ever a respondent that's 100+ years old.. I'm not sure that's ever happened but I guess they want to reserve a 3 character field just in case :)

    I don't believe this will become part of a database.. I actually just had that discussion with my supervisor.  From what he told me, we rarely ever work with databases, just free tables.

    Whether the data passes validation or not, I still have to write that line out to the table, display it to the user, write out a detailed error log (text file format) and give the user the option of manually fixing the records that have errors with the DGV or cancel processing until they get a new/correct file from our other office.  Since the table is getting loaded regardless of whether or not the file is correct, do you think think we need to do all that fancy validation you're talking about?

    Thanks a bunch :)

    Joni


    -Joni :)

  • 10. srpna 2012 21:28
     
     

    Joni,

    My apologies for taking so long to reply. I have several fairly involved projects going on and, as Murphy sees to it, they all "need something right now" at the same time (I'm an engineer, not a programmer!)

    At any rate, I took a few hours to put something together that I'm hoping will get you at least closer to your end goal. I still want to explain every step of the way (if you're interested that is?), but phat lot of good that would do if this isn't what you want, so I'd like to show the version, show the code, and also hand over the program (zipped up) for you to try yourself. If it's even a little bit close, it's bound to get you to your end goal faster.

    The basis of the program is to do some "pre-checking" before trying to read it into the table. There are two steps of that: Testing first to see if any of the lines are malformed and then next checking to see if any of the fields don't pass validation. Once it passes both tests, it then does "the real deal" and loads the data into the ListOf(Class) which is then used to build the table.

    The new UI looks like this:

    Please note that I took a copy of my "JoniFile" and modified it so I could do at least some preliminary testing. I only have three lines of data though, so I'm depending on you to do more thorough checking.

    When the user clicks the "Open File" button on the menu bar, they'll be presented with a standard Windows OpenFileDialog:

    The program will first test to see if any lines are malformed and, if so, show the user the issue:

    At that point, the program will close. As you see above, it does give them some aid in knowing where to look to fix it, but I don't offer to repair it for them in the program. You might want to alter that.

    Assuming there are no malformed lines of data, it next tests for a malformed field in any line of data. If it spots one, a second form will open as shown here:

    When they re-enter the data, it's tested again and will show an ErrorProvider if one still exists and will lock them in to having to change it to something valid. As you see above, it gives them information to know how the program is expecting the data to be formatted in order to be acceptable.

    Once they modify it:

    The program will re-check that entire line and continue to do so (and all other lines) until there are no more field errors. Note that the corrections are NOT dont with the text file; it's all done strictly in memory. In fact, the text file is opened only once, read into a ListOf(String) and then closed. The text file, at that point, is no longer in play (and that's the safest way to do things - open it, read it, record it, close it).

    Once everything finally passes all tests, it builds the table as before:

    The code is shown on two pages of my website as shown below:

    Form1.vb

    ModifyField.vb

    Also, the entire project folder is zipped up and uploaded, available here.

    Let me know your thoughts please? The code has very little commenting and, as I said, I'm glad to go through all of it thoroughly but I first want to see if I'm on track for what you have in mind.

    I hope this helps. :)


    Please call me Frank :)

  • 12. srpna 2012 23:32
     
     

    Wow Frank!  Thank you :)

    I'm going to look through it all now, you really went above and beyond!  If you have time to explain it sometime I would love that.. I really want to understand and learn all of this so I don't have to constantly ask for help from others.

    Please don't apologize about the time it takes you to respond, I'm lucky you respond at all - lol.. I understand you have a life too :)

    I'll let you know how it goes...


    -Joni :)

  • 13. srpna 2012 2:02
     
     

    Awesome!  You really put alot of time into that...thanks so much!

    Because you put so much time and effort into it, I feel terrible having to say that it's not exactly what I need to do.  The problem is that the user requested to not have any pop up windows in case of error.  See, they actually already have a system that they've been using that they're not crazy about and that's sort of what it does (yours is way better by the way :) ).  What they really want is for the DGV to be loaded, line by line, from the text file, whether or not the data is correct.  Pretty much like what you already had.  The difference would be that when there is a field that doesn't pass the validation, the error should be written out to an error log file that specifies the line of the error, what field(s) contains the error and a copy of the record.  Once the DGV is all loaded and all the records/fields have gone through the validation process there should be a label on the form that displays the number of errors ("No Errors found" or "12 Errors found").  At this point, if there are errors, the user should be given the option as to whether or not they want to fix the errors manually (changes would be made to the DGV to fix any errors) or cancel all processing at this point so they could request a new file from our other office.  There should be an extra column in the DGV titled 'ERROR' and a mark (I've just been putting an 'X') should be placed in each row that contains an error.. this way it would be easier for the user to scroll through and find the lines with errors and make corrections.  99% of the time, when there is a line that doesn't pass verification, it's because there's a field missing (which is okay) in the record so the data falls into the wrong fields, so all they need to do is just go in and move the data into the proper fields in the DGV.  There should also be a button on the form, in case of errors, that allows the user to open the error log to help them determine if they're able to make the corrections manually or if they need a new file.  This makes it easier for them to find the line that's 'off' and manually fix it (the files that go into this could have up to 50,000 records).  Once the DGV is fixed, they could click a button on the form to revalidate (the revalidation would be on the data in the DGV, not the original file)  and if it passes then the data in the DGV would be transferred over to a FoxPro table (my partner on this project is supposed to help me out with this part).  Does this make sense??   Hope I didn't ramble too much, I tend to do that sometimes :)

    On another note, please don't feel like you have to do this for me.  Your help is MORE than welcome, I really appreciate it (I know I've said that 100 times but I really do mean it!), I just feel a little guilty that you've put so much time and effort into this, I'm hoping it's because you're enjoying yourself and not because you feel obligated.. I would hate to be a burden...

    THANKS AGAIN!! :)

    Joni


    -Joni :)

  • 13. srpna 2012 2:55
     
     

    Joni,

    We seem to have noncoincident timing. ;-)

    When you said "99% of the time, when there is a line that doesn't pass verification, it's because there's a field missing (which is okay) in the record so the data falls into the wrong fields, so all they need to do is just go in and move the data into the proper fields in the DGV."

    Then it wouldn't pass the first test - because the length wouldn't be correct ... or am I wrong about that?

    I'm just trying to envision how this can be done and it seems to get more twisted at each step!


    Please call me Frank :)

  • 13. srpna 2012 3:04
     
      Obsahuje kód

    You are absolutely correct!  Well, at least you can't assume the data is bad because of the length.   Data most likely is good but is just in the wrong position.  Here's a basic example of what could happen:


    Sorry.. I edited it a bunch of times to get it to display correctly.. there's no way to preview, unless I'm missing it.  

    Anyway... line starting 104041 is has valid data, just not in the right position.. in this case the user would just fix it in the DGV

    104037                                               COLORADO SPRINGS         CO809180918 80920321005MALE 47                             555-333-10950471
    104041                                               CO80921321005FEMALE 42                           555-444-53950422
    1040511411 W Pxxxx xxx AVE        COLORADO SPRINGS         CO809044046 80904321005YOLANDA ROxxxxS          555-333-67960482

    ***Address, phone numbers and names were edited :)


    -Joni :)
















  • 13. srpna 2012 3:17
     
     

    Joni,

    If that's real data - actual person's information - please remove it.

    We can't use the DGV to show the real data AND the errant data - remember, it's showing the data that was parsed but this can't be parsed so that's out ... it would be nothing more than garbled data. If they don't want to use other forms, then maybe we could use a split container with other controls in the bottom or something, but I really don't know what's wrong with using another form.

    I want to think about how best to do this - heck how to do it at all - especially with the new constraint of Pop-Up Form-a-phobia.

    We'll talk again soon. Monday morning is looming on the not too distant horizon and Lord don't we all love Monday mornings! ;-)


    Please call me Frank :)

  • 13. srpna 2012 5:14
     
     

    I'm responding now but by no means do I expect a response now.. please get a good night's rest :)

    I'm not sure if I'm understanding correctly, or maybe I'm confusing you :)

    Basically, I just want to populate the DGV based on the layout I'm expecting with whatever is in text file - checking it as the table is loaded and writing info to a error log if anything looks funny (but still adding the the table).  Every time a record is written to the 'error log' add to an error counter so once the file is done being loaded into the DGV we would have a count of how many lines we presume to have errors (this count would be displayed through a label on the form).  The user could view the error log for a more detailed explanation (line number and copy of record) of what we suspect to be errors.  Now that they know the line number of the suspected error(s), they could scroll through the DGV and make any necessary corrections.  Once they've fixed all errors, they could re-validate to ensure they didn't miss anything and at that point they could load it into FoxPro (there's a main table in FoxPro that I have to append to).  

    So.. I'm not trying to display 2 different sets of data in the DGV, just what's in the text file, correct or not so the user can make corrections if they need to before appending into the main FoxPro table.  

    I feel like what you had last time was really close.  The validation was missing a few things but working for the most part.  The only thing missing was writing to the error log and the re-validation of what's in the DGV after corrections.  Is that not possible?


    -Joni :)

  • 13. srpna 2012 16:02
     
     

    Joni,

    I’ll try to answer some of what you asked here:

    Basically, I just want to populate the DGV based on the layout I'm expecting with whatever is in text file - checking it as the table is loaded and writing info to a error log if anything looks funny (but still adding the the table)…

    … So.. I'm not trying to display 2 different sets of data in the DGV, just what's in the text file, correct or not so the user can make corrections if they need to before appending into the main FoxPro table.  

    I feel like what you had last time was really close.  The validation was missing a few things but working for the most part.  The only thing missing was writing to the error log and the re-validation of what's in the DGV after corrections.  Is that not possible?

    I wanted to explain all of this eventually but one part that I don’t think you’re understanding is this: The DGV isn’t the text from the file; not exactly. Yes it was sourced from it, but you’re missing what’s happened in between reading the line of text and it showing up in the DGV.

    “Ok so if it’s not, then what is it?”

    Good question! ;-)

    It’s the values that came from an instance of the class named “UserInfo” and that particular line of data shown in the DGV is one of those instances in the ListOf(UserInfo).

    Like I said, it all came from the line of text read in, yes – but since then it’s had to pass the various validations. If it didn’t then it can’t be parsed and those values in the instance of “UserInfo” won’t exist.

    I suppose that we could wheedle something into a row of the DGV (maybe, I won’t swear that part either), but even if we do, that would make for a mess. Trying to modify it in the DGV would be cumbersome at best and downright annoying because the value in one cell has no influence over the value in another cell.

    You said that most of time the error is from missing information. So the user *could* potentially modify the line to have that information – but using the DGV to do it with would be annoyingly difficult.

    It needs to stay as a line of text – and modified as a line of text – then once everything is right with that line of text, the information is added into the DGV.

    My opinion here obviously, but do you agree?

    To that end, I’d like to propose another way to do it. Let’s say that the information is read in and each line either passes all validation (that’s for a malformed line or invalid field information) and is added – OR – it’s put into a list purely as that line of data.

    Whether this next part is done in a separate form or another area of the same form, here’s my thoughts:

    Allow the user to “load up” one of those lines of errant data into a TextBox (or a RichTextBox shown in the following), and once loaded, let the program allow the user to both show the errant information and allow them to edit it on the fly.

    I took one of the three lines of data that you gave me the other night to work with and simply added two blank spaces in front then ran this test:

    You can see the erroneous information highlighted with orange. Now I remove one of the leading spaces:

    … and finally now, remove the other leading space:

    The user can clearly see that this line is now valid and can be added.

    Tell me what you think of this concept?


    Please call me Frank :)

  • 13. srpna 2012 16:43
     
     

    I think you're brilliant!!!  I never would've come up with that!

    Would it still be possible to create an error log?  Maybe a text file that displays the line of errant data 'before' and 'after' modification with the line number?  I think they want to keep a record of this..


    -Joni :)

  • 13. srpna 2012 16:49
     
     

    Would it still be possible to create an error log?  Maybe a text file that displays the line of errant data 'before' and 'after' modification with the line number?  I think they want to keep a record of this..


    -Joni :)

    Sure we could do that.

    Before we get too much further along though, I want to throw something else out: Early on we talked about two "styles" - one with an additional field at the end (and the length was then 154 rather than 152).

    What do you think about let's include it in all of them? If the line is 152 then we append "--" to it and that will be made to pass as valid?


    Please call me Frank :)

  • 13. srpna 2012 17:23
     
     

    I think that would be a great idea!  I just found out that it would actually be a 1 digit field, column name would be 'R Ind' (short for  'Release Indicator') and it would be either a '1' or '2'.  It's not something that's in the text file so it would be added at run time when creating the table.  We're starting release 2 now so it would default to '2'.


    -Joni :)

  • 13. srpna 2012 17:30
     
     

    I think that would be a great idea!  I just found out that it would actually be a 1 digit field, column name would be 'R Ind' (short for  'Release Indicator') and it would be either a '1' or '2'.  It's not something that's in the text file so it would be added at run time when creating the table.  We're starting release 2 now so it would default to '2'.


    -Joni :)

    Ok, to be clear then, it won't be 154 long, it will be either 152 long (as it is in the examples you gave me) or 153 long, the last one being a digit of either 1 or 2, correct? What should I use to show that nothing was in it (i.e., it was a 152 line) - a 0 maybe?

    How you do you envision using what I presented earlier? On the same form (it'll be a long form though) or maybe put everything in tab pages?

    I'm thinking about what you said before too - that it might be 50,000 lines. If so, even 1% of them having an error would mean that someone has to manually go through 500 errant lines and fix them? That's a day's work in itself.

    I'm having to guess a lot about what the end game is - I don't mean to be nosey. Let's say that you have everything in the DGV (50,000 lines would be really difficult to navigate through), what's next? This part is done now, or do you create some sort of "output" text or ...?


    Please call me Frank :)

  • 13. srpna 2012 17:53
     
     

    the records coming in would be 152 long, the release indicator isn't in the original file but should be added to the table.  What the release indicator will be is determined by the file they are loading.  For instance... the file I'm working with now is named R112BLUE_AD.DAT (all filenames are in the same format).  I figured I could assign the filename as a string and just use the substring function to get the release.  Is this what you're asking?  Am I making sense?

    There's a part I'm a little unclear about before I can say what my 'vision' is... Is the DGV loaded completely and then the user is prompted to fix errors or is that window shown as the DGV is being loaded and then continues to load once the error is fixed?  Once I know that I'll have a better idea of how it should function.

    BTW..There are hardly even any errors.. the big file I'm working with now only has 3 so I doubt there would ever be a case when there are 500.  10 would be alot.  

    I don't think your being nosey at all.. Ask away!! lol  You're helping me so much I hate to see you put in all that time and then have me tell you 'that's not what I'm trying to do'


    -Joni :)

  • 13. srpna 2012 18:13
     
     

    the records coming in would be 152 long, the release indicator isn't in the original file but should be added to the table.  What the release indicator will be is determined by the file they are loading.  For instance... the file I'm working with now is named R112BLUE_AD.DAT (all filenames are in the same format).  I figured I could assign the filename as a string and just use the substring function to get the release.  Is this what you're asking?  Am I making sense?

    There's a part I'm a little unclear about before I can say what my 'vision' is... Is the DGV loaded completely and then the user is prompted to fix errors or is that window shown as the DGV is being loaded and then continues to load once the error is fixed?  Once I know that I'll have a better idea of how it should function.

    BTW..There are hardly even any errors.. the big file I'm working with now only has 3 so I doubt there would ever be a case when there are 500.  10 would be alot.  

    I don't think your being nosey at all.. Ask away!! lol  You're helping me so much I hate to see you put in all that time and then have me tell you 'that's not what I'm trying to do'


    -Joni :)

    Right now it's been somewhat quiet today (I work from a home-office, well usually) but that usually means that it'll all flare up at once so that's why I'm able to reply back so quickly right now. Please do note that's ephemeral though - subject to change on a moment's notice. ;-)

    How about tell me how to "read" the file name so I can do that in the program. It needs to be added in per line so it needs to be known when the file is loaded and used for all lines from that point forward. Also, what if what it's looking for (a "1" or a "2") isn't there? I need to give it a fallback, lest something come along that causes an exception. I could, if you want, make it stop the program, issue a warning, and close if it's not able to figure out the version. Would there be a chance that in the future it might be a "3" or somehting else?

    As for program flow, it's up to you how it's done. What I thought about was this though:

    The data is read in and each line stored in a list. The text file is now closed and the reader disposed. The file is now "out of play" and safe.

    I'll then have two more lists:

    - Dim validLines As New ListOf(String)
    - Dim erroroneousLines as New ListOf(String)

    It reads through each line in the first list and determines which of those two lists it belongs in and places them there. It then empties that first list (for memory sake).

    If there are any valid lines in the valid list, it builds the DGV based on what it knows - and that's shown on one tab page of a TabControl.

    If there are any lines in the erroneous list, it will then show a second  tab where they can modify those lines by "loading them" one at a time. As they make them good (assuming they can ... they can't know the phone number if it's not in there), then they click a button to "add to the valid list".

    When it's added, the program will rebuild the DGV so that any sorting order will be preserved and that line is then removed from the erroneous list (you can think of this as "moving it from the bad list to the good list, but it's actually two separate operations).

    All of this is just me thinking out loud here; nothing is carved in stone about how the program flows.

    Tell me your thoughts please?

    Also, can you post one line where there's some missing information in it? I'd like to test what I did before using one that's more typical. Please do tell me what's missing though. :)


    Please call me Frank :)

  • 13. srpna 2012 19:31
     
      Obsahuje kód

    (1) The first thing that happens is the user is asked to select release from a pull down menu on a splash screen.

    (2) once release is selected, a browser window opens that defaults to directory F:\PD\AddOut and displays only files that follow this pattern:

    '*(release selected)*.DAT'  (ex. R112BLUE_AD.DAT)

    (3) file is selected and is copied to working directory (right now it's C:\dev\vendorbuilderpro\vendorbuilderpro\Input_files) along with it's corresponding file of the same name but .RPT extension instead of .DAT (these files are compared later on - didn't want to bother you with that but you asked for it! lol)

    if either of these 2 files already exists in input_Files directory I do a comparison of the time\date stamps.  If they are different I copy the file that already exists in Input_files directory to C:\dev\vendorbuilderpro\vendorbuilderpro\backup before copying the new file(s) in.

    (4) Now I read the .RPT file and create an array of the info that I need to compare against the .DAT file to make sure it matches.  This .RPT file is short and just basically gives what we expect to be in the .DAT.  Here's what it looks like:

    The info I need is 'Market' and 'Total Rcds'  This is the count expected of the total number of records for each market in the .DAT file. It starts in the 11th line of the file.  Market starts in the 1st column and is always 6 digits long.  Total Rcds starts in the 15th column and is the last piece of data in the line.

    Here's the code I was using to do this.. I have a feeling you're not going to be crazy about it but I'll show you non-the-less :)

    If System.IO.File.Exists(Rpt_FILE) = True Then
                Dim RptReader As New System.IO.StreamReader(Rpt_FILE)
                Dim Rpt_TotalRecs As String
                Do While RptReader.Peek() <> -1
                    Rpt_REC = RptReader.ReadLine() & vbNewLine
                    'Dim Rpt_REC_Length = Rpt_REC.Length - 15
                    Rpt_CNT = Rpt_CNT + 1
                    If Rpt_CNT > 10 Then
    
                        'Rpt_TotalRecs = Mid(Rpt_REC, 15, Rpt_REC_Length)
                        Rpt_TotalRecs = Mid(Rpt_REC, 15, 10)
                        Rpt_TotalRecs = Rpt_TotalRecs.Trim
    
                        Rpt_Code = Mid(Rpt_REC, 1, 6)
                        Rpt_Blank = Mid(Rpt_REC, 1, 1)
                        Add_switch = True
                        If IsNumeric(Rpt_Blank) = False Then
                            Add_switch = False
                        End If
                    End If
    
                    If Add_switch = True Then
                        Rpt_List.Add(Rpt_Code)
                        RptTotl_List.Add(Rpt_TotalRecs)
                    End If
                Loop
            End If

    The .DAT file is already sorted by market number so I would need to perform a count of records per market and save the info in a table/array to compare against.  If all counts match then proceed.. if they don't then display message of a 'miscount' and display a report showing where the miscount is and don't load table.

    (4) This is where you came into the picture :)

    Loading the DGV and validation.  There's something here to keep in mind.. there WILL be some blank fields, not all records contain all data, this is okay.  The two fields that always have info are cati_id and market.  When a field contains data that's invalid (numeric when it shouldn't be or vice versa), that's the instance when we would give the user the option to fix it.  In case of a blank field (there will be lots), there should be a report generated showing line number and list of blank fields.  AGain, this is most likely okay, they just want to be able to look and see what fields were blank if they need to.

    here's a line with missing info:

    100111N1056 VxxxxR MxxxxN DR                                                  WI549428749 54942321003                                   555-555-55550621

    I removed 'city' and name

    Does this help you?  If your interested I could show you the specs, didn't want to overwhelm you but now it seems I'm telling you every part of the project anyway.. maybe it would help?

    So.. as far as my 'vision' goes, I was thinking that it would be best to load the DGV, display label showing number of 'critical' errors found (again, a blank field is not considered critical (but should be noted in log file), unless that field is cati_id or market).  There would be 3 buttons on the form - 1 to open log of critical errors, 1 to open log of missing data (not so critical errors), and the other to perform corrections of critical errors (which will most likely just be a misalignment of data).  Do you think that would work?


    -Joni :)


  • 13. srpna 2012 19:52
     
     

    Joni,

    When you said there was missing information I assumed you meant that the line length wouldn't be correct (152), but I see you meant there's just nothing in it.

    So long as it's not a digit (as defined by what you told me other night), then it'll pass validation as shown above. I should explain that I've modified my function now to accept both digits and other characters (like a blank space, a dash, etc.) if it's a string, but if it's supposed to be honest-to-goodness digits only, then math is performed on it to do the testing.

    That said, it sounds like we need to consider ALL of it as being a string, but I may be wrong because I can say with all honesty that I have NO IDEA what you just wrote above! I'm so confused I don't know whether to scratch my watch or wind my ass.

    I don't mind helping, you've seen that - but I'm lost!

    Tell me what I need to do to help or ...?


    Please call me Frank :)

  • 13. srpna 2012 20:07
     
     

    First.. LMAO!  Too funny :)

    Secondly, I didn't realize you wanted an example of a line that was shorter than 152.. this is something that could absolutely happen (and has).

    Here's an example:

    104041                                               CO80921321005FEMALE 42                           555-444-53950422

    Address1, Address2 and city are missing so it caused everything to shift left.

    I'll leave you with that for now while i got back and try to give you a better explanation :)


    -Joni :)

  • 13. srpna 2012 20:41
     
     

    First.. LMAO!  Too funny :)

    Secondly, I didn't realize you wanted an example of a line that was shorter than 152.. this is something that could absolutely happen (and has).

    Here's an example:

    104041                                               CO80921321005FEMALE 42                           555-444-53950422

    Address1, Address2 and city are missing so it caused everything to shift left.

    I'll leave you with that for now while i got back and try to give you a better explanation :)


    -Joni :)

    Well, this is one that I can't figure out how to fix with my new "tool":

    I kept thinking we were closer - looks like I'm further and further away...

    Please call me Frank :)

  • 13. srpna 2012 20:54
     
      Obsahuje kód

    "How about tell me how to "read" the file name so I can do that in the program. It needs to be added in per line so it needs to be known when the file is loaded and used for all lines from that point forward. Also, what if what it's looking for (a "1" or a "2") isn't there? I need to give it a fallback, lest something come along that causes an exception. I could, if you want, make it stop the program, issue a warning, and close if it's not able to figure out the version. Would there be a chance that in the future it might be a "3" or somehting else?"

    When file is selected I would use substring to get the release:

    dim filename as string = "R112BLUE_AD.DAT"
    
    r_ind = filename.substring(4,1)
    If you want, set up the filename as a string for now.  I could just change it later when I'm trying to piece all the parts of the puzzle together.  I'm going to set the string up when the user selects the file to process from an openfilediaglog box.  It has to be a '1' or '2', if it's not then display message (something like "Release not valid, please select another file") and show the openfiledialog box again.  I seriously doubt that could ever happen, only because the files they are choosing from are in a specific format, otherwise they would not be able to select it.  The openfiledialog only displays files that begin "R112" (or whatever the current release is, could  be R212 for next relelase) and end with '.DAT'.  
    Dim Rel As String = "112"
    
            Dim FilterString As String = ("Address Files(R" & Rel & "*.dat)|R" & rel & "112*.dat")
    
            OpenFD.InitialDirectory = "C:\dev\vendorbuilderpro\vendorbuilderpro\input_files"
            OpenFD.Title = "Select file to check in"
            OpenFD.Filter = FilterString
            OpenFD.ShowDialog()
            AddressFile = OpenFD.FileName

    I have it set up like this for now for testing until I get the other parts working and I can put them all together.

    Just seen your last post.  In the event the record is not 152 in length coming in, that would be considered a critical error (resp gender will always be there in 152, never  blank, sorry I didn't say that before, I just realized).  So, if rec length < 152 (r_ind not yet added, which would make it 153), couldn't it be manually fixed with your new process?  There's so much I don't understand (but I'm learning!) so I apologize if I sound like a complete dope! :)



    -Joni :)


  • 13. srpna 2012 21:06
     
     
    I read your last reply through email so I didn't see the graphic.  But looking at it now I think that's fine (DAMN FINE lol)!  The user could most definately edit that.. they know what the data is supposed to look like so it wouldn't be a problem figuring out what goes where... or maybe there's something more I'm unaware of?

    -Joni :)

  • 13. srpna 2012 21:19
     
     

    Not a complete dope - but I see several issues in what you just said.

    Before I get started, let me say this: YOU understand what you want, but obviously I don't (not fully). I have a reasonable knowledge of how to do it in VB. Not like some of the pro's here, but I can usually wrangle it some way or another. If we can manage to get each other to figure out a common interpretation, then I think this whole program can be done in way that'll work for everyone you're involved in.

    Last point first: If I understand correctly, the line will ALWAYS be 152 or it's simply a malformed line (more about that later). I said earlier "we'll add to the line" but when you said the version will be known in advance, there's no point in doing that; we don't need to add to it just to then turn around and extract it back out - we already know it so the line need not be modified.

    Question 1: Please tell me if I'm wrong on that point.

    Secondly, when you showed ".SubString(4,1)" looking at the text "R112BLUE_AD.DAT", that would yield this:

    "B"

    Remember that almost everything in dotNET is zero-based so the first character ("R") has the index of 0, not 1.

    Question 2: I'll presume that you meant ".SubString(3,1)", correct?

    You said "...could  be R212 for next relelase" which would yield a version number of "2", the same as "R112", so I don't see where the version number is being changed.

    Question 3: Splain it to me Lucy.

    The other comment that I'll make - because you need to know - is that it would appear that you're using an OpenFileDialog from the toolbox, whereas if you look at my code, it's being created purely in code inside a Using Block. It's not *wrong* doing it your way, but be aware that your OpenFileDialog will never be be disposed until the program is closed. The Using block is able to do that for you: It will both close AND dispose it once it's outside of the Using Block. Technically it's just "marked as can be disposed and GC attends to the 'when', but you get the idea.


    As for the last comment about what you read in e-mail, if the line length isn't 152 then I don't understand what you mean about someone fixing it; I sure couldn't. What did I miss? Please do understand that the 20 TextBoxes beneath the main one at the top are NOT editable; that's for "reading the data only". Should they be? That would totally flub up the automatic parsing but ...


    Please call me Frank :)

  • 13. srpna 2012 21:41
     
     

    That's correct... no need to add to the line, no need to modify :)

    Question 1:  Once again, you are correct sir!  That's my mistake, I forgot it was zero-based (i'm used to Mid, I'll get used to substring :) )

    Question 2:  You got it!

    Question 3:  I'll accept any suggestions you have, you know way more than I do at that point (that may change someday! lol... maybe).  That's just the only way I could figure out how to do it.  If there's a better way then PLEASE show me.  My only request is that they are able to select the file from a list so we know we're getting the correct filename, that's in the correct format.  I just went back to see if I could find what you're talking about but I'm not sure where that part of the code is - you've sent me so much I think I'm losing it!  Not that that's a bad thing :)

    I understand you can't edit the line in the textboxes, from what I understand it would have to be done above that in the input box...correct?  If that is the case, I think it's fine.  AFter working with these files as much as I have, I would have no problem figuring out what should be moved and to where.  That being the case, I'm sure the user wouldn't have a problem either, they work with these files inside and out.  I actually realized that the filler is also missing between zip4 and name, does help you understand how it should be at all?


    -Joni :)

  • 13. srpna 2012 22:05
     
     

    Joni,

    I'm surprised you're not irritated and annoyed at all my questions and comments - I'm glad to know you're not.

    How about try this: Download the following project folder:

    http://www.fls-tech.com/VBNet_Forum/08-13-12/Forum_Query_5.zip

    Please do note that it's bloated with all sorts of things from various examples I've done for users here in the forum, so once done, just toss the whole folder away.

    Run that (keep in mind it was just for testing purposes) and see if you can fix the the line in the text at the top to make it all work out? If you can then it might be something worth using but if even you can't do it, then ... *shrug*.

    Let me know please. :)


    Please call me Frank :)

  • 13. srpna 2012 23:03
     
     

    Sorry it took me so long to reply.. I was having unzipping issues :)

    So... took me maybe 30 seconds (probably less) to fix that line... easy as pie!  I love your idea!!

    zip4 and Geo zip are missing... but that's okay :)

    Please ask anything and comment away! If anything I feel I'm frustrating you because of my lack of knowledge.  I'm so grateful you've stuck around this long!  I never wouldn't expected it :)  THANK YOU!!

    I have question.. what are the 'will not be used' fields?


    -Joni :)



  • 13. srpna 2012 23:17
     
     

    Sorry it took me so long to reply.. I was having unzipping issues :)

    So... took me maybe 30 seconds (probably less) to fix that line... easy as pie!  I love your idea!!

    zip4 and Geo zip are missing... but that's okay :)

    ....

    Please ask anything and comment away! If anything I feel I'm frustrating you because of my lack of knowledge.  I'm so grateful you've stuck around this long!  I never wouldn't expected it :)  THANK YOU!!

    I have question.. what are the 'will not be used' fields?


    -Joni :)



    SHOWOFF! :-)~~~

    Ok ok, so you know your data and I don't! That's a good sign.

    I'm not sure what I need to do really, but I'm not going to work on this tonight any longer. Will you be around tomorrow.

    As for the "Will Not Be Used", if you look at the rules you gave me last week, there's a gap in data between Address1 and Address2 (look at the starting point and lengths). I need every character to be committed to something. The last one is for a malformed line which might be longer than 152 - I'd like to show it rather than shave it off (truncate it) so that if need be, if the user deletes spaces to the left of it, that field will "pull back to the left" also. Make sense?

    If you look at that test deal I sent, there's nothing in it to prevent you from sending a text file of any length to it; it will only read 152 out, but anything beyond that goes into that last one (as with my initial example with two blank spaces in front).

    Give some thought to what you want me to do next and depending on how tomorrow goes for 'real work', we can pick up then.


    Please call me Frank :)

  • 14. srpna 2012 14:44
     
     

    Oh ok.. I understand, that makes sense :)

    Next?  I need to create a table that contains a count of cati_id's per market.  Later on (after validation) I have to compare that count against another report to see if it matches.  For example:

    If this is what's in the input file (I'm just showing the two fields that are needed for count):

    Then this is what the table should contain:

    Does that make sense?


    -Joni :)

  • 14. srpna 2012 15:08
     
     

    Oh ok.. I understand, that makes sense :)

    Next?  I need to create a table that contains a count of cati_id's per market.  Later on (after validation) I have to compare that count against another report to see if it matches.  For example:

    If this is what's in the input file (I'm just showing the two fields that are needed for count):

    Then this is what the table should contain:

    Does that make sense?


    -Joni :)


    Ok - do you want me to show you how to do that or do you want me to try to put the whole thing together? I got somewhat lost about that yesterday.

    Please call me Frank :)

  • 14. srpna 2012 15:23
     
     

    yea.. yesterday I just started posting everything because i thought if you knew the big picture it would be easier but I just confused you more! lol... sorry about that.

    Either is fine with me.. whatever is easier for you :)


    -Joni :)

  • 14. srpna 2012 15:26
     
     

    yea.. yesterday I just started posting everything because i thought if you knew the big picture it would be easier but I just confused you more! lol... sorry about that.

    Either is fine with me.. whatever is easier for you :)


    -Joni :)

    I don't mind trying at least, but my nemisis is time. I'd need four or five contiguous hours to get it done and right now, that would be difficult.

    If you don't have what you want by this week's end though, I'll plan on doing it this weekend.

    Are you willing to share either a whole list or a partial one? Don't post it here!!

    If you are, I'll give you the information where you can upload it to an FTP area, I'll then download it and delete it from the site.


    Please call me Frank :)

  • 14. srpna 2012 15:41
     
     

    Wow really??  I'll accept any help you're willing to give, so whatever you need just let me know and consider it done!

    The deeper I get into this and the more you show me how to do, makes me wonder how in the world they could expect me to do this without help from anyone.. there's NO WAY I could've figured this out.  Makes me wonder if they were purposely setting me up for failure.. hmmmm.  Thanks for saving me :)

    If anything, would you be able to add comments to what you already have and share it with me so I could start going over it and understanding what's going on?


    -Joni :)

  • 14. srpna 2012 15:48
     
     

    Wow really??  I'll accept any help you're willing to give, so whatever you need just let me know and consider it done!

    The deeper I get into this and the more you show me how to do, makes me wonder how in the world they could expect me to do this without help from anyone.. there's NO WAY I could've figured this out.  Makes me wonder if they were purposely setting me up for failure.. hmmmm.  Thanks for saving me :)

    If anything, would you be able to add comments to what you already have and share it with me so I could start going over it and understanding what's going on?


    -Joni :)

    Well, what I have is jumbled - I know which parts of each thing I've done to make it work as a whole but it's not straightforward.

    The thing that you unzipped yesterday - if you still have it (and if not it's still on the site so just download it again), look at the modified function for validation; that one works better than the original one.

    Tell me if you can share one of your lists though so I can get that done and I'll explain now that I'll be using LINQ to do it with. I'll also tell you that LINQ is a weird thing to work with and the syntax will make you cross your eyes, but once you get the hang of it (and I'm only a beginner with it), you'll quickly realize just how powerful it is.

    As for documentation ... what concepts are you fuzzy about? I'll focus on that rather than literally every single step of the way.


    Please call me Frank :)

  • 14. srpna 2012 18:03
     
     

    Sure.. I'll share my list.  Just tell me how to do it.

    I'm wondering though, if you're using LINQ does that mean that I'll have to as well?  I"m not sure if that would work, I don't think we have that at my office.  I'm not sure how that all works...

    I can't find the validation function.  I see something that looks like a form designer (I think it's automatically generated code, there'a s note that says to not edit).  What file in that zipped folder should I be trying to open to get to the validation portion?  Yesterday I opened the .exe and ran that to fix that line (couldn't find the code yesterday either, I don't know where to look). I've been trying for about an hour now to find it but no luck... ugh!  I'm sorry, I feel like such a pain in the butt!


    -Joni :)

  • 14. srpna 2012 18:09
     
     

    Sure.. I'll share my list.  Just tell me how to do it.

    I'm wondering though, if you're using LINQ does that mean that I'll have to as well?  I"m not sure if that would work, I don't think we have that at my office.  I'm not sure how that all works...

    I can't find the validation function.  I see something that looks like a form designer (I think it's automatically generated code, there'a s note that says to not edit).  What file in that zipped folder should I be trying to open to get to the validation portion?  Yesterday I opened the .exe and ran that to fix that line (couldn't find the code yesterday either, I don't know where to look). I've been trying for about an hour now to find it but no luck... ugh!  I'm sorry, I feel like such a pain in the butt!


    -Joni :)

    Here's the FTP login information:

    ftp.fls-tech.com
    login: vbforum
    password: L5Mgq9S35$;f

    Yes, you have LINQ - it's part of dotNET (starting at 3.5 I think, I might be wrong about the version that it started in). There are very long-winded other ways to do it but let me at least show you in LINQ then if need be, we'll revert to the other way.

    In what you unzipped yesterday, there should be a Form1.vb file that you can open in Visual Studio - is there not? Most likely it will ask you to convert because I use Visual Studio 2008.


    Please call me Frank :)

  • 14. srpna 2012 18:10
     
     

    Please let me know when you've uploaded it - it doesn't notify me or anything.

    Thanks


    Please call me Frank :)

  • 14. srpna 2012 18:25
     
     

    I logged in to upload it but all I see is this:
    I'm not sure how to upload.. I don't see anywhere to type or click.. I've never done this before


    -Joni :)

  • 14. srpna 2012 18:28
     
     

    No doubt you're using your browser (I was hoping you had an FTP client).

    That's ok - it'll work. Use Windows Explorer, find your file, the right-click on it and choose "Copy" (or CTRL+C). Then in that area that you're looking at on the site, right-click and choose "Paste" (or CTRL+V).


    Please call me Frank :)

  • 14. srpna 2012 18:58
     
     

    Today is just not my day!  Even the simplest of things are becoming obstacles :(

    I cut and paste all the time.. I'm selecting the file to copy but then when I go into that window (the one I pasted the image of above) and right click to paste, there is no option there for pasting.. all I get is 'Back', 'Forward', 'Reload', 'Save As', 'Print', 'Translate to English'... no 'Paste'.

    How am I screwing up a simple copy and paste??  could I email it?  Is there anyway you could open a quick email account (in hotmail, or yahoo) and I could send it to you?


    -Joni :)

  • 14. srpna 2012 19:03
     
     

    Today is just not my day!  Even the simplest of things are becoming obstacles :(

    I cut and paste all the time.. I'm selecting the file to copy but then when I go into that window (the one I pasted the image of above) and right click to paste, there is no option there for pasting.. all I get is 'Back', 'Forward', 'Reload', 'Save As', 'Print', 'Translate to English'... no 'Paste'.

    How am I screwing up a simple copy and paste??  could I email it?  Is there anyway you could open a quick email account (in hotmail, or yahoo) and I could send it to you?


    -Joni :)

    Without an FTP client it's probably not obvious - I honestly don't remember how it looks and works in a browser.

    It's probably time to take this "off the air" anyway though ... how about do this:

    Post your e-mail address here, give it about three minutes, then delete your post. I'll still get it in an e-mail and I'll reply back to you.


    Please call me Frank :)

  • 14. srpna 2012 19:06
     
     

    Thanks :)


    -Joni :)


  • 14. srpna 2012 19:09
     
     

    sounds good... this is an email I have set up for junk mail (when I fill out forms online and stuff)

    I'll reply back from there with my real email :)

    Sent ... but please remove that e-mail address from here anyway. You'll thank me for that! ;-)

    Please call me Frank :)