Click button to increment/decrement a loop












0















To Explain What I need Input Parameters User form



I have defined the variables on my sheet.2 within text boxes, and on my VBA form (Sheet.1) I have a Plus command button and a Minus command Button, I want the loop to progress only when any of these buttons are clicked.



'**** Function to determine Layer ID of the Sources and define their Elevation and Rotation Angle



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









share|improve this question

























  • Not quite clear on what you mean. You have a UserForm named Sheet1 - not a Worksheet, but a form inserted within the VBE? And the loop you mean is the For Elevation = MinElevation To MaxElevation Step ElevationStep loop?

    – Darren Bartrup-Cook
    Nov 14 '18 at 12:08











  • I don't have a user form separately, my user form is on sheet.1 and the loop I want to run is elevation and rotation. for both the loop to increment or decrement I want my button to work. This macro is for controlling another piece of software which support macro control

    – Sundeep Srivastava
    Nov 14 '18 at 12:10













  • Ah ok, so it's a Worksheet made to look like a form.

    – Darren Bartrup-Cook
    Nov 14 '18 at 12:11






  • 2





    it is not clear what you mean by loop to progress by command button, if i am thinking of what you trying to achieve then may please think of simple possibility of using a spinner (may be linked to a cell) for and using spinner value as elevation.. The vba could be (with some modification) could be attached to cell change detected via Worksheet_Change event.

    – Ahmed AU
    Nov 14 '18 at 13:34













  • Hi Ahmed, Please see the attached images, maybe that helps clarify what I mean. if I run my code, it progresses with 10degree step, gives me the value of the elevation rotation and its layer ID. Since I am controlling the layer id of another software, I need a click function which makes the loop execute only once so that the layer id of other software can be controlled.

    – Sundeep Srivastava
    Nov 14 '18 at 13:53
















0















To Explain What I need Input Parameters User form



I have defined the variables on my sheet.2 within text boxes, and on my VBA form (Sheet.1) I have a Plus command button and a Minus command Button, I want the loop to progress only when any of these buttons are clicked.



'**** Function to determine Layer ID of the Sources and define their Elevation and Rotation Angle



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









share|improve this question

























  • Not quite clear on what you mean. You have a UserForm named Sheet1 - not a Worksheet, but a form inserted within the VBE? And the loop you mean is the For Elevation = MinElevation To MaxElevation Step ElevationStep loop?

    – Darren Bartrup-Cook
    Nov 14 '18 at 12:08











  • I don't have a user form separately, my user form is on sheet.1 and the loop I want to run is elevation and rotation. for both the loop to increment or decrement I want my button to work. This macro is for controlling another piece of software which support macro control

    – Sundeep Srivastava
    Nov 14 '18 at 12:10













  • Ah ok, so it's a Worksheet made to look like a form.

    – Darren Bartrup-Cook
    Nov 14 '18 at 12:11






  • 2





    it is not clear what you mean by loop to progress by command button, if i am thinking of what you trying to achieve then may please think of simple possibility of using a spinner (may be linked to a cell) for and using spinner value as elevation.. The vba could be (with some modification) could be attached to cell change detected via Worksheet_Change event.

    – Ahmed AU
    Nov 14 '18 at 13:34













  • Hi Ahmed, Please see the attached images, maybe that helps clarify what I mean. if I run my code, it progresses with 10degree step, gives me the value of the elevation rotation and its layer ID. Since I am controlling the layer id of another software, I need a click function which makes the loop execute only once so that the layer id of other software can be controlled.

    – Sundeep Srivastava
    Nov 14 '18 at 13:53














0












0








0








To Explain What I need Input Parameters User form



I have defined the variables on my sheet.2 within text boxes, and on my VBA form (Sheet.1) I have a Plus command button and a Minus command Button, I want the loop to progress only when any of these buttons are clicked.



'**** Function to determine Layer ID of the Sources and define their Elevation and Rotation Angle



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









share|improve this question
















To Explain What I need Input Parameters User form



I have defined the variables on my sheet.2 within text boxes, and on my VBA form (Sheet.1) I have a Plus command button and a Minus command Button, I want the loop to progress only when any of these buttons are clicked.



'**** Function to determine Layer ID of the Sources and define their Elevation and Rotation Angle



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






excel vba excel-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 11:51







Sundeep Srivastava

















asked Nov 14 '18 at 11:28









Sundeep SrivastavaSundeep Srivastava

12




