Hello.
Simple question???
I will assume that everyone is familiar with the HOUSE macro provided by Attachmate to showcase some of its functionality. It collects some input from the user, then is followed by a msgbox message: Congratulations! You just bought a ..., in Anywhere, USA.
If I wanted to utilize the data selected by the user, from within Main()instead of within the function, how could I do that? Could I even use this same data in other functions?
Simple question???
I will assume that everyone is familiar with the HOUSE macro provided by Attachmate to showcase some of its functionality. It collects some input from the user, then is followed by a msgbox message: Congratulations! You just bought a ..., in Anywhere, USA.
If I wanted to utilize the data selected by the user, from within Main()instead of within the function, how could I do that? Could I even use this same data in other functions?
Code:
Declare Function DisplayChoice(szCity$, iStyle%, iBedBath%, iColor%, szLocale$, _
iShutters%, iFence%, iGarage%) As String
'--------------------------------------------------------------------------------
' Routine: Main
'
' Description: Defines and runs a dialog that enables the user to select specific
' options in the design of there new house.
'
' It uses checkboxes, text strings, option groups, drop list boxes,
' drop combo boxes, and push buttons. It then uses this information
' to display the user's selections.
'
'--------------------------------------------------------------------------------
Sub Main
Dim szCity$, szLocation$
Dim iStyle%, iBedBath%, iColor%, iShutters%, iFence%, iGarage%
Dim iDone%
Dim szHouse as String
Begin Dialog dlgHouseSample 0, 1, 285, 193, "House Designer"
ButtonGroup .ButtonPressed
OkButton 225, 10, 50, 14
CancelButton 225, 30, 50, 14
PushButton 225, 50, 50, 14, "&Reset", .btnReset
Text 10, 28, 20, 10, "City:"
TextBox 30, 25, 79, 14, .tbxCity
OptionGroup .ogStyle
OptionButton 15, 130, 73, 10, "Rambler", .btnRambler
OptionButton 15, 140, 73, 10, "Two Story", .btn2Story
OptionButton 15, 150, 73, 10, "Split Level", .btnSplitLevel
OptionButton 15, 160, 73, 10, "Three Story", .btn3Story
GroupBox 10, 120, 95, 55, "Style"
CheckBox 15, 60, 91, 12, "Shutters", .cbxShutters
CheckBox 15, 75, 91, 12, "Fence", .cbxFence
CheckBox 15, 90, 91, 12, "Garage", .cbxGarage
Text 145, 75, 77, 8, "Color:"
DropListBox 145, 90, 81, 30, "Blue"+chr$(9)+"Brown"+chr$(9)+"Grey"+chr$(9)+"Pink Polka
Dots"+chr$(9)+"White"+chr$(9)+"Yellow", .dlbColor
Text 145, 40, 66, 8, "Location"
DropComboBox 145, 55, 70, 30, "inner city"+chr$(9)+"rural"+chr$(9)+"suburban",
.dcbLocation
Text 12, 5, 202, 9, "Pick the characteristics of your new house."
GroupBox 145, 120, 105, 55, "Bedrooms/Bathrooms"
OptionGroup .ogBedBath
OptionButton 150, 130, 85, 10, "2 Bedroom, 1 Bath", .btn2bd1bth
OptionButton 150, 140, 85, 10, "2 Bedroom, 2 Bath", .btn2bd2bth
OptionButton 150, 150, 85, 10, "3 Bedroom, 1 Bath", .btn3bd1bth
OptionButton 150, 160, 85, 10, "3 Bedroom, 2 Bath", .btn3bd2bth
End Dialog
iDone = FALSE
While (iDone = FALSE)
Dim dMain as dlgHouseSample
nRet = Dialog(dMain)
Select Case nRet
Case -1 ' -1 is returned if the user chose OK
iDone = TRUE
szCity = dMain.tbxCity
iStyle = dMain.ogStyle
iBedBath = dMain.ogBedBath
iColor = dMain.dlbColor
szLocation = dMain.dcbLocation
iShutters = dMain.cbxShutters
iFence = dMain.cbxFence
iGarage = dMain.cbxGarage
szHouse = DisplayChoice(szCity, iStyle, iBedBath, iColor, szLocation, _
iShutters, iFence, iGarage)
msgbox (szHouse)
Case 0 ' 0 is returned if the user chose Cancel
iDone = TRUE
Case 1 ' 1 is returned if the user chose Reset
dMain.tbxCity = ""
dMain.ogStyle = 0
dMain.ogBedBath = 0
dMain.dlbColor = 0
dMain.dcbLocation = ""
dMain.cbxShutters = 0
dMain.cbxFence = 0
dMain.cbxGarage = 0
Case Else
msgbox "Some undefined button pressed " + str(dMain.ButtonPressed)
End Select
Wend
End Sub
'--------------------------------------------------------------------------------
' Function: DisplayChoice(szCity$, iStyle%, iBedBath%, iColor%, szLocale$
' iShutters%, iFence%, iGarage%) as String
'
' Parameters: szCity - String containing the selected city.
' iStyle - Integer indicating Style selection.
' iBedBath - Integer designating bedroom and bathroom selections.
' iColor - Integer specifying Color choice.
' iLocale - String containing the locale selected.
' iShutters - Boolean that indicates yes/no for shutters.
' iFence - Boolean that indicates yes/no for fence.
' iGarage - Boolean that indicates yes/no for garage.
'
' Description: This function returns a string containing a description of
' the house characteristics that were selected.
'
'--------------------------------------------------------------------------------
Function DisplayChoice(szCity$, iStyle%, iBedBath%, iColor%, szLocale$, iShutters%, _
iFence%, iGarage%) As String
Dim szStyle$, szBedBath$, szColor$, szShutters$, szFence$, szGarage$
Dim szResult$
If (Trim(szCity) = "") Then
szCity = "Anywhere, USA"
End If
Select Case iStyle
Case 0
szStyle = "rambler"
Case 1
szStyle = "two story house"
Case 2
szStyle = "split level house"
Case 3
szStyle = "three story house"
End Select
Select Case iBedBath
Case 0
szBedBath = "two bedroom, one bathroom"
Case 1
szBedBath = "two bedroom, two bathroom"
Case 2
szBedBath = "three bedroom, one bathroom"
Case 3
szBedBath = "three bedroom, two bathroom"
End Select
Select Case iColor
Case 0
szColor = "blue"
Case 1
szColor = "brown"
Case 2
szColor = "grey"
Case 3
szColor = "pink polka dot"
Case 4
szColor = "white"
Case 5
szColor = "yellow"
End Select
Select Case iShutters
Case 0
szShutters = "out "
Case 1
szShutters = " "
End Select
Select Case iFence
Case 0
szFence = "an unfenced, "
Case 1
szFence = "a fenced, "
End Select
Select Case iGarage
Case 0
szGarage = "out "
Case 1
szGarage = " "
End Select
szResult = "Congratulations, you have selected " + szFence + szBedBath + ", " + _
szColor + ", " + szStyle + " with" + szShutters + "shutters" + _
" and with" + szGarage + "a garage in a " + szLocale + " community in " + _
szCity + "."
DisplayChoice = szResult
End Function