VB Assistance

M

mommakind

I'm having some trouble figuring out the logic to a homework problem,
and since my teacher is out of town for a few days I thought I would
check in here and see if someone can help me.

I have lstClasses, which has a list of 5 classes. I have lstCities,
which has a list of 5 cities. Now each class has registration fee
and a different number of days (, registration fee is $500 for Class
1 and goes for 3 days) and each city has a lodging rate per night.
So, the user should select the class in the first box, then the city
in the second box and the charges should appear in the third box, and
when a button is pressed a grand total appears elsewhere on the form.

I would really appreciate it if you guys could help me think through
the logic I need to attach the values, or calculate the values. I
really think there is an easier way than If then Else for every
combination.

Thanks in advance.

M
 
S

Scott M.

Since we're not real big around here on solving homework assignments, I'll
simply say that you should try to break the overall problem down to its
constituent parts and then build from there. It sounds like you've
determined that you do need decision making logic. Now, ask yourself what
you need to figure out and what syntax VB.NET offers for decision making
code.
 
T

Tom Leylan

In addition to the other reply I'll offer, write it any way you can. One
way people learn to see optimal (aka "better") solutions is to write some
code. As you look at that code you may discover a duplication or a
shortcut. You might think of an alternative but importantly regardless of
what happens you have a solution and that is something you can turn in if no
brainstorms occur or if every attempt to refine it fails.

"Make it work, then make it fast."

Oh and don't throw away the earlier attempts you might change your mind and
want it back.
 
R

RobinS

Tom Leylan said:
"Make it work, then make it fast."

Oh and don't throw away the earlier attempts you might change your mind
and want it back.

LOL.

So true, so true.

Robin S.
 
P

PFC Sadr

keep your shit in a database

using classes is unnecessary overhead
it's well established that OOP makes your code MORE VERBOSE and RUN
SLOWER
 
B

Branco Medeiros

mommak wrote:
I have lstClasses, which has a list of 5 classes. I have lstCities,
which has a list of 5 cities. Now each class has registration fee
and a different number of days (, registration fee is $500 for Class
1 and goes for 3 days) and each city has a lodging rate per night.
So, the user should select the class in the first box, then the city
in the second box and the charges should appear in the third box, and
when a button is pressed a grand total appears elsewhere on the form.
<snip>

I'll use the term "Category" instead of Class, here, to mean the items
in lstClass, so we don't mixup OOP terms with the ones used by your
assignment.

One possible way of thinking this through would be to see both
Categories and Cities as representations of a given type -- a Class in
OOP terms.