12













  • Not quite clear on what you mean. You have a UserForm named Sheet1 - not a Worksheet, but a form inserted within the VBE? And the loop you mean is the For Elevation = MinElevation To MaxElevation Step ElevationStep loop?

    – Darren Bartrup-Cook
    Nov 14 '18 at 12:08











  • I don't have a user form separately, my user form is on sheet.1 and the loop I want to run is elevation and rotation. for both the loop to increment or decrement I want my button to work. This macro is for controlling another piece of software which support macro control

    – Sundeep Srivastava
    Nov 14 '18 at 12:10













  • Ah ok, so it's a Worksheet made to look like a form.

    – Darren Bartrup-Cook
    Nov 14 '18 at 12:11






  • 2





    it is not clear what you mean by loop to progress by command button, if i am thinking of what you trying to achieve then may please think of simple possibility of using a spinner (may be linked to a cell) for and using spinner value as elevation.. The vba could be (with some modification) could be attached to cell change detected via Worksheet_Change event.

    – Ahmed AU
    Nov 14 '18 at 13:34













  • Hi Ahmed, Please see the attached images, maybe that helps clarify what I mean. if I run my code, it progresses with 10degree step, gives me the value of the elevation rotation and its layer ID. Since I am controlling the layer id of another software, I need a click function which makes the loop execute only once so that the layer id of other software can be controlled.

    – Sundeep Srivastava
    Nov 14 '18 at 13:53



















  • Not quite clear on what you mean. You have a UserForm named Sheet1 - not a Worksheet, but a form inserted within the VBE? And the loop you mean is the For Elevation = MinElevation To MaxElevation Step ElevationStep loop?

    – Darren Bartrup-Cook
    Nov 14 '18 at 12:08











  • I don't have a user form separately, my user form is on sheet.1 and the loop I want to run is elevation and rotation. for both the loop to increment or decrement I want my button to work. This macro is for controlling another piece of software which support macro control

    – Sundeep Srivastava
    Nov 14 '18 at 12:10













  • Ah ok, so it's a Worksheet made to look like a form.

    – Darren Bartrup-Cook
    Nov 14 '18 at 12:11






  • 2





    it is not clear what you mean by loop to progress by command button, if i am thinking of what you trying to achieve then may please think of simple possibility of using a spinner (may be linked to a cell) for and using spinner value as elevation.. The vba could be (with some modification) could be attached to cell change detected via Worksheet_Change event.

    – Ahmed AU
    Nov 14 '18 at 13:34













  • Hi Ahmed, Please see the attached images, maybe that helps clarify what I mean. if I run my code, it progresses with 10degree step, gives me the value of the elevation rotation and its layer ID. Since I am controlling the layer id of another software, I need a click function which makes the loop execute only once so that the layer id of other software can be controlled.

    – Sundeep Srivastava
    Nov 14 '18 at 13:53

















Not quite clear on what you mean. You have a UserForm named Sheet1 - not a Worksheet, but a form inserted within the VBE? And the loop you mean is the For Elevation = MinElevation To MaxElevation Step ElevationStep loop?

– Darren Bartrup-Cook
Nov 14 '18 at 12:08





Not quite clear on what you mean. You have a UserForm named Sheet1 - not a Worksheet, but a form inserted within the VBE? And the loop you mean is the For Elevation = MinElevation To MaxElevation Step ElevationStep loop?

– Darren Bartrup-Cook
Nov 14 '18 at 12:08













I don't have a user form separately, my user form is on sheet.1 and the loop I want to run is elevation and rotation. for both the loop to increment or decrement I want my button to work. This macro is for controlling another piece of software which support macro control

– Sundeep Srivastava
Nov 14 '18 at 12:10







I don't have a user form separately, my user form is on sheet.1 and the loop I want to run is elevation and rotation. for both the loop to increment or decrement I want my button to work. This macro is for controlling another piece of software which support macro control

– Sundeep Srivastava
Nov 14 '18 at 12:10















Ah ok, so it's a Worksheet made to look like a form.

– Darren Bartrup-Cook
Nov 14 '18 at 12:11





Ah ok, so it's a Worksheet made to look like a form.

– Darren Bartrup-Cook
Nov 14 '18 at 12:11




2




2





it is not clear what you mean by loop to progress by command button, if i am thinking of what you trying to achieve then may please think of simple possibility of using a spinner (may be linked to a cell) for and using spinner value as elevation.. The vba could be (with some modification) could be attached to cell change detected via Worksheet_Change event.

– Ahmed AU
Nov 14 '18 at 13:34







it is not clear what you mean by loop to progress by command button, if i am thinking of what you trying to achieve then may please think of simple possibility of using a spinner (may be linked to a cell) for and using spinner value as elevation.. The vba could be (with some modification) could be attached to cell change detected via Worksheet_Change event.

