Attribute VB_Name = "ProgBarDemoModule" Option Explicit '--------------------------------------------------------- 'Progress Bar Demo 'This demo shows the use of the WS_PROGRESS_BAR widget '--------------------------------------------------------- Public wsFactory As New WStFactory Public wsForm As New WStForm Public wsWidget As New WStWidget Public Sub Main() Dim bResult As Boolean Dim sObjectName As String Dim sEventValue As String Dim bEnd As Boolean Dim iIntValue As Integer Dim iMaxVal As Integer Dim iStepVal As Integer Dim iNumberOfIterations As Integer Dim i As Integer Dim x As Integer Dim y As Integer Dim cx As Integer Dim cy As Integer Dim barColorRed As Integer Dim barColorGreen As Integer Dim barColorBlue As Integer Dim backColorRed As Integer Dim backColorGreen As Integer Dim backColorBlue As Integer barColorRed = 255 barColorGreen = 0 barColorBlue = 0 backColorRed = 212 backColorGreen = 208 backColorBlue = 200 iMaxVal = 50 iStepVal = 1 bEnd = False 'Create a form wsFactory.CreateFormByName "progBarForm" wsForm.SetCoordTypeByName "progBarForm", WS_FORM_CT_BYPERCENTAGE 'Create all the widgets that will be used on this form wsFactory.CreateWidget WS_LABEL, 0, "formTittle", 30, 0, 40, 5, "Progress Bar Demo" wsFactory.CreateWidget WS_BUTTON, 0, "exitButton", 10, 80, 32, 12, "Exit" x = 10 y = 15 cx = 45 cy = 15 wsFactory.CreateWidget WS_PROGRESS_BAR, 0, "progBar", x, y, cx, cy, "" wsFactory.CreateWidget WS_BUTTON, 0, "runButton", x + cx + 5, y, 32, 12, "Run!" wsWidget.EnableSubmitModeByName "runButton", True x = 10 y = y + cy + 10 cx = 40 cy = 7 wsFactory.CreateWidget WS_LABEL, 0, "progBarColorsLabel", x, y, cx, 5, "Color" wsFactory.CreateWidget WS_FIELD, 0, "barColorRedField", x, y + 6, cx / 3, cy, "255" wsFactory.CreateWidget WS_FIELD, 0, "barColorGreenField", x + cx / 3 + 1, y + 6, cx / 3, cy, "0" wsFactory.CreateWidget WS_FIELD, 0, "barColorBlueField", x + 2 * cx / 3 + 1, y + 6, cx / 3, cy, "0" x = 10 y = y + 15 cx = 40 cy = 7 wsFactory.CreateWidget WS_LABEL, 0, "progBarBackColorsLabel", x, y, cx, 5, "Background Color" wsFactory.CreateWidget WS_FIELD, 0, "backColorRedField", x, y + 6, cx / 3, cy, "212" wsFactory.CreateWidget WS_FIELD, 0, "backColorGreenField", x + cx / 3 + 1, y + 6, cx / 3, cy, "208" wsFactory.CreateWidget WS_FIELD, 0, "backColorBlueField", x + 2 * cx / 3 + 1, y + 6, cx / 3, cy, "200" x = 60 y = 40 cx = 30 cy = 30 wsFactory.CreateWidget WS_LABEL, 0, "progBarMaxValLabel", x, y, cx, 5, "Max Value" wsFactory.CreateWidget WS_MENU, 0, "progBarMaxValMenu", x, y + 6, cx, cy, "" wsFactory.CreateWidget WS_LABEL, 0, "progBarStepLabel", x, y + 6 + 10, cx, 5, "Step Value" wsFactory.CreateWidget WS_MENU, 0, "progBarStepMenu", x, y + 6 + 15, cx, cy, "" wsFactory.CreateWidget WS_LABEL, 0, "progBarTextLabel", x, y + 6 + 25, cx, 5, "Text" wsFactory.CreateWidget WS_FIELD, 0, "progBarTextField", x, y + 6 + 30, cx, 8, "" 'Widgets customization wsWidget.ModifyInputModeByName "barColorRedField", 0, WS_FIELD_IM_NUMERIC_ONLY wsWidget.ModifyInputModeByName "barColorGreenField", 0, WS_FIELD_IM_NUMERIC_ONLY wsWidget.ModifyInputModeByName "barColorBlueField", 0, WS_FIELD_IM_NUMERIC_ONLY wsWidget.SetMaxLengthByName "barColorRedField", 3 wsWidget.SetMaxLengthByName "barColorGreenField", 3 wsWidget.SetMaxLengthByName "barColorBlueField", 3 wsWidget.ModifyInputModeByName "backColorRedField", 0, WS_FIELD_IM_NUMERIC_ONLY wsWidget.ModifyInputModeByName "backColorGreenField", 0, WS_FIELD_IM_NUMERIC_ONLY wsWidget.ModifyInputModeByName "backColorBlueField", 0, WS_FIELD_IM_NUMERIC_ONLY wsWidget.SetMaxLengthByName "backColorRedField", 3 wsWidget.SetMaxLengthByName "backColorGreenField", 3 wsWidget.SetMaxLengthByName "backColorBlueField", 3 wsWidget.ChangeMenuTypeByName "progBarMaxValMenu", WS_COMBO_BOX_MENU_TYPE wsWidget.ChangeMenuTypeByName "progBarStepMenu", WS_COMBO_BOX_MENU_TYPE wsWidget.SetRangeByName "progBar", 0, 50 wsWidget.SetStepByName "progBar", 1 wsWidget.SetBarColorByName "progBar", 255, 0, 0 'All the menus are fulfilled wsWidget.AddOptionByName "progBarMaxValMenu", 0, "50" wsWidget.AddOptionByName "progBarMaxValMenu", 0, "100" wsWidget.AddOptionByName "progBarMaxValMenu", 0, "150" wsWidget.AddOptionByName "progBarStepMenu", 0, "1" wsWidget.AddOptionByName "progBarStepMenu", 0, "5" wsWidget.AddOptionByName "progBarStepMenu", 0, "10" wsWidget.AddOptionByName "progBarStepMenu", 0, "20" wsWidget.AddOptionByName "progBarStepMenu", 0, "50" wsWidget.SetMaxLengthByName "progBarTextField", 10 'Icons and fonts wsFactory.CreateCustomFont 1, 14, True, False, False, "Times New Roman", 0 wsFactory.LoadExternalIcon 3, WS_EXIT, "iconlib.dll" wsFactory.LoadExternalIcon 4, WS_OK, "iconlib.dll" wsWidget.SetIconByName "exitButton", 3 wsWidget.SetIconByName "runButton", 4 wsWidget.SetFontByName "formTittle", 1 wsWidget.SetFontByName "exitButton", 1 'Attach the widgets to the form wsForm.AddObjectByName "progBarForm", "formTittle" wsForm.AddObjectByName "progBarForm", "exitButton" wsForm.AddObjectByName "progBarForm", "runButton" wsForm.AddObjectByName "progBarForm", "progBar" wsForm.AddObjectByName "progBarForm", "progBarColorsLabel" wsForm.AddObjectByName "progBarForm", "barColorRedField" wsForm.AddObjectByName "progBarForm", "barColorGreenField" wsForm.AddObjectByName "progBarForm", "barColorBlueField" wsForm.AddObjectByName "progBarForm", "progBarBackColorsLabel" wsForm.AddObjectByName "progBarForm", "backColorRedField" wsForm.AddObjectByName "progBarForm", "backColorGreenField" wsForm.AddObjectByName "progBarForm", "backColorBlueField" wsForm.AddObjectByName "progBarForm", "progBarTextLabel" wsForm.AddObjectByName "progBarForm", "progBarTextField" wsForm.AddObjectByName "progBarForm", "progBarMaxValLabel" wsForm.AddObjectByName "progBarForm", "progBarMaxValMenu" wsForm.AddObjectByName "progBarForm", "progBarStepLabel" wsForm.AddObjectByName "progBarForm", "progBarStepMenu" bResult = wsForm.ShowByName("progBarForm", True, True) 'Main loop While (bEnd = False And bResult) bResult = wsForm.GetEvent() sEventValue = wsForm.GetLastEventStrValue() sObjectName = wsForm.GetLastEventSourceName() iIntValue = wsForm.GetLastEventIntValue() Select Case sObjectName Case "exitButton" bEnd = True Case "runButton" iNumberOfIterations = iMaxVal / iStepVal wsWidget.SetBarPositionByName "progBar", 0 For i = 0 To iNumberOfIterations wsWidget.StepByName "progBar" wsForm.CommitChangesByName "progBarForm" Next i 'Updates the progress bar color Case "barColorRedField" barColorRed = sEventValue wsWidget.SetBarColorByName "progBar", barColorRed, barColorGreen, _ barColorBlue Case "barColorGreenField" barColorGreen = sEventValue wsWidget.SetBarColorByName "progBar", barColorRed, barColorGreen, _ barColorBlue Case "barColorBlueField" barColorBlue = sEventValue wsWidget.SetBarColorByName "progBar", barColorRed, barColorGreen, _ barColorBlue 'Updates the progress bar background color Case "backColorRedField" backColorRed = sEventValue wsWidget.SetBackGroundColorByName "progBar", backColorRed, backColorGreen, _ backColorBlue Case "backColorGreenField" backColorGreen = sEventValue wsWidget.SetBackGroundColorByName "progBar", backColorRed, backColorGreen, _ backColorBlue Case "backColorBlueField" backColorBlue = sEventValue wsWidget.SetBackGroundColorByName "progBar", backColorRed, backColorGreen, _ backColorBlue 'Updates the progress bar max value and step Case "progBarMaxValMenu" iMaxVal = Val(wsWidget.GetOptionByName("progBarMaxValMenu", iIntValue)) wsWidget.SetRangeByName "progBar", 0, iMaxVal Case "progBarStepMenu" iStepVal = Val(wsWidget.GetOptionByName("progBarStepMenu", iIntValue)) If iStepVal = 0 Then iStepVal = 1 End If wsWidget.SetStepByName "progBar", iStepVal Case "progBarTextField" wsWidget.SetTextByName "progBar", sEventValue + " " End Select Wend End Sub