Нажмите кнопку, чтобы увеличить / уменьшить цикл - PullRequest
0 голосов
/ 14 ноября 2018

Чтобы объяснить, что мне нужно Входные параметры Форма пользователя

Я определил переменные на своем листе 2 в текстовых полях, а в форме VBA (Лист 1) у меня есть кнопка «плюс» и кнопка «минус», я хочу, чтобы цикл выполнялся только тогда, когда любой из этих кнопки нажимаются.

'**** Функция для определения идентификатора слоя источников и определения их угла возвышения и поворота

Function LayerID()
Sheet2.NumberOfSunPositionsBox.Enabled = False
Sheet2.NumberOfSunPositionsBox.Enabled = False
Sheet1.AngleOfRotationBox.Enabled = False
Sheet1.AngleOfElevationBox.Enabled = False

Dim RotationStep, MinRotation, MaxRotation, ElevatioStep, MinElevation, MaxElevation As Integer

RotationStep = Sheet2.RotationStepBox
MinRotation = Sheet2.MinRotationlAngleBox
MaxRotation = Sheet2.MaxRotationAngleBox
ElevationStep = Sheet2.ElevationStepBox
MinElevation = Sheet2.MinElevationAngleBox
MaxElevation = Sheet2.MaxElevationAngleBox

NumberOfRotations = (MaxRotation - MinRotation) / RotationStep + 1
NumberOfElevations = (MaxElevation - MinElevation) / ElevationStep + 1
NumberOfSunPositions = NumberOfRotations * NumberOfElevations
    If MaxElevation = 90 Then
    NumberOfSunPositions = NumberOfSunPositions + 1
    End If

Sheet2.NumberOfSunPositionsBox = NumberOfSunPositions
Sheet1.AngleOfElevationBox = MinElevation
Sheet1.AngleOfRotationBox = MinRotation
'Power1 = 0
'Power2 = 100

    For Elevation = MinElevation To MaxElevation Step ElevationStep
'        If Sheet1.ElevationPlusButton Then
           If LayerNumber <= NumberOfSunPositions Then
           Sheet1.ElevationPlusButton.Enabled = True
                    If Elevation = 90 Then
                    Rotation = 0
                    LayerNumber = LayerNumber + 1
                    Debug.Print ("Layer ID:" & LayerNumber & " E:" & Elevation & " R:" & Rotation)
                    Sheet1.AngleOfElevationBox = Elevation
                    Else
                        For Rotation = MinRotation To MaxRotation Step RotationStep
'                        If Sheet1.RotationPlusButton Then
'                            Sheet1.RotationPlusButton.enable = True
                            LayerNumber = LayerNumber + 1
                            Debug.Print ("Layer ID:" & LayerNumber & " E:" & Elevation & " R:" & Rotation)
                            Sheet1.AngleOfRotationBox = Rotation
'                        End If
                        Next Rotation
                    End If
            End If
'        End If
    Next Elevation
End Function

1 Ответ

0 голосов
/ 16 ноября 2018

Что я мог понять из деталей

  1. Нет необходимости в цикле для ручного управления, и layerNumber может быть просто получено из значений TextBox (или непосредственно из ячеек) с формулой LayerNumber = ((Elevation - MinElevation) / ElevationStep) * NumberOfRotations + (Rotation - MinRotation) / RotationStep

  2. Кнопки «Вращение» и «Высота» Плюс и Минус (или счетчики) можно использовать для увеличения или уменьшения значения «Вращение и высота» с шагами, определенными как Макс., Мин.

  3. Наконец, программное обеспечение VR можно вызвать с любого нажатия кнопки с помощью LayerID Я попробовал вот так, чтобы сгенерировать LayerID по уже сделанным кнопкам и т. Д.

Названия кнопок, имена листов и т. Д. Могут быть изменены в соответствии с вашими потребностями. если мои предположения не верны, не стесняйтесь, чтобы описать ваши потребности.

Option Explicit
Private Sub ElvMinus_Click()
Dim ElevationStep, MinElevation, MaxElevation, Elevation As Integer
ElevationStep = Val(Sheet2.ElevationStepBox.Text)
MinElevation = Val(Sheet2.MinElevationAngleBox.Text)
MaxElevation = Val(Sheet2.MaxElevationAngleBox.Text)
Elevation = Val(Sheet2.AngleOfElevationBox.Text)
Elevation = Elevation - ElevationStep
Elevation = IIf(Elevation < MinElevation, MinElevation, Elevation)
Sheet2.AngleOfElevationBox.Text = Elevation
GetLayerID
End Sub
Private Sub ElvPlus_Click()
Dim ElevationStep, MinElevation, MaxElevation, Elevation As Integer
ElevationStep = Val(Sheet2.ElevationStepBox.Text)
MinElevation = Val(Sheet2.MinElevationAngleBox.Text)
MaxElevation = Val(Sheet2.MaxElevationAngleBox.Text)
Elevation = Val(Sheet2.AngleOfElevationBox.Text)
Elevation = Elevation + ElevationStep
Elevation = IIf(Elevation > MaxElevation, MaxElevation, Elevation)
Sheet2.AngleOfElevationBox.Text = Elevation
GetLayerID
End Sub
Private Sub RotMinus_Click()
Dim RotationStep, MinRotation, MaxRotation, Rotation As Integer
RotationStep = Val(Sheet2.RotationStepBox.Text)
MinRotation = Val(Sheet2.MinRotationAngleBox.Text)
MaxRotation = Val(Sheet2.MaxRotationAngleBox.Text)
Rotation = Val(Sheet2.AngleOfRotationBox.Text)
Rotation = Rotation - RotationStep
Rotation = IIf(Rotation < MinRotation, MinRotation, Rotation)
Sheet2.AngleOfRotationBox.Text = Rotation
GetLayerID
End Sub
Private Sub RotPlus_Click()
Dim RotationStep, MinRotation, MaxRotation, Rotation As Integer
RotationStep = Val(Sheet2.RotationStepBox.Text)
MinRotation = Val(Sheet2.MinRotationAngleBox.Text)
MaxRotation = Val(Sheet2.MaxRotationAngleBox.Text)
Rotation = Val(Sheet2.AngleOfRotationBox.Text)
Rotation = Rotation + RotationStep
Rotation = IIf(Rotation > MaxRotation, MaxRotation, Rotation)
Sheet2.AngleOfRotationBox.Text = Rotation
GetLayerID
End Sub
Private Sub GetLayerID()
Dim RotationStep, ElevationStep, MinRotation, MaxRotation, ElevatioStep, MinElevation, MaxElevation As Integer
Dim NumberOfRotations, NumberOfElevations, NumberOfSunPositions As Integer
Dim Elevation, Rotation, layerNumber As Integer
RotationStep = Val(Sheet2.RotationStepBox.Text)
MinRotation = Val(Sheet2.MinRotationAngleBox.Text)
MaxRotation = Val(Sheet2.MaxRotationAngleBox.Text)
ElevationStep = Val(Sheet2.ElevationStepBox.Text)
MinElevation = Val(Sheet2.MinElevationAngleBox.Text)
MaxElevation = Val(Sheet2.MaxElevationAngleBox.Text)

NumberOfRotations = (MaxRotation - MinRotation) / RotationStep + 1
NumberOfElevations = (MaxElevation - MinElevation) / ElevationStep + 1
NumberOfSunPositions = NumberOfRotations * NumberOfElevations
Sheet2.NumberOfSunPositionsBox.Text = NumberOfSunPositions

Elevation = Val(Sheet2.AngleOfElevationBox.Text)
Rotation = Val(Sheet2.AngleOfRotationBox.Text)
layerNumber = ((Elevation - MinElevation) / ElevationStep) * NumberOfRotations + (Rotation - MinRotation) / RotationStep
Sheet2.layerNumber.Text = layerNumber
' Here call to VR  Software
End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...