PDA

View Full Version : Haven't encountered this before, what does it mean?



MarkInHousto
12-09-2022, 12:09 PM
Trying to modify someone else's code:

Set ReturnArray = Application.InputBox("Select an area consisting of 3-rows and " & n3 - (n3 = 1) & _
" columns" & Chr(13) & "to report results.",

I don't get the n3 - (n3=1) part. What is it doing?

Thanks!

Grade4.2
12-09-2022, 06:50 PM
This line of code could be asking the user to select an area consisting of 3 rows and n3-1 columns. n3 could be a variable that is defined elsewhere in the code and is likely the number of columns in the area that the user is selecting. The (n3=1) part might be a condition which, if true, will subtract 1 from the number of columns and display it as the second part of the prompt.

MarkInHousto
12-09-2022, 07:40 PM
This line of code could be asking the user to select an area consisting of 3 rows and n3-1 columns. n3 could be a variable that is defined elsewhere in the code and is likely the number of columns in the area that the user is selecting. The (n3=1) part might be a condition which, if true, will subtract 1 from the number of columns and display it as the second part of the prompt.

The (n3=1) subtracting one if n3=1 makes perfect sense from what the code is trying to do.

I haven't found this putting an equation inside parentheses documented anywhere. Where can I read up on it?

Thanks!

Paul_Hossler
12-10-2022, 08:54 AM
I haven't found this putting an equation inside parentheses documented anywhere. Where can I read up on it?

Thanks!

Not much to read up on


Sub demo() Dim n3 As Long

n3 = 1

MsgBox n3 ' 1
MsgBox n3 = 1 ' True
MsgBox CLng(n3 = 1) ' -1
MsgBox CLng(True) ' -1
MsgBox n3 - (n3 = 1) ' 2
End Sub

Aussiebear
12-10-2022, 01:08 PM
So why not simply write



Set ReturnArray = Application.InputBox("Select an area consisting of 3-rows and " & 2 & _
" columns" & Chr(13) & "to report results."

rather than


Set ReturnArray = Application.InputBox("Select an area consisting of 3-rows and " & n3 - (n3 = 1) & _
" columns" & Chr(13) & "to report results.",

SamT
12-10-2022, 04:32 PM
Presumably, the value of n3 is not hard coded by the programmer