Results 1 to 14 of 14

Thread: Question About a Homework Assignment

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Location
    St. Louis, MO
    Posts
    8

    Question About a Homework Assignment

    Hello All,

    Edit: We are using Visual Basic Studio 2010 Express in Class.

    I have been out of school many years, recently re-enrolled, and am having a little bit of trouble with a homework assignment:

    Write a program to book an airline flight. If the same airport is selected from the two list boxes, the user should be informed immediately that the departure and arrival airports must be different. If no airport has been selected from one or both of the list boxes when the button is clicked, then the user should be told what information must be supplied. Use message boxes to inform the user of problems.

    Name:  Ch4Q18.jpg
Views: 577
Size:  26.2 KB

    The message at the bottom should output: "You are flying from ___ to ___" when the items are selected from the list box.

    For the life of me I can't figure out where to begin on this assignment.

    Any advise / help is greatly appreciated.
    Min
    Last edited by melinda2538; Mar 31st, 2013 at 01:53 PM. Reason: Forgot to add VB Version

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Question About a Homework Assignment

    You're instructed to use two ListBox controls so the obvious place to start would be to read documentation on ListBox properties and methods. If you want a hint, serach the page for terms including Selected.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Question About a Homework Assignment

    Try this
    Code:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If ListBox1.SelectedIndex = -1 OrElse ListBox2.SelectedIndex = -1 Then ' both or one of airport isn't selected.
                MessageBox.Show("You must select both 'From' and 'To' airport", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            ElseIf ListBox1.SelectedIndex = ListBox2.SelectedIndex Then ' both selected airport are the same.
                MessageBox.Show("You must select different airport", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else
                Dim strFrom As String = "'from value'" ' load from a defined list according to selected "From" airport.
                Dim strTo As String = "'to value'" ' load from a defined list according to selected "To" airport.
                MessageBox.Show("You are flying from " & strFrom & " to " & strTo, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
    
            End If
        End Sub



  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Question About a Homework Assignment

    Or you could just get someone to do it for you! Sigh!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Location
    St. Louis, MO
    Posts
    8

    Thumbs up Re: Question About a Homework Assignment

    dunfiddlin - Thank you for the info, I wasn't quite sure of what I was looking for. We didn't have time to go over listboxes in class, and there isn't a whole lot of understandable information in my text. My goal was not to have someone do the project for me - it doesn't benefit me much if I don't learn anything! I will utilize that search method and the references you pointed me to.

    Thank you 4x2y - I will keep your info as notes

    Much appreciation to both - the last coding I did was 7 years ago as a web design major (and Dreamweaver wrote all the code for me!)

  6. #6
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: Question About a Homework Assignment

    Melinda, not all of us will reply as harshly as dunfiddlin. If you have trouble locating something in a search or can't seem to make your existing code work, don't hesitate to post again. There are others on this forum who create productive responses.

  7. #7
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Question About a Homework Assignment

    Actually, my reply was not to solve his/her homework but to save his/her time, because pointing a beginner to read the documentation is useless in most cases, but giving a working code with some comments is much worth, specially when the question is simple as that one.



  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Location
    St. Louis, MO
    Posts
    8

    Re: Question About a Homework Assignment

    I am a visual learner - sometimes reading the textbook is like reading Chinese to me. Code samples are great references because I can usually puzzle it together for what I need for my assignment - I'll see what I'm missing that makes the light-bulb go off and have the "a-ha!" moment. My professor says there's a file full of different examples in VB - I really need to find it so I can look through it all.

    Thank you again everyone for the info!

  9. #9
    New Member
    Join Date
    May 2013
    Posts
    3

    Re: Question About a Homework Assignment

    I also have a couple questions on this topic, when doing this program and using the above code im getting erros saying too many arguments to 'public sub show()

  10. #10
    New Member
    Join Date
    May 2013
    Posts
    3

    Re: Question About a Homework Assignment

    Private Sub btnexec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexec.Click
    If lstfrom.SelectedIndex = -1 OrElse lstto.SelectedIndex = -1 Then ' both or one of airport isn't selected.
    txtdecide.Show("You must select both 'From' and 'To' airport")
    ElseIf lstfrom.SelectedIndex = lstto.SelectedIndex Then ' both selected airport are the same.
    txtdecide.Show("You must select different airport")
    Else
    Dim lstfrom As String = "'from value'" ' load from a defined list according to selected "From" airport.
    Dim lstto As String = "'to value'" ' load from a defined list according to selected "To" airport.
    txtdecide.Show("You are flying from " & lstfrom & " to " & lstto, )

  11. #11
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: Question About a Homework Assignment

    You should create your own thread instead of hijacking someone else's.

    That said, what kind of control is txtdecide? If it is a textbox or label then you should be using txtdecide.text = "You must select a different airport". The .Show() method does not take any arguments, which is why you are getting the error.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

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

    Re: Question About a Homework Assignment

    Actually, txtDecide wasn't a control at all in the code posted by 4x2y, but was the MessageBox component. For some reason, cploof1 changed the name to something else, which isn't going to work. Perhaps they weren't aware of MessageBox because they are used to using the old MsgBox, but whatever the reason was, it's a change that can't be made.
    My usual boring signature: Nothing

  13. #13
    New Member
    Join Date
    May 2013
    Posts
    3

    Re: Question About a Homework Assignment

    Sorry i didn't mean to hijack anything but its the exact same question so i thought it would be easier and everyone would have more information because i started using part of the code provided above. I changed back the message box but now im getting it to run but wont pull the information.
    If lstfrom.SelectedIndex = -1 OrElse lstto.SelectedIndex = -1 Then ' both or one of airport isn't selected.
    MessageBox.Show("You must select both 'From' and 'To' airport", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
    ElseIf lstfrom.SelectedIndex = lstto.SelectedIndex Then ' both selected airport are the same.
    MessageBox.Show("You must select different airport", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
    Else
    Dim lstfrom As String = "'from value'" ' load from a defined list according to selected "From" airport.
    Dim lstto As String = "'to value'" ' load from a defined list according to selected "To" airport.
    MessageBox.Show("You are flying from " & lstfrom & " to " & lstto, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)

    I added the cities in the properties from items, do i need to do something else with those to get the code to actually see it? Im pretty new to using visual basics so hopefully im making sense.

  14. #14
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Question About a Homework Assignment

    Try this
    Code:
            If lstfrom.SelectedIndex = -1 OrElse lstto.SelectedIndex = -1 Then ' both or one of airport isn't selected.
                MessageBox.Show("You must select both 'From' and 'To' airport", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            ElseIf lstfrom.SelectedIndex = lstto.SelectedIndex Then ' both selected airport are the same.
                MessageBox.Show("You must select different airport", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else
                Dim strFrom As String = lstfrom.SelectedItem.ToString
                Dim strTo As String = lstto.SelectedItem.ToString
                MessageBox.Show("You are flying from " & strFrom & " to " & strTo, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End If
    To make your code readable, begin each separate word in a name with a capital letter, as in SelectedIndex and MessageBox. so use lstFrom, lstTo instead of lstfrom, lstto



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