Solved
Printable View
Solved
Try this one
VB Code:
Option Explicit Public Function GetInput() As String guest(0) = "a" guest(1) = "b" guest(2) = "c" Do strinput = InputBox("Who are you?") 'Check if the name is in the array For i = 0 To 2 If guest(i) = strinput Then blnvalid = True GetInput = guest(i) 'get the string then exit Exit Function End If Next i 'Loop while a valid name has not been entered Loop While Not blnvalid End Function Private Sub Command1_Click() 'Call the function MsgBox GetInput End Sub
Here is the modified version
VB Code:
Option Explicit Public Function GetInput() As String Dim guest(3) Dim strinput Dim i As Integer Dim blnvalid As Boolean guest(1) = "a" guest(2) = "b" guest(3) = "c" Step1: Do strinput = InputBox("Who are you?") 'Check if the name is in the array 'If the user click the cancel button then ask goto the begining If StrPtr(strinput) = 0 Then GoTo Step1 For i = 0 To 2 If guest(i) = strinput Then blnvalid = True GetInput = guest(i) 'get the string then exit Exit Function End If Next i 'Loop while a valid name has not been entered Loop While Not blnvalid End Function Private Sub Command1_Click() 'Call the function MsgBox GetInput End Sub
Solved! :D
What is your aim?
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:
Private Sub Command1_Click() Const hotel = "Hilton" Dim guest(2) As String Dim room As Variant Dim i As Integer Dim blnvalid As Boolean Dim strinput As String Call parameter(room) Call validation(strinput) ' This is the mainprogram calling for the input of strinput '********************************************************* Private Sub validation(strinput) guest(0) = "a" 'Do this appear in the main program or here? guest(1) = "b" guest(2) = "c" Do strinput = InputBox("Who are you?") 'Check if the name is in the array For i = 0 To 2 If guest(i) = strinput Then blnvalid = True End If Next i 'Loop while a valid name has not been entered Loop While Not blnvalid End Sub '******************************************************** Private Sub parameter(room) room = InputBox("Choose a room") Do While room < 1 Or room > 5 Or room = 3 room = InputBox("The selection might have been out of range. (Note: Room 3 is booked)") Loop end sub
First you have to change the keyword "parameter" to some other .
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.
Try this one
VB Code:
Private Sub Command1_Click() Const hotel = "Hilton" Dim guest(2) As String Dim room As Variant Dim i As Integer Dim blnvalid As Boolean Dim strinput As String Call parameter(room) 'Call validation(strinput) ' This is the mainprogram calling for the input of strinput 'Call validation(strinput) ' This is the mainprogram calling for the input of strinput Call GetInput End Sub '********************************************************* Public Function GetInput() As String Dim guest(3) Dim strinput Dim i As Integer Dim blnvalid As Boolean guest(1) = "a" guest(2) = "b" guest(3) = "c" Step1: Do strinput = InputBox("Who are you?") 'Check if the name is in the array 'If the user click the cancel button then ask goto the begining If StrPtr(strinput) = 0 Then GoTo Step1 For i = 0 To 2 If guest(i) = strinput Then blnvalid = True GetInput = guest(i) 'get the string then exit Exit Function End If Next i 'Loop while a valid name has not been entered Loop While Not blnvalid End Function '******************************************************** Private Sub parameter(room) room = InputBox("Choose a room") Do While room < 1 Or room > 5 Or room = 3 room = InputBox("The selection might have been out of range. (Note: Room 3 is booked)") Loop End Sub
What do you mean by "And placew the function in a code module to make it public."?Quote:
Originally Posted by leinad31
I'm sorry.. im such a noob lol...
NEVERMIND.. IT WORKS!!!!!!!1 YESSHHH!!! I USE PUBLIC FUNCTION AND IT WORKS! YAYYY!!!!
Please don't edit out your posts - they would be useful for other people who have a similar problem and read this thread later. ;)