160 likes | 306 Views
Dialog Boxes – Day 1. Built-in Dialog Boxes Input Box Message Box Custom Dialog Boxes – User Forms. Form. Title: form property. Label. Text Box. Command Buttons. Form Controls. Built-in boxes Form: overall rectangle Controls: tools used to make box function. User Form Design.
E N D
Dialog Boxes – Day 1 • Built-in Dialog Boxes • Input Box • Message Box • Custom Dialog Boxes – User Forms
Form Title: form property Label Text Box Command Buttons Form Controls • Built-in boxes • Form: overall rectangle • Controls: tools used to make box function
User Form Design • Decide what data to collect • Design form layout • Select form tools • Write code to use data • What event triggers? • How is data used? • Write macro to display form
Text Box Check Box, Toggle Frame, Option Buttons Combo Box, List Box Data Collection • Data types • Text • Numbers • Yes/No • Exclusive options • Lists • Choose control to fit
Start Get Name, Temp in °F Convert °F to °C Display Name, Temp in °C End Example: Temperature Convert °F to °C • Decide on Inputs • Name • Temp, °F • Determine Output • Name + °C • Determine action • Event – button? • Psuedocode
Start Get Name, Temp in °F Convert °F to °C Display Name, Temp in °C End Example: Temperature • Pseudocode Ask for user’s name Ask for temp, °F DegC = (DegF-32)*5/9 Display name and DegC
Input Name Label Temp, °F Output Action Form Layout • Use form to collect inputs, display output Temperature x Output Area Go
Insert User Form Form name Form properties
Form Tools • Label • Text Box • Command button
User Form Objects Object Names • Text Boxes txtName txtDegF • Labels lblOut • Buttons cmdOK • Object and variable names must be different!
Action Code • Event Driven • Form events tied to object on form • Double-click object to add code • VBA selects name based on form object • Form holds data, does nothing • Code tells VBA how to use it • Data called by object name • Assignment statements tell use
Form Process Ron 86 Ron, the temperature is 30 Degrees C
Display Macro • Form won’t appear until its called • Need a macro • Goes in module, not form code • Need name of form • Only one line of code Sub ShowForm( ) MyForm.Show End Sub
Hiding Forms • You choose when • After code runs • Separate button • Two forms • MyForm.hide – form still active • Unload MyForm – closes form • Unload Me