|
-
Jan 23rd, 2007, 11:08 AM
#1
Thread Starter
Member
[RESOLVED] Implementation of parameter passing.
Last edited by vert; Jan 23rd, 2007 at 12:04 PM.
-
Jan 23rd, 2007, 11:18 AM
#2
Re: Implementation of parameter passing.
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
Please mark you thread resolved using the Thread Tools as shown
-
Jan 23rd, 2007, 11:23 AM
#3
Re: Implementation of parameter passing.
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
Please mark you thread resolved using the Thread Tools as shown
-
Jan 23rd, 2007, 11:25 AM
#4
Thread Starter
Member
Re: Implementation of parameter passing.
Solved!
Last edited by vert; Jan 23rd, 2007 at 12:04 PM.
-
Jan 23rd, 2007, 11:30 AM
#5
Re: Implementation of parameter passing.
Please mark you thread resolved using the Thread Tools as shown
-
Jan 23rd, 2007, 11:35 AM
#6
Thread Starter
Member
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:
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
-
Jan 23rd, 2007, 11:37 AM
#7
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
-
Jan 23rd, 2007, 11:39 AM
#8
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.
-
Jan 23rd, 2007, 11:40 AM
#9
Re: Implementation of parameter passing.
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
Please mark you thread resolved using the Thread Tools as shown
-
Jan 23rd, 2007, 11:49 AM
#10
Thread Starter
Member
Re: Implementation of parameter passing.
 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.
-
Jan 23rd, 2007, 01:03 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|