VB Programin Task Help !!!!

pcmagic

Member
To be honest here im not too great with programming on Visual Basic, Im asking please if somebody could help me out? I would appreciate it to a great extent!

Thanks very much,

******************

My Task......

The hotel wants to have a program to calculate the bills for guests checking out each day.

The program will ask how many guests are checking out that day (in range 1 to 10 inclusive) and then for each of those guests, aks their name. The number of nights they stayed and the room type (either *S* for a single or *T* for a double). You may asume that all numbers entered are whole numbers.

The program will calculate the amount for each guest. The total is calculated by muitplying the number of nights by the room rate. The room rate depends on the room type £60 = single, £90 = Twin, £80 = Double

The Program should display the guest’s Bill.
The Process is repeated for each guest.

The output from the program should look like this.



Pseudocode

1 Get valid number of guests checking out (in range 1 to 10 inclusive)
2 For each guest
3 Get guest name
4 get number of nights
5 get valid room type (S, T or D)
6 Calculate amount due
7 Display guest details
8 END LOOP

7 Display guest detalis
7.1 Display guest name
7.2 Display number of nights
7.3 Display room type
7.4 Display Amount due
 
I am not a VB programmer, I am learning PHP myself. But I am wondering what help is it that you are asking for:confused: Your pseudocode looks ok. Just start coding.
 
You can delete a post - just hit edit -> delete post. As for your problem, i've done a fair bit of VB programming, and i'd be happy to help. Not quite sure what you're after though. Do you need to know where to start, or are you just looking for some help if you run into trouble.
 
I could give you a hand I've been doing programming on VB for a while now.
You will need a loop in there so I'm going to suggest this.

Your first task is to get the end user to enter the number of guest's checking out and make that a variable. (e.g. b) then what you need to do is use a for loop.
Example
For I=0 to b 'b being the amount of people checking out

Then get all the details and store all the info into an array, then print the details of the array onto the list boxes.

If you need any more help or can be a bit more specific then please leave more details (I will not code this thing for you though lol)
 
I just really know where to start and how llol

Thanks Hellbreather but that was basicly double dutch to me lol
 
Okay first of all, you need to create the first form with the labels and the list boxes, following this you need 3 buttons "Get Details" , "Exit" and "Clear".

And I can't really explain the code without using terminology.
 
Hellbreather's is a more elegant solution, but for the sake of simplicity, i'd be more inclined to just use the List.AddItem command to add the items to the list as they're entered, rather than creating an array.

Write a loop that:
1) prompts the user to input the details and then
2) Uses the List.AddItem function to add these details to the lists
 
Loop untill
Name = Inputputbox = "Please enter your name"

No of nights = inputbox = "Please enter the number of nights you will be staying"

Room Type = inputbox = "Please enter the room type you would like to stay in"

ListName.AddItem = Name
ListNights.AddItem = No of Nights
ListType.AddItem = Room Type

End Loop


******
HOw do you calculate the bill ?
Is that ok or what have i done wrong ?
 
Sorry for not responding sooner, your input box syntax isn't exactly right (and you can't have spaces in variable names), but that's pretty much it.

To calculate the total bill, i'd define a new variable called room_cost.

Then say something like:
if room_type = "Single" Then room_cost = 60
if room_type = "Double" Then room_cost = 80
(etc...)

once you've found the room_cost, bill=room_cost * number_of_nights

If you want to send me your code, i'll take a look at it.

Again, there are more efficient ways, but this is about the simplest.
 
Option Explicit
Dim Guest As String
Dim Howlong As Integer
Dim Room_type As String
Dim Room_cost as String

Private Sub cmdStart_Click()
Call Getnames
Call Nights
Call Roomtype
Call Bill
Call Disply
End Sub

Sub Getnames()
Guest = InputBox("Please enter your name below please.")
End Sub

Sub Nights()
Howlong = InputBox("PLease enter the number of night you stayed.")
End Sub

Sub Roomtype()
Room_type = InputBox("Please enter the Room Type you stayed in. Single, Double or Twin")
End Sub

Sub Bill()
if Room_type = "Single" Then Room_cost = 60
if Room_type = "Double" Then Room_cost = 80
if Room_type = "Twin" Then Room_cost = 90
End Sub

Sub Disply()
lstname.AddItem = Guest
ListNights.AddItem = Howlong
ListType.AddItem = Room_type
ListBill.AddItem = Bill
End Sub


*****


I Know there still more to do, but im kinda stuck n lost a little now .. Do i need counters or what?? how to i get info into arrays.???Help

Thanks
 
that code will work fine, its not the most effective though consider using functions for getname, nights, and room_type. That we you dont need to maintain Dim Guest As String,
Dim Howlong As Integer,
Dim Room_type As String, or
Dim Room_cost as String
as globals, which may cause you problems later on when you think the variables have fallen out of scope.

Also theres not much error checking in there, what is the user presses cancel, or enters text when you expect a number. Here is some better code with error checking and less globals

Code:
Option Explicit



Function Getnames() As String
Getnames = InputBox("Please enter your name below please.")
End Function

Function Nights() As Integer
Dim temp
temp = InputBox("PLease enter the number of night you stayed.")
If IsNumeric(temp) = False Then
MsgBox "Error, invalid number"
Nights = 0
Else
Nights = temp
End If

End Function

Function Roomtype() As String
'this is a goto marker
Dim temp
Repeat:

temp = UCase(InputBox("Please enter the Room Type you stayed in. Single, Double or Twin"))

If temp = "SINGLE" Or temp = "DOUBLE" Or temp = "TWIN" Then
    Roomtype = temp
Else
    If MsgBox("Invalid input do you want to cancel", vbYesNo, "Error") = vbYes Then
        temp = ""
    Else
        GoTo Repeat
    End If

End If
End Function

Function Bill(Room_type As String) As Integer
If Room_type = "SINGLE" Then Bill = 60
If Room_type = "DOUBLE" Then Bill = 80
If Room_type = "TWIN" Then Bill = 90
End Function

Function Disply(Guest_Name As String, Length_stayed As Integer, Type_of_room As String, Cost As Integer) As Integer
lstname.AddItem Guest_Name
ListNights.AddItem Length_stayed
ListType.AddItem Type_of_room
ListBill.AddItem Cost

Disply = 1 'return success
End Function



Private Sub cmdStart_Click()
Dim Guest As String
Dim Howlong As Integer
Dim Room_type As String
Dim Room_cost As Integer
Dim i


Guest = Getnames
If Guest = "" Then Exit Sub

Howlong = Nights
If Howlong = 0 Then Exit Sub

Room_type = Roomtype
If Room_type = "" Then Exit Sub

Room_cost = Bill(Room_type)
If Room_cost = 0 Then Exit Sub

i = Disply(Guest, Howlong, Room_type, Room_cost)
If i < 0 Then MsgBox "An unknown error occured in adding to the list"
End Sub
 
apj101 thats Brill thanks very much ... But the thing is its a bit advanced for my likings i dont understand some of it ....

Like Whats Function ????

Could you Basic it down a little or Go through it so i understand please /??

Thanks
 
Back
Top