Results 1 to 11 of 11

Thread: [RESOLVED] Implementation of parameter passing.

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Resolved [RESOLVED] Implementation of parameter passing.

    Solved
    Last edited by vert; Jan 23rd, 2007 at 12:04 PM.

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Implementation of parameter passing.

    Try this one
    VB Code:
    1. Option Explicit
    2. Public Function GetInput() As String
    3.  
    4. guest(0) = "a"
    5. guest(1) = "b"
    6. guest(2) = "c"
    7.  
    8.  
    9. Do
    10.         strinput = InputBox("Who are you?")
    11.         'Check if the name is in the array
    12.     For i = 0 To 2
    13.         If guest(i) = strinput Then
    14.                 blnvalid = True
    15.                 GetInput = guest(i) 'get the string then exit
    16.                 Exit Function
    17.          End If
    18.         Next i
    19.     'Loop while a valid name has not been entered
    20.     Loop While Not blnvalid
    21.  
    22. End Function
    23.  
    24. Private Sub Command1_Click()
    25.     'Call the function
    26.     MsgBox GetInput
    27. End Sub
    Please mark you thread resolved using the Thread Tools as shown

  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Implementation of parameter passing.

    Here is the modified version
    VB Code:
    1. Option Explicit
    2. Public Function GetInput() As String
    3. Dim guest(3)
    4. Dim strinput
    5. Dim i As Integer
    6. Dim blnvalid As Boolean
    7. guest(1) = "a"
    8. guest(2) = "b"
    9. guest(3) = "c"
    10.  
    11.  
    12. Step1:
    13. Do
    14.         strinput = InputBox("Who are you?")
    15.         'Check if the name is in the array
    16.         'If the user click the cancel button then ask goto the begining
    17.         If StrPtr(strinput) = 0 Then GoTo Step1
    18.     For i = 0 To 2
    19.        
    20.         If guest(i) = strinput Then
    21.                 blnvalid = True
    22.                 GetInput = guest(i) 'get the string then exit
    23.                 Exit Function
    24.          End If
    25.         Next i
    26.     'Loop while a valid name has not been entered
    27.     Loop While Not blnvalid
    28.  
    29. End Function
    30.  
    31. Private Sub Command1_Click()
    32.     'Call the function
    33.     MsgBox GetInput
    34. End Sub
    Please mark you thread resolved using the Thread Tools as shown

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Implementation of parameter passing.

    Solved!
    Last edited by vert; Jan 23rd, 2007 at 12:04 PM.

  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Implementation of parameter passing.

    What is your aim?
    Please mark you thread resolved using the Thread Tools as shown

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Implementation of parameter passing.

    In theory, i want it to look like this. The parameter passing is wrong for the strinput though...

    I want the program to appear in 3 chunks, with the first one acting as the main control room.

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. Const hotel = "Hilton"
    4.  
    5. Dim guest(2) As String
    6. Dim room As Variant
    7. Dim i As Integer
    8. Dim blnvalid As Boolean
    9. Dim strinput As String
    10.  
    11.  
    12. Call parameter(room)
    13. Call validation(strinput) ' This is the mainprogram calling for the input of strinput
    14.  
    15.  '*********************************************************
    16. Private Sub validation(strinput)
    17.  
    18. guest(0) = "a"  'Do this appear in the main program or here?
    19. guest(1) = "b"
    20. guest(2) = "c"
    21.  
    22.  
    23. Do
    24.         strinput = InputBox("Who are you?")
    25.         'Check if the name is in the array
    26.     For i = 0 To 2
    27.         If guest(i) = strinput Then
    28.                 blnvalid = True
    29.             End If
    30.         Next i
    31.     'Loop while a valid name has not been entered
    32.     Loop While Not blnvalid
    33.  
    34.  
    35.  
    36.  
    37. End Sub
    38.  
    39. '********************************************************
    40. Private Sub parameter(room)
    41.  
    42. room = InputBox("Choose a room")
    43.  
    44. Do While room < 1 Or room > 5 Or room = 3
    45. room = InputBox("The selection might have been out of range. (Note: Room 3 is booked)")
    46. Loop
    47.  
    48. end sub

  7. #7
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Implementation of parameter passing.

    First you have to change the keyword "parameter" to some other .
    Please mark you thread resolved using the Thread Tools as shown

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Implementation of parameter passing.

    if the data in the array is static then assign it only once such as during form load event.

    You have to return a value to the calling procedure so use functions instead of subs as previous samples showed. And placew the function in a code module to make it public.

  9. #9
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Implementation of parameter passing.

    Try this one
    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. Const hotel = "Hilton"
    4.  
    5. Dim guest(2) As String
    6. Dim room As Variant
    7. Dim i As Integer
    8. Dim blnvalid As Boolean
    9. Dim strinput As String
    10.  
    11.  
    12. Call parameter(room)
    13. 'Call validation(strinput) ' This is the mainprogram calling for the input of strinput
    14. 'Call validation(strinput) ' This is the mainprogram calling for the input of strinput
    15. Call GetInput
    16. End Sub
    17.  '*********************************************************
    18. Public Function GetInput() As String
    19. Dim guest(3)
    20. Dim strinput
    21. Dim i As Integer
    22. Dim blnvalid As Boolean
    23. guest(1) = "a"
    24. guest(2) = "b"
    25. guest(3) = "c"
    26.  
    27.  
    28. Step1:
    29. Do
    30.         strinput = InputBox("Who are you?")
    31.         'Check if the name is in the array
    32.         'If the user click the cancel button then ask goto the begining
    33.         If StrPtr(strinput) = 0 Then GoTo Step1
    34.     For i = 0 To 2
    35.  
    36.         If guest(i) = strinput Then
    37.                 blnvalid = True
    38.                 GetInput = guest(i) 'get the string then exit
    39.                 Exit Function
    40.          End If
    41.         Next i
    42.     'Loop while a valid name has not been entered
    43.     Loop While Not blnvalid
    44.  
    45. End Function
    46. '********************************************************
    47. Private Sub parameter(room)
    48.  
    49. room = InputBox("Choose a room")
    50.  
    51. Do While room < 1 Or room > 5 Or room = 3
    52. room = InputBox("The selection might have been out of range. (Note: Room 3 is booked)")
    53. Loop
    54.  
    55. End Sub
    Please mark you thread resolved using the Thread Tools as shown

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Implementation of parameter passing.

    Quote Originally Posted by leinad31
    if the data in the array is static then assign it only once such as during form load event.

    You have to return a value to the calling procedure so use functions instead of subs as previous samples showed. c
    What do you mean by "And placew the function in a code module to make it public."?

    I'm sorry.. im such a noob lol...


    NEVERMIND.. IT WORKS!!!!!!!1 YESSHHH!!! I USE PUBLIC FUNCTION AND IT WORKS! YAYYY!!!!
    Last edited by vert; Jan 23rd, 2007 at 12:03 PM.

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

    Re: [RESOLVED] Implementation of parameter passing.

    Please don't edit out your posts - they would be useful for other people who have a similar problem and read this thread later.

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