So, each Category is a difference instance of the same kind -- of the
same Class. What all different Categories have in common is the fact
that there's both a RegistrationFee and a ValidDays property attached
to each of them. Therefore you could consider defining this type of
object (this Class) under the terms of these two properties. Not that
you can't add other properties as well, such as ID, or whatever you
think would be usefull (don't go overboard here).

Clue: you may have a Sub in your application that performs the app
initialization, where each Category gets created. Can you spot in the
pseudocode below the initialization of each category? Considering what
I suggested earlier, can you guess what the initialization parameters
are?

mCategories = New List(Of Category)
mCategories.Add(New Category("Standard", 500.00, 3))
mCategories.Add(New Category("Premium", 1000.00, 7))
'... and the thing goes on

Likewise, think of each city as instances of a City class. Therefore
each City will have a NightlyLodgingRate property (or whatever you
call it..), as well as a Name property. Now, one thing a City must
know how to do is, given a Category, return the corresponding charge.
This sounds more like an action than a property. Therefore you might
consider defining a CalcRate(Cat As Category) function in the City
class that would simply get the niglty rate of the class and use the
appropriate properties of the given Category to calculate the
resulting value -- which is up to you to come up with an apropriate
formula.

Just as I suggested with the categories, you may create all the cities
in your initialization section:

'Continued from the previous code:
mCities = New List(Of City)
mCities.Add(New City("Samara", 3.00))
mCities.Add(New City("Oz", 45.00))
mCities.Add(New City("Gothan City", 1999.00))
'... etc, etc, etc.

When you have everything in place, then you must consider how to bind
these lists (mCategories and mCities) to your list boxes, and how (and
when) to perform the actual calculations.

Good luck.

HTH.

Regards,

Branco.
 
M

mommakind

I'm having some trouble figuring out the logic to a homework problem,
and since my teacher is out of town for a few days I thought I would
check in here and see if someone can help me.

I have lstClasses, which has a list of 5 classes. I have lstCities,
which has a list of 5 cities. Now each class has registration fee
and a different number of days (, registration fee is $500 for Class
1 and goes for 3 days) and each city has a lodging rate per night.
So, the user should select the class in the first box, then the city
in the second box and the charges should appear in the third box, and
when a button is pressed a grand total appears elsewhere on the form.

I would really appreciate it if you guys could help me think through
the logic I need to attach the values, or calculate the values. I
really think there is an easier way than If then Else for every
combination.

Thanks in advance.

M

Wow, I really didn't expect this. I believe I said "I would really
appreciate it if you guys could help me think through the logic".
Not, "Please do my homework for me".

And for the record, I did try to "write the code". I spent several
hours trying to "write the code". After about the fourth piece of
paper and fourth attempt in VB I assumed there was something I was
missing, Some way of looking at the problem that I was missing.

Clearly I am not well versed in how VB geeks should ask a question, I
suppose I could have simply said "This project I am working on", or
maybe "I'm trying to build a super cool database for my supercool
comic book collection". Then would you have helped me think it
through rather than sit there with your smug expressions?

Nice.
 
S

Scott M.

I'm afraid you've misread us and our intentions.

I don't think anyone's reply here was smug, rude or anything other than
truly trying to help. You should understand that these groups are mostly
frequented by professional developers and most of us got to where we are by
following certain proven learning techniques. The general mantra of not
supplying answers to homework is not so that we can be smug, it is so you
can learn not only how to solve your particular problem at hand, but also
how you can help yourself in the future (teach a man to fish...).

I believe that the suggestions you have gotten to your question have been
very helpful in breaking down your problem into manageable parts. And,
honestly, if you are still stuck after these comments, it may be because you
either haven't learned what you should have at this point in your studies
(not a dig on you, but certainly a possibility) or your teacher hasn't
provided you with adequate instruction. Either way, if we just give a
student, such as yourself the answer, you may not actually learn "why" it is
correct, and, after all, isn't that what you are taking a class for in the
first place?

-Scott
 
J

jeff

Momma,

The advice given is more than enough to solve the problem...what
specifically are you having problems with? From your explanation of the
problem, you should be able to build a solution (becuase your explanation of
the problem is the solution) ... the first part is understanding the
question ... which you do ... now break it down into parts... you smallest
elements ... and build up to a solution ... Is a house a bunch of walls with
a roof ... or is it a bunch of lumber held together by nails? Looking at
the walls does not solve your problem ... you have a list ... a list of what
.... courses ... each course has what ... has a bunch of properties ... (Reg
Few, Training Days) ... now, when you have a list (hint ... COLLECTION) of
courses, you want to be able to find a specific courses Training Days ... so
you need a method that will easily return this information when you know the
course ID ... and so on....

1. The Class List (lets call these courses)
Properties of the Course are
- Registration Few
- Number of Days.

2. The City List.
Properties of a the City are
- Lodging Rate

......................................................

Create a Class
clsCourse
Properties ... Course ID , Course Descriptio, RegFew and TeachingDays

Create an Collection of Courses with the following Methods
GetTeachingDays(byVal CourseID)
GetRegFew(byVal CourseID)

Create a Class
clsCities
Properties ... City ID , City Name, and LodgingRate

Create a collection of Cities with the following method
GetLodgingRate(byVal CityID)

.......................................................

Form ...
- create a couple instance variables ... Courses Collection and Cities
Collection
- on load ...populate the two collections (courses and classes) with the
appropriate data. courses.Add(CourseID, CourseDesc,REfEw,TeachingDays)...
- on load ... populate two combo boxes ... one with a list of Courses (BOX1)
and one with a list of Cities (BOX2) ... display Description, store ID...
- Create a Function on the form ... fCalculateCost()
- On the update event either combobox call this function...

the function will look like...

....
box3 = Courses.GetRefFew(BOX1) + courses.GetTeachingDays(BOX1) *
cities.GetLodgingRate(BOX2)
....

no button necessary ...

make the proper error checking ... for null / blank values...

This should be enough for you to solve your problem... the detailed syntax I
leave to you. Why? Becuase you need to understand the fundamentals of
programming, so you can apply what you have learned here to your next
problem. You will need to look at building a Class, a Collection of
Classes, Populating User Controls (combo boxes) and capturing User events
(combobox updates) .... If you have specific questions regarding these
detailed subjects, ask away ... How do I create a class ... How do I create
a collection of classes ... How do I populate a combo box from a collection
of items ... and so on ... you will probably get better responses... Once
you have your solution, and you have hard coded adding 5 courses to your
courses collection, and adding 5 cities to your city collection ... have the
program get this information from a database or an XML file ... why ... so,
you will learn how to connect to a database or read from an XML file ...
simple techniques for data management. If you do not care about this
because it is not in scope of the problem ... you are taking this course for
the wrong reason ... unless you have a kegger to go to!

Again, your explanation of the problem is your SOLUTION, you just need to be
able to break it down in to managable units of work!

And no, we are not sitting a top a pedistal looking down, it's just that we
have alll been here / there before, and have all matured past this point
with our programming techniques and problem solving methodology ... those
that did not are probably in IT management somewhere ... this is a
fundamental question, and if you can not understand it ... you will have a
steep learning curve as you progress in you studies ... good luck. I am not
digging at you, I am simply stating the obvious! Too many people think that
because they can use a wizard to create a data entry screen, they are
programmers! Unfortunately, you need to understand the theory / methodology
long before you will become a reliable programmer.

Jeff.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top