– Ahmed AU
Nov 14 '18 at 13:34















Hi Ahmed, Please see the attached images, maybe that helps clarify what I mean. if I run my code, it progresses with 10degree step, gives me the value of the elevation rotation and its layer ID. Since I am controlling the layer id of another software, I need a click function which makes the loop execute only once so that the layer id of other software can be controlled.

– Sundeep Srivastava
Nov 14 '18 at 13:53





Hi Ahmed, Please see the attached images, maybe that helps clarify what I mean. if I run my code, it progresses with 10degree step, gives me the value of the elevation rotation and its layer ID. Since I am controlling the layer id of another software, I need a click function which makes the loop execute only once so that the layer id of other software can be controlled.

– Sundeep Srivastava
Nov 14 '18 at 13:53












1 Answer
1






active

oldest

votes


















0














What I could understand from the details




  1. There is no need to loop for manual operation and the layerNumber could be simply derived from the TextBox values (or directly from Cells) with the formula
    LayerNumber = ((Elevation - MinElevation) / ElevationStep) * NumberOfRotations + (Rotation - MinRotation) / RotationStep


  2. Rotation & Elevation Plus & Minus buttons (or spinners) could be used for increase or decrease Rotation & Elevation with the steps,Max, Min defined.


  3. Finally VR software could be called from any button click with the help of LayerID
    I tried it like this to generate LayerID according to already made buttons etc.



Buttons names, Sheet names etc may be changed according to your need. if my assumptions are not correct feel free to further describe your need.



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





share|improve this answer
























  • Please note that without explicitly specifying a data type (or object type) as e.g. in Dim ElevationStep, MinElevation, MaxElevation, Elevation As Integer, only the last variable Elevation is declared as Integer; all other variables will be treated as Variant by default! A consistent declaration is as follows: Dim ElevationStep As Integer, MinElevation As Integer, MaxElevation As Integer, Elevation As Integer :-)

    – T.M.
    Nov 16 '18 at 11:17











  • Thank very much Ahmed AU, this is very good, I just tried your code and with some minor tweaks, it is doing what it should do. Thanks a ton for your help.

    – Sundeep Srivastava
    Dec 10 '18 at 18:03













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299170%2fclick-button-to-increment-decrement-a-loop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














What I could understand from the details




  1. There is no need to loop for manual operation and the layerNumber could be simply derived from the TextBox values (or directly from Cells) with the formula
    LayerNumber = ((Elevation - MinElevation) / ElevationStep) * NumberOfRotations + (Rotation - MinRotation) / RotationStep


  2. Rotation & Elevation Plus & Minus buttons (or spinners) could be used for increase or decrease Rotation & Elevation with the steps,Max, Min defined.


  3. Finally VR software could be called from any button click with the help of LayerID
    I tried it like this to generate LayerID according to already made buttons etc.



Buttons names, Sheet names etc may be changed according to your need. if my assumptions are not correct feel free to further describe your need.



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





share|improve this answer
























  • Please note that without explicitly specifying a data type (or object type) as e.g. in Dim ElevationStep, MinElevation, MaxElevation, Elevation As Integer, only the last variable Elevation is declared as Integer; all other variables will be treated as Variant by default! A consistent declaration is as follows: Dim ElevationStep As Integer, MinElevation As Integer, MaxElevation As Integer, Elevation As Integer :-)

    – T.M.
    Nov 16 '18 at 11:17











  • Thank very much Ahmed AU, this is very good, I just tried your code and with some minor tweaks, it is doing what it should do. Thanks a ton for your help.

    – Sundeep Srivastava
    Dec 10 '18 at 18:03


















0














What I could understand from the details




  1. There is no need to loop for manual operation and the layerNumber could be simply derived from the TextBox values (or directly from Cells) with the formula
    LayerNumber = ((Elevation - MinElevation) / ElevationStep) * NumberOfRotations + (Rotation - MinRotation) / RotationStep


  2. Rotation & Elevation Plus & Minus buttons (or spinners) could be used for increase or decrease Rotation & Elevation with the steps,Max, Min defined.


  3. Finally VR software could be called from any button click with the help of LayerID
    I tried it like this to generate LayerID according to already made buttons etc.



Buttons names, Sheet names etc may be changed according to your need. if my assumptions are not correct feel free to further describe your need.



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





