Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub UserForm_Activate()
- ' Store the name of the form in the currentForm global variable
- currentFormName = Me.Name
- ' Display the correct colors for the ActivityButton and PartyMembersButon using the corresponding global variables
- If activityButtonColor = 0 Then
- activityButtonColor = &H8000000D 'Reset the global variable to the default color if it is null/has'nt been set yet(Blue)
- End If
- Me.ActivityButton.BackColor = activityButtonColor
- If partyMembersButtonColor = 0 Then
- partyMembersButtonColor = &H80FF& 'Reset the global variable to the default color if it is null/has'nt been set yet(Orange)
- End If
- Me.PartyMembersButton.BackColor = partyMembersButtonColor
- 'Display the current interval time in the label, by combining the currentIntervalHour and currentIntervalMinute global variables
- LabelCurrentInterval.Caption = currentIntervalHour & ":" & currentIntervalMinute
- ' Set the ComboBoxVocalization value to the global Vocalization variable, if it exists
- If selectedVocalization <> vbNullString Then
- ComboBoxVocalization.Value = selectedVocalization
- End If
- ' Set the ComboBoxWeather value to the global Weather variable, if it exists
- If selectedWeather <> vbNullString Then
- ComboBoxWeather.Value = selectedWeather
- End If
- ' Set the ComboBoxHeight value to the global Height variable, if it exists
- If selectedHeight <> vbNullString Then
- ComboBoxHeight.Value = selectedHeight
- End If
- ' Set the OptionButton for visibility to selectedVisibility global variable, if it exists
- Select Case selectedVisibility
- Case "0"
- OptionButton0.Value = True
- Case "1"
- OptionButton1.Value = True
- Case "2"
- OptionButton2.Value = True
- Case "Obs.break"
- OptionButtonObsBreak.Value = True
- Case Else
- ' No option selected; reset all OptionButtons
- OptionButton0.Value = False
- OptionButton1.Value = False
- OptionButton2.Value = False
- OptionButtonObsBreak.Value = False
- End Select
- End Sub
- Private Sub ComboBoxWeather_Change()
- 'assign the selected value in ComboBoxWeather to the selectedWeather global variable
- selectedWeather = ComboBoxWeather.Value
- End Sub
- Private Sub ComboBoxHeight_Change()
- 'assign the selected value in ComboBoxHeight to the selectedHeight global variable
- selectedHeight = ComboBoxHeight.Value
- End Sub
- Private Sub ComboBoxVocalization_Change()
- 'assign the selected value in ComboBoxVocalization to the selectedVocalization global variable
- selectedVocalization = ComboBoxVocalization.Value
- End Sub
- 'The 4 subs below make sure that the local visibility variable is assigned the value of the corresponding OptionButton;
- 'it also attributes a similar index value that we will use in the next sub
- Private Sub OptionButton0_Click()
- HandleOptionButtonClick 0, "0"
- End Sub
- Private Sub OptionButton1_Click()
- HandleOptionButtonClick 1, "1"
- End Sub
- Private Sub OptionButton2_Click()
- HandleOptionButtonClick 2, "2"
- End Sub
- Private Sub OptionButtonObsBreak_Click()
- HandleOptionButtonClick "ObsBreak", "Obs.break"
- End Sub
- ' This sub handles color updates, so the selected OptionButton gets colored in green, and gets back to normal when unselected
- 'It also updates the local visibility variable so it corresponds to the selected button
- Private Sub HandleOptionButtonClick(ByVal Index As Variant, ByVal visibility As String)
- 'Update the value of the local visibility variable
- HandleVisibilityChange visibility
- ' Manually reset colors for all OptionButtons
- OptionButton0.BackColor = &HC0C0C0 ' Default color
- OptionButton1.BackColor = &HC0C0C0
- OptionButton2.BackColor = &HC0C0C0
- OptionButtonObsBreak.BackColor = &HFFFFC0
- ' Change color of the selected OptionButton
- If IsNumeric(Index) Then
- Me.Controls("OptionButton" & Index).BackColor = RGB(0, 200, 100) ' Green
- Else
- 'as OptionButtonObsBreak does not have a numerical index, we need to handle it separately
- Me.Controls("OptionButtonObsBreak").BackColor = RGB(0, 200, 100) ' Green
- End If
- End Sub
- Private Sub HandleVisibilityChange(ByVal visibility As String)
- ' Update the selectedVisibility global variable, using the local visibility variable
- selectedVisibility = visibility
- End Sub
- Private Sub CommandButtonBackToIntervalForm_Click()
- Unload Me
- intervalForm.Show
- End Sub
- Private Sub ActivityButton_Click()
- Me.Hide
- mainActivityForm.Show
- End Sub
- Private Sub PartyMembersButton_Click()
- Me.Hide
- PartyMemberForm.Show
- End Sub
- Private Sub CommandButtonReviewActivityData_Click()
- Dim wsActivity As Worksheet
- Set wsActivity = ThisWorkbook.Sheets("Activity Data")
- wsActivity.Activate
- Set wsActivity = Nothing
- Unload Me
- backToPreviousFormForm.Show vbModeless
- End Sub
- Private Sub CommandButtonComment_Click()
- CommentForm.Show
- End Sub
- Private Sub CommandButtonSocialNotes_Click()
- socialNotesForm.Show
- End Sub
- Private Sub CommandButtonSaveAndNext_Click()
- Dim wsActivity As Worksheet
- Set wsActivity = ThisWorkbook.Sheets("Activity Data")
- ' Update worksheet values
- wsActivity.Cells(currentIntervalRow, 112).Value = selectedWeather
- wsActivity.Cells(currentIntervalRow, 7).Value = selectedVisibility
- wsActivity.Cells(currentIntervalRow, 20).Value = selectedVocalization
- wsActivity.Cells(currentIntervalRow, 19).Value = selectedHeight
- ' Move to next row
- currentIntervalRow = currentIntervalRow + 1
- currentIntervalHour = Format(wsActivity.Cells(currentIntervalRow, 5).Value, "00")
- currentIntervalMinute = Format(wsActivity.Cells(currentIntervalRow, 6).Value, "00")
- ' Update UI elements in a single batch
- LabelCurrentInterval.Caption = currentIntervalHour & ":" & currentIntervalMinute
- OptionButton0.BackColor = &HC0C0C0
- OptionButton1.BackColor = &HC0C0C0
- OptionButton2.BackColor = &HC0C0C0
- OptionButtonObsBreak.BackColor = &HFFFFC0
- ActivityButton.BackColor = &H8000000D
- PartyMembersButton.BackColor = &H80FF&
- activityButtonColor = &H8000000D 'Reset the global variable to Blue
- partyMembersButtonColor = &H80FF& 'Reset the global variable to Orange
- ' Reset selected variables
- selectedWeather = vbNullString
- selectedHeight = vbNullString
- selectedVisibility = vbNullString
- selectedActivity = vbNullString
- selectedVocalization = vbNullString
- selectedItemFocal = vbNullString
- selectedItemDetail = vbNullString
- selectedJenisFocal = vbNullString
- selectedJenisLokasi = vbNullString
- focalCling = vbNullString
- ' Reset ListPmDistance values efficiently
- Dim key As Variant
- For Each key In ListPmDistance
- ListPmDistance(key) = vbNullString
- Next key
- ' Clear ComboBoxes and OptionButtons in one go
- ComboBoxHeight.Value = vbNullString
- ComboBoxVocalization.Value = vbNullString
- ComboBoxWeather.Value = vbNullString
- OptionButton0.Value = False
- OptionButton1.Value = False
- OptionButton2.Value = False
- OptionButtonObsBreak.Value = False
- ' Save workbook if necessary
- ThisWorkbook.Save
- Set wsActivity = Nothing
- ' Show success message
- MsgBox "Interval saved successfully! The current interval is now " & currentIntervalHour & ":" & currentIntervalMinute, vbInformation
- End Sub
- Private Sub CommandButtonNextIntervalSame_Click()
- Dim wsActivity As Worksheet
- Dim colIndexHour As Long, colIndexMinute As Long
- Dim oldRow As Long, destRow As Long
- Dim key As Variant
- ' Set worksheet reference
- Set wsActivity = ThisWorkbook.Sheets("Activity Data")
- ' Store the Hour and Minute columns' indexes in variables
- colIndexHour = 5
- colIndexMinute = 6
- ' Store row indices
- oldRow = currentIntervalRow - 1
- destRow = currentIntervalRow
- ' Copy only the desired continuous range (G to DI)
- wsActivity.Range("G" & oldRow & ":DI" & oldRow).Copy
- wsActivity.Range("G" & destRow).PasteSpecial Paste:=xlPasteValues
- ' Cleanup clipboard
- Application.CutCopyMode = False
- ' Update global variables
- currentIntervalRow = currentIntervalRow + 1
- currentIntervalHour = Format(wsActivity.Cells(currentIntervalRow, colIndexHour).Value, "00")
- currentIntervalMinute = Format(wsActivity.Cells(currentIntervalRow, colIndexMinute).Value, "00")
- ' Update label
- LabelCurrentInterval.Caption = currentIntervalHour & ":" & currentIntervalMinute
- ' Reset selected variables
- selectedWeather = vbNullString
- selectedHeight = vbNullString
- selectedVisibility = vbNullString
- selectedActivity = vbNullString
- selectedVocalization = vbNullString
- selectedItemFocal = vbNullString
- selectedItemDetail = vbNullString
- selectedJenisFocal = vbNullString
- selectedJenisLokasi = vbNullString
- focalCling = vbNullString
- ' Reset dictionary values
- For Each key In ListPmDistance.Keys
- ListPmDistance(key) = vbNullString
- Next key
- ' Reset colors for OptionButtons and Buttons
- OptionButton0.BackColor = &HC0C0C0
- OptionButton1.BackColor = &HC0C0C0
- OptionButton2.BackColor = &HC0C0C0
- OptionButtonObsBreak.BackColor = &HFFFFC0
- ActivityButton.BackColor = &H8000000D
- PartyMembersButton.BackColor = &H80FF&
- activityButtonColor = &H8000000D
- partyMembersButtonColor = &H80FF&
- ' Clear ComboBoxes and OptionButtons
- ComboBoxHeight.Value = vbNullString
- ComboBoxVocalization.Value = vbNullString
- ComboBoxWeather.Value = vbNullString
- OptionButton0.Value = False
- OptionButton1.Value = False
- OptionButton2.Value = False
- OptionButtonObsBreak.Value = False
- ' Save the workbook (so the observer does not have to do it manually, and we also do not overload the RAM of the tablet with unsaved data)
- ThisWorkbook.Save
- Set wsActivity = Nothing
- ' Show success message
- MsgBox "Interval saved successfully! The current interval is now " & currentIntervalHour & ":" & currentIntervalMinute, vbInformation
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement