To Explain What I need Input Parameters User form
我已经在文本框中的sheet.2上定义了变量,并且在我的VBA表单(Sheet.1)上定义了一个加号命令按钮和一个减号命令按钮,我希望循环仅在以下任何一种情况下才能进行单击按钮。
'****确定源的图层ID并定义其高程和旋转角度的功能
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
答案 0 :(得分:0)
我可以从细节中了解到什么
无需循环进行手动操作,layerNumber
可以简单地从TextBox
值(或直接从Cells)中导出,并具有以下公式:
LayerNumber = ((Elevation - MinElevation) / ElevationStep) * NumberOfRotations + (Rotation - MinRotation) / RotationStep
“旋转和高程”加号和“减号”按钮(或微调器)可用于按照定义的最大,最小步长来增加或减少“旋转和高程”。
最终,可以在LayerID
的帮助下通过单击任意按钮来调用VR软件
我试过像这样,根据已经制作好的按钮等生成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