|
Hello !
But I'm speaking about passing as argument a button , a checkbox , a BindingSource and a entity.
What about memory consuming , because Byref is passing only a pointer ? ( Or I'm wrong ?)
Thank you !
|
|
|
|
|
dilkonika wrote: Byref is passing only a pointer
It passes the reference by value.
|
|
|
|
|
Ok , let's get only a case :
Passing a bindingsource as Value or as reference , both are consuming the same memory or ?????
thank you !
|
|
|
|
|
In your example, both are passing a pointer to the BindingSource. In the case of a ByRef, your passing the pointer to the object. By passing a reference type ByVal, you're passing a copy of the pointer. Both will allow you to call methods and make changes to properties in the original object. But, ByRef will allow you to replace the original object with a new one. Passing a reference type ByVal will not.
For value types, if you pass them ByVal you are passing a copy of the value. Changing the variable in the called method does nothing to the original passed in value.
If you pass in a value type ByRef, you're passing in a pointer to the value. Any change to the variable containing the value will change the original value in the calling code.
Where you run into a performance hit, albeit as very small one, is when you pass a large structure by value. Each value type in the structure, when passed ByVal, is copied and passed to the target method. For those types, it's probably better to pass a structure ByRef.
Read this[^].
|
|
|
|
|
PIEBALDconsult wrote: Performance is not a reason to choose between those options. Sure it is. What if you are passing huge objects?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Doesn't matter. Use the right tool. If ByVal works, use it.
|
|
|
|
|
Ok , but at least , can someone give me a response for this question :
Passing a bindingsource as Value or as reference , both are consuming the same memory or ?????
Thank you !
|
|
|
|
|
If your bindingsource is a class (and it probably is) then you're passing a reference byval or byref, so it works out to the same thing.
|
|
|
|
|
I'm not sure what Pieb's going on about, but byref obviously just passes a reference, not a copy of the object. Therefore, if the object is big, byref will be faster.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Pieb is right in that one should use Byval most of the time and only use Byref sparingly, if at all.
I personally do not feel that performance is that much of an issue between the two.
And yes, Byref is passing a reference pointer back to the original variable. Whereas Byval is just passing the value to the called function/routine.
I recommend to use Byref sparingly because if, in the called subroutine, you change the value of the passed variable, what you are actually doing is changing the value in the original variable that you made your call with. See example:
Public sub TryThis
dim X as String
dim Y as String
dim Z as String
X = "Red"
Y = "Green"
Z = "Yellow"
Z = TestFunction(x,y)
debug.print x
debug.print y
debug.print z
end sub
======
Public Function TestFunction(byval Value1 as string, Byref Value2 as string) as string
Value1 = "White"
Value2 = "Blue"
Return Value1
End Function
Results: X = "Red"
Y = "Blue"
Z = "White"
Notice that the value of Y changed even though it was not referenced or accessible by name in the function. This is because Y was represented in the function as Value2 and was passed Byref. The value of X was passed ByVal and did not change even though Value1 was also changed in the function. One should be careful using Byref for this reason. ByVal should be the preferred option in most all cases.
Any time I code a Byref, I always make it clearly known in a comment at every call what is being passed byref and if any value is being returned using the byref variable.
|
|
|
|
|
dbitsch wrote: Pieb is right in that one should use Byval most of the time and only use Byref sparingly, I rarely use ByRef but never heard anyone say it should almost never be used.
dbitsch wrote: because if, in the called subroutine, you change the value of the passed variable, what you are actually doing is changing the value in the original variable that you made your call with. Yes, that IS the definition of ByRef and the reason you would use it.
I had a case years ago where I was passing an object byval, which is the default, to a function that was called repeatedly thousands of times. It turns out ByRef worked much better.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Not quite.
ByVal will NOT make a copy of a reference type. Both ByVal and ByRef will pass a pointer to the object.
The difference is that passing a reference type ByVal makes a copy of the POINTER, not the object.
What's the difference? Passing a reference type ByRef will allow the called method to replace the original object with a new one. Passing a reference type ByVal will not.
|
|
|
|
|
Yes! Neither is making a copy of the original object. ByRef and ByVal both pass a pointer to the object.
|
|
|
|
|
I have a MS Access Database that has 2 tables (for this example)
Table_1 has a Filed named [ID] which is the Primary Key
Table 2 has a field name [tbl1ID]
I want to Create a relationship between Table_2 and Table_1
I tried:
"ALTER TABLE Table_2 ADD CONSTRAINT [tbl1ID] FOREIGN KEY (MyNewID) REFERENCES [Table_1](ID)"
I get the error "Can Not Find Table Or Constraint"
I know Table_1 and Table_2 exists and I know ID is a filed in Table_1 and I know tbl1ID is in Table_2
So can anyone tell me where I went wrong?
|
|
|
|
|
Not sure, but are tbl1ID and MyNewID in the wrong order?
|
|
|
|
|
Well I flip them per your suggestion and I still Get the same error.
|
|
|
|
|
Well It Looks like I had a typo after-all. I had a space in the sable name where it should have been an Underscore.
Thanks.
|
|
|
|
|
I connect them by using a select query. Access is all about tables, querys and records
|
|
|
|
|
Good Evening,
I would like to make a progressBar - (Visual Basic Express 2010) vb - connect his PC, for example, the Lego Mindstorm bluetooth.
I click on the "connect" the progressBar should be filled completely, then subsequently a label is displayed by marking "Connected"; if you click on the button "disconnect" the ProgressBar empties completely the label is displayed by marking "disconnected".
While the progressbar fills or empties there must be a connection or disconnection between the PC and the Lego Mindstorm (here).
And displayed directly in the label1 "connected" or "disconnected".
Thank you in advance, I will be very grateful to you.
I'm sorry for details, and expressions that I used.
I hope you understood what I mean.
Best Regards,
William
P.S: This is extremely urgent !!
Thank you to contact me asap for more detail.
|
|
|
|
|
Member 11380762 wrote: P.S: This is extremely urgent !! To you, yes, not to me. We're volunteers, and I can even choose to ignore the post completely. I would not even be rushed if you were paying.
As for the question, it needs more detail. If connecting consists of a few measurable steps, with the Lego giving you feedback on how connected it is, then yes, you can have a meaningful progressbar.
I'll bet you a banana that it doesn't. In that case you start with an "indeterminate" state, and measure how long it takes. On next startup, take that value as the max and measure again, and adjust the current max. Make it an average for better results.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Member 11380762 wrote: P.S: This is extremely urgent !! Sorry, not to anyone here.
|
|
|
|
|
Hi there,
For some functionality, I'm thinking about developing a custom control. It would be a kind of mini pnnel containing a few basic controls.
On my form, I would then have to create a panel displaying something liek a listbox, but instead of display text, it should be displaying instances of my custom control. When they don't fit in the panel, there should be a vertical scroll bar appearing.
I also need drag & drop functionality. This means I will need to somehow catch per control if a certain other control is dropped on it (like in a TreeView).
Does anyone have any idea about how to get this done? What container control is best to use in this case and how do I use it?
Thanks in advance!
|
|
|
|
|
Bart Van Eyndhoven wrote: Does anyone have any idea about how to get this done?
Derive a new class from UserControl. Add your controls in the UI designer. Develop your code in the source editor. Voila!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Instead of a UserControl, I'd use a Panel. That's the only difference.
Bart Van Eyndhoven wrote: When they don't fit in the panel, there should be a vertical scroll bar appearing. AutoScroll[^].
Bart Van Eyndhoven wrote: I also need drag & drop functionality. This means I will need to somehow
catch per control if a certain other control is dropped on it (like in a
TreeView). There's a HOWTO on MSDN, a walkthrough and various examples.
Bart Van Eyndhoven wrote: Does anyone have any idea about how to get this done? MSDN[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I'm new to VB2013 and am looking to generate a small app that will read SNMP data from a device and log it to a file. I came accross this nice little tool An introduction to #SNMP, an Open Source SNMP implementation[^]
It has some small examples but they all seem to have been written for 2008 or older. Does anyone have a newer example of how to use this (assume I needs to do everything) or some other way to perform SNMP GET and Even SET (later task)?
Thanks!
|
|
|
|