Results 1 to 15 of 15

Thread: [RESOLVED] Not sure how to approach this

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    51

    Resolved [RESOLVED] Not sure how to approach this

    hi everyone...

    is there a way I can read in a CSV file setup like below (the real file is about 200+ lines long), and populate Combo Boxes with just 1 "Jeopardy" or "wheel of fortune" (etc), and then depending on the selection that the user makes then the data in the second column - "New York", "Boston", etc, can populate another box, and depending on what the user chooses with those two boxes, then variables named "SyndNetwork" and "SyndTime" (all variables are Strings) will automatically equal the values in the 3rd and fourth column?

    (forgive the formatting, this is a copy a paste of different area (same columns, just further down the rows)):

    Code:
    Jeopardy	New York	WABC	19:00:00
    Jeopardy	Boston	WBZ	19:30:00
    Jeopardy	Hartford	WTNH	19:00:00
    Jeopardy	Philadelphia	WPVI	19:00:00
    Jeopardy	Baltimore	WMAR	19:30:00
    Jeopardy	Washington, DC	WJLA	19:30:00
    Jeopardy	Raleigh-Durham	WTVD	19:00:00
    Jeopardy	Charlotte	WCNC	19:00:00
    Jeopardy	Atlanta	WATL	19:30:00
    Jeopardy	Orlando	WFTV	19:00:00
    Jeopardy	Tampa	WFTS	19:30:00
    Jeopardy	West Palm Beach	WPBF	19:00:00
    Jeopardy	Miami	WPLG	19:30:00
    Wheel of Fortune	New York	WABC	19:30:00
    Wheel of Fortune	Boston	WBZ	19:00:00
    Wheel of Fortune	Hartford	WTNH	19:30:00
    Wheel of Fortune	Philadelphia	WPVI	19:30:00
    Wheel of Fortune	Baltimore	WMAR	19:30:00
    Wheel of Fortune	Washington, DC	WJLA	19:00:00
    Wheel of Fortune	Raleigh-Durham	WTVD	19:30:00
    Wheel of Fortune	Charlotte	WCNC	19:30:00
    Wheel of Fortune	Atlanta	WATL	19:00:00
    Wheel of Fortune	Orlando	WFTV	19:30:00
    Wheel of Fortune	Tampa	WFTS	19:00:00
    Wheel of Fortune	West Palm Beach	WPBF	19:30:00
    Wheel of Fortune	Miami	WPLG	19:00:00
    Wheel of Fortune	Pittsburgh	WPXI	19:30:00
    The Insider	New York	WCBS	19:00:00
    The Insider	Boston	WSBK	19:00:00
    The Insider	Philadelphia	KYW	19:30:00
    The Insider	Atlanta	WGLC	19:00:00
    The Insider	Orlando	WRDQ	22:30:00
    The Insider	Tampa	WTVT	19:30:00
    The Insider	West Palm Beach	WPEC	16:00:00
    The Insider	Miami	WFOR	19:30:00
    The Insider	Pittsburgh	KDKA	19:30:00
    The Insider	Cleveland	WOIO	19:00:00
    The Insider	Detroit	WWJ	19:00:00
    The Insider	Indianapolis	WRTV	19:30:00
    The Insider	Chicago	WCIU	18:00:00
    The Insider	Minniapolis	WUCW	22:00:00
    The Insider	St. Louis	WRBU	21:00:00
    The Insider	Kansas City	KCTV	23:30:00
    The Insider	Dallas	WFAA	23:05:00
    Entertainment Tonight	Atlanta	WGLC	19:00:00
    Entertainment Tonight	Orlando	WESH	19:00:00
    Entertainment Tonight	Tampa	WFLA	19:00:00
    Entertainment Tonight	West Palm Beach	WPTV	19:00:00
    Entertainment Tonight	Miami	WFOR	19:00:00
    Entertainment Tonight	Pittsburgh	WTAE	19:30:00
    Entertainment Tonight	Cleveland	WKYC	19:30:00
    Entertainment Tonight	Cincinnatti	WKRC	19:30:00
    Entertainment Tonight	Detroit	WXYZ	19:30:00
    Entertainment Tonight	Indianapolis	WISH	19:30:00
    Entertainment Tonight	Chicago	WBBM	18:30:00
    Entertainment Tonight	Minniapolis	KARE	18:30:00
    Entertainment Tonight	St. Louis	KMOV	18:30:00
    Entertainment Tonight	Kansas City	KMBC	18:30:00
    Entertainment Tonight	Tulsa	KOTV	18:30:00
    Entertainment Tonight	Dallas	WFAA	18:30:00
    Entertainment Tonight	Houston	KPRC	18:30:00
    Entertainment Tonight	Denver	KUSA	18:30:00
    Extra	New York	WNBC	19:00:00
    Extra	Boston	WHDH	19:30:00
    Extra	Hartford	WVIT	19:00:00
    Extra	Philadelphia	WCAU	19:00:00
    Extra	Baltimore	WUTB	18:30:00
    Extra	Raleigh-Durham	WNCN	19:30:00
    Extra	Atlanta	WXIA	19:30:00
    Extra	Orlando	WKMG	16:00:00
    Extra	Tampa	WFLA	19:30:00
    Extra	West Palm Beach	WPTV	19:30:00
    Extra	Miami	WTVJ	16:30:00
    I've included a pic of the windows form app that i'm working this all in so you have more of an idea what I'm talking about....

    I originally wanted to do this as a 4 dimensional array, but I can't find any guides or suggestions for how to read in a 4 dimensional array properly... I was contemplating just hardcoding all the text into combo boxes (to eliminate duplicates) using SELECT CASE, but holy crap would that be a lot of unneeded steps....

    HELP!! (please!)
    Attached Images Attached Images  
    Last edited by paradox34690; Apr 12th, 2012 at 10:01 PM. Reason: added "(all variables are Strings)"

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,196

    Re: Not sure how to approach this

    It can probably be done but need to know more about the text file. Is it a fixed width, csv, tab seperated... You need a way of knowing where one field ends and another begins. If you know the answer, tell us. If not, then you might need to post a copy of the text file.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    51

    Re: Not sure how to approach this

    Quote Originally Posted by wes4dbt View Post
    It can probably be done but need to know more about the text file. Is it a fixed width, csv, tab seperated... You need a way of knowing where one field ends and another begins. If you know the answer, tell us. If not, then you might need to post a copy of the text file.
    As stated in my original post, it's a CSV file. 4 columns consisting of a program name ("jeopardy", "wheel", etc), regional market (boston, NY, etc), affiliate station (WNBC, KNBC, etc), and a time.

    All values are strings.

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,196

    Re: Not sure how to approach this

    There are no comma's in the file shown, did you remove them?

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    51

    Re: Not sure how to approach this

    no, that's just a copy and paste from excel. I'd attach the actual .CSV file, but it's not one of the options available for file attaching here...

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    51

    Re: Not sure how to approach this

    Full CSV file, opened through Notepad, copy & pasted:

    Jeopardy,New York,WABC,19:00:00
    Jeopardy,Boston,WBZ,19:30:00
    Jeopardy,Hartford,WTNH,19:00:00
    Jeopardy,Philadelphia,WPVI,19:00:00
    Jeopardy,Baltimore,WMAR,19:30:00
    Jeopardy,"Washington, DC",WJLA,19:30:00
    Jeopardy,Raleigh-Durham,WTVD,19:00:00
    Jeopardy,Charlotte,WCNC,19:00:00
    Jeopardy,Atlanta,WATL,19:30:00
    Jeopardy,Orlando,WFTV,19:00:00
    Jeopardy,Tampa,WFTS,19:30:00
    Jeopardy,West Palm Beach,WPBF,19:00:00
    Jeopardy,Miami,WPLG,19:30:00
    Jeopardy,Pittsburgh,WPXI,19:00:00
    Jeopardy,Cleveland,WEWS,19:30:00
    Jeopardy,Cincinnatti,WCPO,19:30:00
    Jeopardy,Detroit,WDIV,19:30:00
    Jeopardy,Indianapolis,WTHR,19:30:00
    Jeopardy,Chicago,WLS,15:30:00
    Jeopardy,Minniapolis,KARE,16:30:00
    Jeopardy,St. Louis,KSDK,15:30:00
    Jeopardy,Kansas City,KSHB,16:30:00
    Jeopardy,Tulsa,KJRH,16:30:00
    Jeopardy,Dallas,KTVT,11:00:00
    Jeopardy,Houston,KHOU,11:30:00
    Jeopardy,Denver,KMGH,18:00:00
    Jeopardy,Phoenix,KNXV,16:30:00
    Jeopardy,San Diego,KNSD,19:30:00
    Jeopardy,Los Angeles,KABC,19:00:00
    Jeopardy,San Fancisco,KGO,19:00:00
    Jeopardy,Sacramento,KXTV,18:30:00
    Jeopardy,Portland,KATU,19:00:00
    Jeopardy,Seattle,KOMO,19:30:00
    Wheel of Fortune,New York,WABC,19:30:00
    Wheel of Fortune,Boston,WBZ,19:00:00
    Wheel of Fortune,Hartford,WTNH,19:30:00
    Wheel of Fortune,Philadelphia,WPVI,19:30:00
    Wheel of Fortune,Baltimore,WMAR,19:30:00
    Wheel of Fortune,"Washington, DC",WJLA,19:00:00
    Wheel of Fortune,Raleigh-Durham,WTVD,19:30:00
    Wheel of Fortune,Charlotte,WCNC,19:30:00
    Wheel of Fortune,Atlanta,WATL,19:00:00
    Wheel of Fortune,Orlando,WFTV,19:30:00
    Wheel of Fortune,Tampa,WFTS,19:00:00
    Wheel of Fortune,West Palm Beach,WPBF,19:30:00
    Wheel of Fortune,Miami,WPLG,19:00:00
    Wheel of Fortune,Pittsburgh,WPXI,19:30:00
    Wheel of Fortune,Cleveland,WEWS,19:00:00
    Wheel of Fortune,Cincinnatti,WCPO,19:00:00
    Wheel of Fortune,Detroit,WDIV,19:00:00
    Wheel of Fortune,Indianapolis,WTHR,19:00:00
    Wheel of Fortune,Chicago,WLS,18:30:00
    Wheel of Fortune,Minniapolis,WCCO,18:30:00
    Wheel of Fortune,St. Louis,KSDK,18:30:00
    Wheel of Fortune,Kansas City,KSHB,18:30:00
    Wheel of Fortune,Tulsa,KFSM,18:30:00
    Wheel of Fortune,Dallas,KTVT,18:30:00
    Wheel of Fortune,Houston,KHOU,18:30:00
    Wheel of Fortune,Denver,KMGH,18:30:00
    Wheel of Fortune,Phoenix,KNXV,18:30:00
    Wheel of Fortune,San Diego,KNSD,19:00:00
    Wheel of Fortune,Los Angeles,KABC,19:30:00
    Wheel of Fortune,San Fancisco,KGO,19:30:00
    Wheel of Fortune,Sacramento,KXTV,19:00:00
    Wheel of Fortune,Portland,KATU,19:30:00
    Wheel of Fortune,Seattle,KOMO,19:00:00
    The Insider,New York,WCBS,19:00:00
    The Insider,Boston,WSBK,19:00:00
    The Insider,Philadelphia,KYW,19:30:00
    The Insider,Atlanta,WGLC,19:00:00
    The Insider,Orlando,WRDQ,22:30:00
    The Insider,Tampa,WTVT,19:30:00
    The Insider,West Palm Beach,WPEC,16:00:00
    The Insider,Miami,WFOR,19:30:00
    The Insider,Pittsburgh,KDKA,19:30:00
    The Insider,Cleveland,WOIO,19:00:00
    The Insider,Detroit,WWJ,19:00:00
    The Insider,Indianapolis,WRTV,19:30:00
    The Insider,Chicago,WCIU,18:00:00
    The Insider,Minniapolis,WUCW,22:00:00
    The Insider,St. Louis,WRBU,21:00:00
    The Insider,Kansas City,KCTV,23:30:00
    The Insider,Dallas,WFAA,23:05:00
    The Insider,Phoenix,KTVK,23:00:00
    The Insider,San Diego,KUSI,20:30:00
    The Insider,Los Angeles,KCBS,19:00:00
    The Insider,San Fancisco,KRON,19:00:00
    The Insider,Sacramento,KMAX,22:30:00
    The Insider,Portland,KPTV,23:33:00
    The Insider,Seattle,KIRO,19:30:00
    Entertainment Tonight,New York,WCBS,19:30:00
    Entertainment Tonight,Boston,WSBK,19:30:00
    Entertainment Tonight,Philadelphia,KYW,19:30:00
    Entertainment Tonight,"Washington, DC",WUSA,19:30:00
    Entertainment Tonight,Raleigh-Durham,WRAL,19:30:00
    Entertainment Tonight,Charlotte,WSOC,19:30:00
    Entertainment Tonight,Atlanta,WGLC,19:00:00
    Entertainment Tonight,Orlando,WESH,19:00:00
    Entertainment Tonight,Tampa,WFLA,19:00:00
    Entertainment Tonight,West Palm Beach,WPTV,19:00:00
    Entertainment Tonight,Miami,WFOR,19:00:00
    Entertainment Tonight,Pittsburgh,WTAE,19:30:00
    Entertainment Tonight,Cleveland,WKYC,19:30:00
    Entertainment Tonight,Cincinnatti,WKRC,19:30:00
    Entertainment Tonight,Detroit,WXYZ,19:30:00
    Entertainment Tonight,Indianapolis,WISH,19:30:00
    Entertainment Tonight,Chicago,WBBM,18:30:00
    Entertainment Tonight,Minniapolis,KARE,18:30:00
    Entertainment Tonight,St. Louis,KMOV,18:30:00
    Entertainment Tonight,Kansas City,KMBC,18:30:00
    Entertainment Tonight,Tulsa,KOTV,18:30:00
    Entertainment Tonight,Dallas,WFAA,18:30:00
    Entertainment Tonight,Houston,KPRC,18:30:00
    Entertainment Tonight,Denver,KUSA,18:30:00
    Entertainment Tonight,Phoenix,KTVK,18:30:00
    Entertainment Tonight,San Diego,KFMB,19:00:00
    Entertainment Tonight,Los Angeles,KCBS,19:30:00
    Entertainment Tonight,San Fancisco,KRON,19:30:00
    Entertainment Tonight,Sacramento,KMAX,22:00:00
    Entertainment Tonight,Portland,KOIN,19:00:00
    Entertainment Tonight,Seattle,KIRO,19:00:00
    Extra,New York,WNBC,19:00:00
    Extra,Boston,WHDH,19:30:00
    Extra,Hartford,WVIT,19:00:00
    Extra,Philadelphia,WCAU,19:00:00
    Extra,Baltimore,WUTB,18:30:00
    Extra,Raleigh-Durham,WNCN,19:30:00
    Extra,Atlanta,WXIA,19:30:00
    Extra,Orlando,WKMG,16:00:00
    Extra,Tampa,WFLA,19:30:00
    Extra,West Palm Beach,WPTV,19:30:00
    Extra,Miami,WTVJ,16:30:00
    Extra,Cincinnatti,WLWT,19:30:00
    Extra,Indianapolis,WRTV,17:30:00
    Extra,Chicago,WMAQ,16:00:00
    Extra,Minniapolis,KMPS,13:00:00
    Extra,St. Louis,KDNL,23:30:00
    Extra,Kansas City,KCWE,23:30:00
    Extra,Dallas,KXAS,18:30:00
    Extra,Denver,KUSA,12:30:00
    Extra,Phoenix,KPNX,18:30:00
    Extra,San Diego,KUSI,20:00:00
    Extra,Los Angeles,KNBC,19:00:00
    Extra,San Fancisco,KNTV,19:00:00
    Extra,Sacramento,KCRA,19:30:00
    Extra,Portland,KOIN,19:30:00
    Extra,Seattle,KONG,19:00:00
    Access Hollywood,New York,WNBC,19:30:00
    Access Hollywood,Boston,WHDH,19:00:00
    Access Hollywood,Hartford,WVIT,19:30:00
    Access Hollywood,Philadelphia,WCAU,19:30:00
    Access Hollywood,Baltimore,WBAL,19:30:00
    Access Hollywood,"Washington, DC",WRC,19:30:00
    Access Hollywood,Raleigh-Durham,WNCN,17:30:00
    Access Hollywood,Atlanta,WAGA,19:00:00
    Access Hollywood,Orlando,WESH,19:30:00
    Access Hollywood,Miami,WTVJ,19:30:00
    Access Hollywood,Pittsburgh,WTAE,12:30:00
    Access Hollywood,Cincinnatti,WLWT,19:00:00
    Access Hollywood,Detroit,WJBK,18:30:00
    Access Hollywood,Indianapolis,WNDY,18:30:00
    Access Hollywood,Chicago,WMAQ,18:30:00
    Access Hollywood,Minniapolis,WUCW,21:00:00
    Access Hollywood,St. Louis,KTVI,12:30:00
    Access Hollywood,Tulsa,KFTA,23:30:00
    Access Hollywood,Dallas,KDFW,18:30:00
    Access Hollywood,Denver,KWGN,22:30:00
    Access Hollywood,Phoenix,KNXV,15:00:00
    Access Hollywood,San Diego,KNSD,18:30:00
    Access Hollywood,Los Angeles,KNBC,19:30:00
    Access Hollywood,San Fancisco,KNTV,19:30:00
    Access Hollywood,Sacramento,KCRA,19:00:00
    Access Hollywood,Portland,KPTV,19:30:00
    Access Hollywood,Seattle,KONG,19:00:00
    Last edited by paradox34690; Apr 12th, 2012 at 10:13 PM. Reason: Recreated CSV file without extra commas at end of each line...

  7. #7
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: Not sure how to approach this

    vb Code:
    1. Private WithEvents myComboBox As New ComboBox

    vb Code:
    1. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Dim aShow, aCity, aStation, aTime As String
    4.         Dim aLine As String()
    5.         Dim sr As New StreamReader(My.Application.Info.DirectoryPath & "\file.txt")
    6.  
    7.  
    8.         While (sr.Peek() > -1)
    9.             aLine = sr.ReadLine.Split(CChar(","))
    10.             aShow = aLine(0)
    11.             aCity = aLine(1)
    12.             aStation = aLine(2)
    13.             aTime = aLine(3)
    14.             'TextBox1.Text &= "Show: " & aShow & " City: " & aCity & " Station: " & aStation & " Time: " & aTime & vbNewLine
    15.             myComboBox.Items.Add(aLine)
    16.             ComboBox1.Items.Add(aShow)
    17.             ComboBox2.Items.Add(aCity)
    18.             ComboBox3.Items.Add(aStation)
    19.             ComboBox4.Items.Add(aTime)
    20.  
    21.         End While
    22.  
    23.         sr.Close()
    24.      
    25.         myComboBox.SelectedIndex = 0
    26.  
    27.  
    28.     End Sub
    29.     Private Sub myComboBox_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles myComboBox.SelectedIndexChanged, ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged, ComboBox3.SelectedIndexChanged, ComboBox4.SelectedIndexChanged
    30.         Dim x As Object = sender.SelectedIndex
    31.  
    32.         Me.ComboBox1.SelectedIndex = CInt(x)
    33.         Me.ComboBox2.SelectedIndex = CInt(x)
    34.         Me.ComboBox3.SelectedIndex = CInt(x)
    35.         Me.ComboBox4.SelectedIndex = CInt(x)
    36.  
    37.     End Sub

    Option Strict = Off, so please just change a few things, make it your own, turn Option Strict back on!
    Last edited by proneal; Apr 12th, 2012 at 11:32 PM.

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    51

    Re: Not sure how to approach this

    I'd LOVE to try this, but I just opened up a new project and pasted it all in, the

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    throws the following error: "Handles clause requires a WithEvents variable defined in the containing type or one of its base types."

    I'm going to play around with some of that and see if that helps me with what I'm specifically doing...

    From looking at the code (and not being able to fix it to see it... sorry, i'm still new to VB and teaching myself as I go), isn't the code:

    Code:
     myComboBox.Items.Add(aLine)
                ComboBox1.Items.Add(aShow)
                ComboBox2.Items.Add(aCity)
                ComboBox3.Items.Add(aStation)
                ComboBox4.Items.Add(aTime)
    going to wind up adding ALL of the entries to the combo boxes, or is that a way to "load" all the values for the combo boxes, but not display them until the myComboBox_SelectedIndexChanged bit?

  9. #9
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: Not sure how to approach this

    vb Code:
    1. Private WithEvents myComboBox As New ComboBox
    That belongs in Local declarations area of Form.

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    You have to have a Button1 on your form before pasting that. You pasted before actually having a Button1 on your form, right?

    You have to also have the file.txt that contains all that data you posted -exactly.
    It fills the comboboxes, and you must have them on the Form too, with all the data, each in their own combo, and then on Indexchanged -each one goes to same index selected on any of them.
    Option Strict must be off for this late binding to work. It is just a quick example I whipped up late last night.

    On second thought, try a different way with Option Strict On!.

    good Luck

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Not sure how to approach this

    You might also look into querying the file using ADO.NET. It seems to me that this is not the best solution for this case, though, because it sounds like you really just want ALL of the data, in one form or another.
    My usual boring signature: Nothing

  11. #11
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: Not sure how to approach this

    The combos are Drop Down Lists type too, btw

  12. #12
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: Not sure how to approach this

    I agree with SH, btw -as you pull this from the NET right?
    What I presented just loads combos and has no real world application as is..Just some poorly written code

  13. #13

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    51

    Re: Not sure how to approach this

    Sorry for the delay... Um... actually, i don't pull this from the net.

    I work for a multibillion dollar company. We have live tv feeds all over the globe... this is a UI for part of one of our feed streams.

    To be honest with you, I got so frustrated over this past weekend, I wrote the whole thing, hardcoded with a bunch of multi-level nested If..Then/Select Case functions. Works perfectly. I'm working on a "Pro" version of this now, but I have to optimize the code and I want to change it from using a WMP embedded COM to Quicktime as well as multiple data file sources for configuration, server management, etc... this is actually big...

    I will say this... I just beat the cable companies....
    Oh... free HBO too....

    No, unfortunately, I can't post the code.... sorry...

  14. #14
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Re: Not sure how to approach this

    The following example requires

    lstShowNames: ListBox
    cboCity: ComboBox
    cboChannel: ComboBox
    cboTimes: ComboBox

    In Form Load the following file is loaded which I populated from the text you posted.

    Code:
    IO.Path.Combine(Application.StartupPath, "Document.txt")
    The data within the file is loaded using TextFieldParser into a class, one item per line which gets placed into a List.

    The ListBox displays a distinct and sorted list of shows. When selecting a show the cboCity ComboBox is loaded with cities for that show. When the City item changes the cboChannel ComboBox is loaded with channels for the city followed by cboTimes shows times for that channel selected.

    Form code
    Code:
    Public Class Form5
        Private FileName As String = IO.Path.Combine(Application.StartupPath, "Document.txt")
        Private MyShowList As New List(Of MyShow)
        Private Sub Form5_Load(
            ByVal sender As System.Object,
            ByVal e As System.EventArgs) _
        Handles MyBase.Load
    
            If IO.File.Exists(FileName) Then
    
                Dim ErrorLines As Integer = 0
    
                Using Reader As New Microsoft.VisualBasic.FileIO.TextFieldParser(FileName)
    
                    Reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
                    Reader.Delimiters = New String() {","}
    
                    Dim currentRow As String()
    
                    While Not Reader.EndOfData
                        Try
                            currentRow = Reader.ReadFields()
    
                            MyShowList.Add(
                                New MyShow With
                                {
                                    .ShowName = currentRow(0),
                                    .City = currentRow(1),
                                    .Channel = currentRow(2),
                                    .ShowTime = currentRow(3)
                                }
                            )
    
                        Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                            ErrorLines += 1
                        End Try
                    End While
                End Using
    
                Dim Shows =
                    (
                        From T In MyShowList
                        Select ShowName = T.ShowName, City = T.City, ShowTime = T.ShowTime, Channel = T.Channel
                        Order By ShowName).Distinct(Function(x, y) x.ShowName = y.ShowName
                    )
    
    
                lstShowNames.DisplayMember = "ShowName"
                lstShowNames.DataSource = Shows.ToList
    
                If ErrorLines > 0 Then
                    MessageBox.Show(ErrorLines.ToString & " were not processed.")
                End If
            End If
    
    
        End Sub
    
        Private Sub ListBox1_SelectedIndexChanged(
            ByVal sender As System.Object,
            ByVal e As System.EventArgs) _
        Handles lstShowNames.SelectedIndexChanged
    
            Dim ShowsCities =
                (
                    From T In MyShowList
                    Where T.ShowName = lstShowNames.Text
                    Select City = T.City, Channel = T.Channel, ShowTime = T.ShowTime
                    Order By City).Distinct(Function(x, y) x.City = y.City)
    
    
            cboCity.DataSource = Nothing
            cboCity.DisplayMember = "City"
            cboCity.DataSource = ShowsCities.ToList
    
        End Sub
    
        Private Sub cboCity_SelectedIndexChanged(
            ByVal sender As System.Object,
            ByVal e As System.EventArgs) _
        Handles cboCity.SelectedIndexChanged
    
            Dim ShowsChannels =
                (
                    From T In MyShowList
                    Where T.ShowName = lstShowNames.Text AndAlso T.City = cboCity.Text
                    Select Channel = T.Channel, ShowTime = T.ShowTime
                    Order By Channel).Distinct(Function(x, y) x.Channel = y.Channel)
    
    
            cboChannel.DataSource = Nothing
            cboChannel.DisplayMember = "Channel"
            cboChannel.DataSource = ShowsChannels.ToList
    
        End Sub
        Private Sub cboChannel_SelectedIndexChanged(
            ByVal sender As System.Object,
            ByVal e As System.EventArgs) _
        Handles cboChannel.SelectedIndexChanged
    
            Dim ShowsTimes =
                (
                    From T In MyShowList
                    Where T.ShowName = lstShowNames.Text AndAlso T.City = cboCity.Text AndAlso T.Channel = cboChannel.Text
                    Select ShowTime = T.ShowTime
                    Order By ShowTime).ToList
    
    
            cboTimes.DataSource = Nothing
            cboTimes.DataSource = ShowsTimes
    
        End Sub
    End Class
    Public Class MyShow
        Public Property ShowName As String
        Public Property City As String
        Public Property Channel As String
        Public Property ShowTime As String
        Public Sub New()
        End Sub
    End Class
    Code module i.e. Module1.vb
    Converted from C Sharp from Code Project
    Code:
    Module Module1
        Public Class PredicateEqualityComparer(Of T)
            Inherits EqualityComparer(Of T)
            Private predicate As Func(Of T, T, Boolean)
    
            Public Sub New(ByVal predicate As Func(Of T, T, Boolean))
                MyBase.New()
                Me.predicate = predicate
            End Sub
            Public Overloads Overrides Function Equals(ByVal x As T, ByVal y As T) As Boolean
                If x IsNot Nothing Then
                    Return ((y IsNot Nothing) AndAlso Me.predicate(x, y))
                End If
    
                If y IsNot Nothing Then
                    Return False
                End If
    
                Return True
            End Function
            Public Overrides Function GetHashCode(ByVal obj As T) As Integer
                ' Always return the same value to force the call to IEqualityComparer<T>.Equals
                Return 0
            End Function
        End Class
        <System.Runtime.CompilerServices.Extension()> _
        Public Function Distinct(Of TSource)(ByVal source As IEnumerable(Of TSource), ByVal predicate As Func(Of TSource, TSource, Boolean)) As IEnumerable(Of TSource)
            Return source.Distinct(New PredicateEqualityComparer(Of TSource)(predicate))
        End Function
    End Module

  15. #15
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: Not sure how to approach this

    I meant OP- that is SHAGGY pulled (took this data from this webpage, FROM THE NET-in order to use in his resolutions for you!
    You are one of those high risk heart attack programmers aren't you.

    Shaggy's way is the better way, it does exactly what you wanted
    which means you will be pulling this part FROM THE NET too

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width