byref

VBA What's the underlying difference between call Sub or Function with or without parentheses

淺唱寂寞╮ 提交于 2019-11-29 23:39:22
问题 I had an issue with passing an Array to a Sub By Reference, but the Array actually not get modified. I managed to fix that , but I want to know why. Here is the example. Private Function fCountArray(ByRef arrayVar As Variant) arrayVar(0) = 333 End Function Sub Test1() Dim changedArr As Variant Dim notChangedArr As Variant ' create 2 quick array changedArr = Array(1, 2, 33, 56, 76, 89, 10) notChangedArr = Array(1, 2, 33, 56, 76, 89, 10) 'intest = Array(3, 1, 2) fCountArray (notChangedArr)

'ByRef' parameter '<parametername>' cannot be used in a lambda expression

元气小坏坏 提交于 2019-11-29 16:25:38
I'm using SharpZipLib to compress files. The library is wrapped in a plugin interface, in a separate DLL. I pass the plugin dll a ByRef parameter to keep track of the compression progress. SharpZipLib, while compressing, will periodically call a delegate sub passed when launching the compression. I can't figure out how to update the ByRef parameter when the delegate is called. If I try to assign the ByRef variable in the body of a lamba expression, I get a 'ByRef' parameter '<parametername>' cannot be used in a lambda expression error. Here's my code: Using InputFile As New IO.FileStream

Best Practice: ByRef or ByVal? in .Net

北慕城南 提交于 2019-11-29 11:19:10
问题 What are the things to consider when choosing between ByRef and ByVal. I understand the difference between the two but I don't fully understand if ByRef saves resources or if we even need to worry about that in the .Net environment. How do you decide between the two if the functionality doesn't matter in a situation? 回答1: There's a lot of misinformation around about this. The main thing is that you understand the difference between value types and reference types, and the difference between

F# member constraints + ^a byref parameters

拟墨画扇 提交于 2019-11-29 06:55:30
After some playing around F# member constraints feature and writing function like this: let inline parse< ^a when ^a : (static member Parse: string -> ^a) > s = (^a: (static member Parse: string -> ^a) s) That works perfectly fine: let xs = [ "123"; "456"; "999" ] |> List.map parse<int> I'm trying to write other func tryParse , that uses static method TryParse and wraps the parse result into 'a option type for better support in F#. Something like this doesn't compiles: let inline tryParse s = let mutable x = Unchecked.defaultof< ^a> if (^a: (static member TryParse: string * ^a byref -> bool)

VBA - Returning array from Property Get

不羁的心 提交于 2019-11-27 20:44:38
If arrays are returned by reference, why doesn't the following work: 'Class1 class module Private v() As Double Public Property Get Vec() As Double() Vec = v() End Property Private Sub Class_Initialize() ReDim v(0 To 3) End Sub ' end class module Sub Test1() Dim c As Class1 Set c = New Class1 Debug.Print c.Vec()(1) ' prints 0 as expected c.Vec()(1) = 5.6 Debug.Print c.Vec()(1) ' still prints 0 End Sub In VBA, arrays are never returned by reference unless they are returned through a ByRef parameter. Furthermore, whenever you use = to assign an array to a variable, you've made a new copy of the

Understanding byref, ref and &

浪子不回头ぞ 提交于 2019-11-27 19:45:30
Well, I came to understand that F# is able to manage references (some sort of C++ like references). This enables the possibilities to change value of parameters passed in functions and also enables the programmer to return more than a single value. However here's what I need to know: Ref keyword: The keyword ref is used to create, from a value, a reference to that value of the inferred type. So let myref = ref 10 This means that F# will create an object of type Ref<int> putting there (in the mutable field) my int 10 . OK. So I assume that ref is used to create instances of the Ref<'a> type. Is

Doesn't C# Extension Methods allow passing parameters by reference?

♀尐吖头ヾ 提交于 2019-11-27 14:58:51
Is it really impossible to create an extension method in C# where the instance is passed as a reference? Here’s a sample VB.NET console app: Imports System.Runtime.CompilerServices Module Module1 Sub Main() Dim workDays As Weekdays workDays.Add(Weekdays.Monday) workDays.Add(Weekdays.Tuesday) Console.WriteLine("Tuesday is a workday: {0}", _ CBool(workDays And Weekdays.Tuesday)) Console.ReadKey() End Sub End Module <Flags()> _ Public Enum Weekdays Monday = 1 Tuesday = 2 Wednesday = 4 Thursday = 8 Friday = 16 Saturday = 32 Sunday = 64 End Enum Module Ext <Extension()> _ Public Sub Add(ByRef Value

Why is it not necessary to indicate ByVal/ByRef anymore?

不问归期 提交于 2019-11-27 13:53:49
I just installed Visual Studio 2010 Service pack (proposed on Windows Update), and I can see a new feature on the "intellisense" that means when I write a Function or Sub in VB.NET it doesn't auto-complete parameters with ByRef or ByVal ... 1) Is there anyway that I can configure this option back to how it was before? 2) If I don't specify ByX , which one is used by default? (it seems like it is always ByRef ) Jay Tim covered what you asked directly, but something else to keep in mind is that any reference type variable, like a user defined class even if passed by value will allow you to make

Which is faster? ByVal or ByRef?

限于喜欢 提交于 2019-11-27 11:34:09
In VB.NET, which is faster to use for method arguments, ByVal or ByRef ? Also, which consumes more resources at runtime (RAM)? I read through this question , but the answers are not applicable or specific enough. user50612 Byval and ByRef arguments should be used based on requirements and knowledge of how they work not on speed. http://www.developer.com/net/vb/article.php/3669066 In response to a comment by Slough - Which consumes more resources at runtime? Parameters are passed on the stack. The stack is very fast, because its memory allocation is simply a pointer increment to reserve a new

Understanding byref, ref and &

我只是一个虾纸丫 提交于 2019-11-26 19:58:48
问题 Well, I came to understand that F# is able to manage references (some sort of C++ like references). This enables the possibilities to change value of parameters passed in functions and also enables the programmer to return more than a single value. However here's what I need to know: Ref keyword: The keyword ref is used to create, from a value, a reference to that value of the inferred type. So let myref = ref 10 This means that F# will create an object of type Ref<int> putting there (in the