Questions tagged [byval]
66 questions
2
votes
2 answers
In .NET if you pass a struct into a method with an interface parameter does it box the value?
From a simple test I can see that if you pass the struct into the method it is passed by value but if you first assign it to an interface it is passed by reference.
interface IFoo { int Val { get; set; } }
struct Foo : IFoo { public int Val { get;…

justin.m.chase
- 13,061
- 8
- 52
- 100
2
votes
1 answer
Run Macro Based On Worksheet Change (Cell Contains Formula)
I think I have a fairly reasonable/standard ask and the methods I've tried thus far have proved unsuccessful.
I'm running Excel 2013 32-Bit and in Sheet 6 in Cell J7 I have a third-party formula that changes every so often. Basically I'd like to…

user979226
- 47
- 2
- 11
2
votes
1 answer
vbval vs public variable
In VBA, I generally define shared variables as Public as opposed to building references via byVal or byRef. Most commonly, I call a subroutine or function to establish a value for said variable. Will someone please explain to me the benefit of…

Nathan Green
- 93
- 6
2
votes
1 answer
converting vb.net to c#- optimise parameter passing
I want to move a vb.net app to c#. The vb.net app has thousands of byref parameters that should be byval. Does anybody know a way to automate checking whether each parameter passing approach can be safely changed?

daniel
- 289
- 1
- 3
- 4
1
vote
3 answers
VB.Net, EventArgs, ByRef and ByVal
In VB.Net, I have an object named WorkflowButtonEventArgs that inherits from System.EventArgs.
The WorkflowButtonEventArgs class contains two ByRef Properties. These are objects that are in memory, and I do not want them duplicated or copied in any…

user1100622
- 11
- 1
1
vote
1 answer
byval vs byref when passing object
I want to check if a worksheet with particular name is exist, so I generate shtexist function below.
However, for the second parameter in shtexist. When I pass it byref at first, shtexist(name,thisworkbook) goes well while shtexist(name,rwb) does…

victor
- 13
- 2
1
vote
2 answers
ByVal/ByRef to copy data [VBA]
[Answer found -
Problem wasn't with the Sourcerange. Apparently it's because I didn't indicate ".xlsx" within Extractdata1 for each of the inputWBs. Somehow, that led to the code churning out the same value for each output cell. After adding .xlsx…

rainbowtox
- 35
- 5
1
vote
2 answers
How do I use Change(byVal Target as Range) to check/change cell color
My primary data entry is a Worksheet named "Master". I want to check in Range A2:A1000 when a word is entered. If it is "CBI", "Fire", "InCase" or "LEA" nothing needs to happen in Column I (Offset(0, 8)) as it already has a no-fill…

LawGuy
- 65
- 6
1
vote
1 answer
Does long support decimals?
I was trying to make sense of ByVal and ByRef and passing arguments from long to double using the ByVal keyword.
I noticed that VBA gave me the incorrect answer for the value of y squared. It does work when y (i in my sub) is a whole number.
In the…

NeilF
- 13
- 3
1
vote
1 answer
Change cell colour where vba has changed the value VBA
I am new to VBA so please bear with me if I sound stupid-
Background info:
I am trying to automate a workbook that we update every quarter- I want to show which cells are changed by my VBA script by changing the background colour of those cells, so…

CHsu
- 17
- 6
1
vote
1 answer
C++ Templates ByRef vs. ByVal
I'm following an online course (Pluralsight.com) in C++ and struggling with an exercise on templates, in particular passing an actual number (e.g. 3) to a template which expects (T& t).
The code written by the instructor will not compile on my PC -…

David258
- 697
- 2
- 6
- 15
1
vote
0 answers
UIAutomationClient elementFromPoint With VBA error "User-Defined type may not be passed ByVal"
Is there a way to use ElementfromPoint from UIAutomationClient with VBA (EXCEL)
I have always an compilation error :
"User-Defined type may not be passed ByVal"
Sub Test_ElementFromPoint()
Dim uiAuto As New UIAutomationClient.CUIAutomation8
Dim…

Oliv
- 11
- 3
1
vote
3 answers
Pass anonymous function by value in javascript?
I have a function that accepts an anonymous function as an argument and sets it to a variable (scoped) for reference. I then try to execute another function with that reference but it obviously fails since that function is out of scope.
I was…

Jean-Charles
- 366
- 2
- 11
1
vote
3 answers
Using ParamArray ByRef
Is there any way to use ParamArray ByRef? Barring that, it there a workaround that accomplishes the same thing?
I could do some overloads, but I am trying to avoid the clunkiness.
Background: Porting over some old code, and trying to keep the same…

Connor Albright
- 723
- 4
- 13
- 29
1
vote
1 answer
Difference between ByVal sender as object.... and Sender as object
I'm completely new to coding, and have been trying do a lot of at home research. I'm currently using VB 2012 and have noticed that on a lot of forums people have
(ByVal Sender as Object,... present when I load up a button or form, my code…

Jeremy Miranda
- 11
- 3