-
Mar 31st, 2013, 12:39 PM
#1
Thread Starter
New Member
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.
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
-
Mar 31st, 2013, 06:34 PM
#2
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!
-
Mar 31st, 2013, 06:43 PM
#3
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
-
Mar 31st, 2013, 07:11 PM
#4
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!
-
Mar 31st, 2013, 08:17 PM
#5
Thread Starter
New Member
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!)
-
Mar 31st, 2013, 08:20 PM
#6
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.
-
Mar 31st, 2013, 08:39 PM
#7
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.
-
Mar 31st, 2013, 08:50 PM
#8
Thread Starter
New Member
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!
-
May 8th, 2013, 04:03 PM
#9
New Member
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()
-
May 8th, 2013, 04:04 PM
#10
New Member
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, )
-
May 8th, 2013, 04:23 PM
#11
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.
-
May 8th, 2013, 05:02 PM
#12
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
-
May 8th, 2013, 05:51 PM
#13
New Member
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.
-
May 8th, 2013, 06:12 PM
#14
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|