Results 1 to 12 of 12

Thread: [RESOLVED] New to VB 6! Can't code this program.. :(

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Resolved [RESOLVED] New to VB 6! Can't code this program.. :(

    Ok, here are the details... I've spent hours trying to code this simple program but it refuses to work... I am completely new to this and am starting to think that i'm a little too stupid to learn vb..

    1) This is a hotel reservation system and the hotel name is constant. Let say Hilton.

    2) Initially, the program will contain 10 guest names already. I tried using array but I've no idea what to do next..

    3) The program then asks for the names and will validate them before the guests will be able to book a room. Error will be generated when the name is wrongly inserted and the thing will loop over and over asking for reentry of name. (Here.. I tried using the "do while.. loop" but it doesn't recognise my array)

    4) The guests will then have to choose between 10 rooms and an error will be generated if the rooms were booked already. (How is this even possible? Do I just pick a random rooms as full already or is there a proper way?) Again, the thing will ask for another room and loops.

    5) Finally, all the details about one guest's booking (the one that "log in") will be displayed. Do I use picturebox for this?

    As an additional note, how, do I use subprograms and parameter passing in this? I've read the vb for dummies book but I still am clueless...

    I just don't understand the concept of parameter passing or subprograms. I will really appreciate it if anyone can help a newbie here. If possible, don't give explanations that are too hard to follow since I've asked my friend who works in the IT industry and he suggested that I use access to store the guest details... lol.. I only need a simple program...

    I know I've been rambling for a bit.. sorry!

    Thanks!

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: New to VB 6! Can't code this program.. :(

    Welcome to vbf!

    If this is a School assignment, then we cannot help you write the program, we wont write the whole program any way.

    We will only help with specific questions...



    Have you thought about using a Database?
    My usual boring signature: Something

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: New to VB 6! Can't code this program.. :(

    Nah, i don't expect you guys to write the code, more like point me at the right direction..

    For the array I tried and use..

    Dim guest(10) as string

    Guest(0) = name1
    Guest(1) = name 2

    and so on..

    The problem comes when I tried to do the do..while loop..

    valid = InputBox("Who are you?")

    Do While valid <> guest(10) -----> It won't recognise this..why?
    valid = InputBox("reenter")
    Loop

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: New to VB 6! Can't code this program.. :(

    I am not good with arrays, but i am guessing that dimming "guest(10)" is not proper.

    Try this:

    VB Code:
    1. Dim guest() as String

    And use [vbcode ] [ /vbcode] tags
    My usual boring signature: Something

  5. #5
    Addicted Member
    Join Date
    Dec 2005
    Posts
    230

    Re: New to VB 6! Can't code this program.. :(

    I guess it's because dim guest(10) = start from 0 ...9
    so 10 is not valid

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: New to VB 6! Can't code this program.. :(

    The array declaration is fine, and by definition there is an element 10 (the number in the Dim line is not the amount of items, but the index of the last item).

    vert, try to be very specific about the problems you are having... dclamp and Vntalk have assumed that you are getting an error message pop up, but I dont think you are - I think it just isn't working as you want it to.

    As you currently have it, you are only comparing to one of the guests ( guest(10) ), instead of checking if it is any of them. To do that you need to use a loop.

    I would recommend looking at this FAQ thread which explains about arrays, and how to use them. (you will probably find other useful info in our Classic VB FAQ's, link below).

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: New to VB 6! Can't code this program.. :(

    Oh, I thought by using ( guest(10) ), or 9 perhaps, I will be comparing it from 0-9..all at once...

    That page seems very helpful... but I still don't understand it.. how do you include every array in the input validation?

    it's about 12 am now so im going to go..

    I will update on my progress tomorrow...
    Last edited by vert; Jan 21st, 2007 at 07:17 PM.

  8. #8
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: New to VB 6! Can't code this program.. :(

    Quote Originally Posted by vert
    Oh, I thought by using ( guest(10) ), or 9 perhaps, I will be comparing it from 0-9..all at once...

    That page seems very helpful... but I still don't understand it.. how do you include every array in the input validation?

    it's about 12 am now so im going to go..

    I will update on my progress tomorrow...
    Im not sure how to do this in vb, but you are going to have to make it so that the integer within guest() is greater than 1 and less than 10
    My usual boring signature: Something

  9. #9
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: New to VB 6! Can't code this program.. :(

    See if this gets you going in the right direction
    VB Code:
    1. Option Explicit
    2. Dim strGuests(4) As String
    3.  
    4. Private Sub Command1_Click()
    5. Dim blnValid As Boolean
    6. Dim strInput As String
    7. Dim i As Integer
    8.  
    9.     Do
    10.         'Get the name
    11.         strInput = LCase(InputBox("Who are you?"))
    12.         'Check if the name is in the array
    13.         For i = 0 To 4
    14.             If LCase(strGuests(i)) = strInput Then
    15.                 blnValid = True
    16.                 Exit For
    17.             End If
    18.         Next i
    19.     'Loop while a valid name has not been entered
    20.     Loop While Not blnValid
    21.    
    22.     MsgBox "valid name"
    23. End Sub
    24.  
    25. Private Sub Form_Load()
    26.     strGuests(0) = "Vert"
    27.     strGuests(1) = "dclamp"
    28.     strGuests(2) = "vntalk"
    29.     strGuests(3) = "si_the_geek"
    30.     strGuests(4) = "MarkT"
    31. End Sub

  10. #10
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: New to VB 6! Can't code this program.. :(

    There have been suggestions made in the past about ways to quick-search an array. If the array is fixed, my suggestion has always been to set up a string with each entry in it and a * on either side of the name...as in "*Vert*dclamp*vntalk*si_the_geek*MarkT*"...then when you are checking for a name you instr for "*" & name & "*" and it should return 0 if the name isn't in there. Downside to that is it doesn't return the location (so you will only know it is a valid name, not which one in the array is that name). It's a lot of work for a simple bit of code though, and if you want to go the easy way then a loop would be the better option.

    I'd go with a simple loop in this case :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: New to VB 6! Can't code this program.. :(

    When addressing an array it's always better to use LBound(ArrayName) and UBound(ArrayName) as the lower and upper element numbers. That way, if you have to change the number of elements in the array you won't have to go through your code changing every occurrence of the lower or upper element number.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  12. #12

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: New to VB 6! Can't code this program.. :(

    Quote Originally Posted by MarkT
    See if this gets you going in the right direction
    VB Code:
    1. Option Explicit
    2. Dim strGuests(4) As String
    3.  
    4. Private Sub Command1_Click()
    5. Dim blnValid As Boolean
    6. Dim strInput As String
    7. Dim i As Integer
    8.  
    9.     Do
    10.         'Get the name
    11.         strInput = LCase(InputBox("Who are you?"))
    12.         'Check if the name is in the array
    13.         For i = 0 To 4
    14.             If LCase(strGuests(i)) = strInput Then
    15.                 blnValid = True
    16.                 Exit For
    17.             End If
    18.         Next i
    19.     'Loop while a valid name has not been entered
    20.     Loop While Not blnValid
    21.    
    22.     MsgBox "valid name"
    23. End Sub
    24.  
    25. Private Sub Form_Load()
    26.     strGuests(0) = "Vert"
    27.     strGuests(1) = "dclamp"
    28.     strGuests(2) = "vntalk"
    29.     strGuests(3) = "si_the_geek"
    30.     strGuests(4) = "MarkT"
    31. End Sub
    That helps a lot! Thanks!

    I think this will be enough to start me off.
    Last edited by vert; Jan 22nd, 2007 at 03:13 PM.

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