share|improve this answer
























  • Please note that without explicitly specifying a data type (or object type) as e.g. in Dim ElevationStep, MinElevation, MaxElevation, Elevation As Integer, only the last variable Elevation is declared as Integer; all other variables will be treated as Variant by default! A consistent declaration is as follows: Dim ElevationStep As Integer, MinElevation As Integer, MaxElevation As Integer, Elevation As Integer :-)

    – T.M.
    Nov 16 '18 at 11:17











  • Thank very much Ahmed AU, this is very good, I just tried your code and with some minor tweaks, it is doing what it should do. Thanks a ton for your help.

    – Sundeep Srivastava
    Dec 10 '18 at 18:03
















0












0








0







What I could understand from the details




  1. There is no need to loop for manual operation and the layerNumber could be simply derived from the TextBox values (or directly from Cells) with the formula
    LayerNumber = ((Elevation - MinElevation) / ElevationStep) * NumberOfRotations + (Rotation - MinRotation) / RotationStep


  2. Rotation & Elevation Plus & Minus buttons (or spinners) could be used for increase or decrease Rotation & Elevation with the steps,Max, Min defined.


  3. Finally VR software could be called from any button click with the help of LayerID
    I tried it like this to generate LayerID according to already made buttons etc.



Buttons names, Sheet names etc may be changed according to your need. if my assumptions are not correct feel free to further describe your need.



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





share|improve this answer













What I could understand from the details




  1. There is no need to loop for manual operation and the layerNumber could be simply derived from the TextBox values (or directly from Cells) with the formula
    LayerNumber = ((Elevation - MinElevation) / ElevationStep) * NumberOfRotations + (Rotation - MinRotation) / RotationStep


  2. Rotation & Elevation Plus & Minus buttons (or spinners) could be used for increase or decrease Rotation & Elevation with the steps,Max, Min defined.


  3. Finally VR software could be called from any button click with the help of LayerID
    I tried it like this to generate LayerID according to already made buttons etc.



Buttons names, Sheet names etc may be changed according to your need. if my assumptions are not correct feel free to further describe your need.



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






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 4:42









Ahmed AUAhmed AU

89528




89528













  • Please note that without explicitly specifying a data type (or object type) as e.g. in Dim ElevationStep, MinElevation, MaxElevation, Elevation As Integer, only the last variable Elevation is declared as Integer; all other variables will be treated as Variant by default! A consistent declaration is as follows: Dim ElevationStep As Integer, MinElevation As Integer, MaxElevation As Integer, Elevation As Integer :-)

    – T.M.
    Nov 16 '18 at 11:17











  • Thank very much Ahmed AU, this is very good, I just tried your code and with some minor tweaks, it is doing what it should do. Thanks a ton for your help.

    – Sundeep Srivastava
    Dec 10 '18 at 18:03





















  • Please note that without explicitly specifying a data type (or object type) as e.g. in Dim ElevationStep, MinElevation, MaxElevation, Elevation As Integer, only the last variable Elevation is declared as Integer; all other variables will be treated as Variant by default! A consistent declaration is as follows: Dim ElevationStep As Integer, MinElevation As Integer, MaxElevation As Integer, Elevation As Integer :-)

    – T.M.
    Nov 16 '18 at 11:17











  • Thank very much Ahmed AU, this is very good, I just tried your code and with some minor tweaks, it is doing what it should do. Thanks a ton for your help.

    – Sundeep Srivastava
    Dec 10 '18 at 18:03



















Please note that without explicitly specifying a data type (or object type) as e.g. in Dim ElevationStep, MinElevation, MaxElevation, Elevation As Integer, only the last variable Elevation is declared as Integer; all other variables will be treated as Variant by default! A consistent declaration is as follows: Dim ElevationStep As Integer, MinElevation As Integer, MaxElevation As Integer, Elevation As Integer :-)

– T.M.
Nov 16 '18 at 11:17





Please note that without explicitly specifying a data type (or object type) as e.g. in Dim ElevationStep, MinElevation, MaxElevation, Elevation As Integer, only the last variable Elevation is declared as Integer; all other variables will be treated as Variant by default! A consistent declaration is as follows: Dim ElevationStep As Integer, MinElevation As Integer, MaxElevation As Integer, Elevation As Integer :-)

– T.M.
Nov 16 '18 at 11:17













Thank very much Ahmed AU, this is very good, I just tried your code and with some minor tweaks, it is doing what it should do. Thanks a ton for your help.

– Sundeep Srivastava
Dec 10 '18 at 18:03







Thank very much Ahmed AU, this is very good, I just tried your code and with some minor tweaks, it is doing what it should do. Thanks a ton for your help.

– Sundeep Srivastava
Dec 10 '18 at 18:03






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299170%2fclick-button-to-increment-decrement-a-loop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values