|
Hi everybody,
i have a "little" problem with this function in my class:
Public bPayLoad() As Byte
Public lCount As Integer
Public Sub New(ByVal b_PayLoad() As Byte)
bPayLoad = b_PayLoad
If Not (b_PayLoad Is Nothing) Then
lCount = bPayLoad.Length
Else
lCount = 0
End If
End Sub
If I create a new object of this class and pass the ByteArray B() to it why does the objects bytearray change when i change B()?
thanks for your help and sorry for my bad english
|
|
|
|
|
Because the array is an object. You are passing a reference to the array by value, that only means that the reference is copied, not that the object is copied.
If you want a copy of the array, you have to create a new array and copy the data to it.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hello,
Maybe a stupid question.
Is there a possibility to change the shape of a command button from rectangle to a circle (round button)
If yes, is it standard or do i have to add something 3th party
If it is not possible in VB 2005 is it posible in VB 2008 ?
Thanks
DCA
|
|
|
|
|
|
If I have a method which writes to a byref parameter without reading it first, is there any way I can indicate that the compiler shouldn't warn about uninitialized variables being passed to it? I'd expect it's probably something simple, but I searched and couldn't find it.
|
|
|
|
|
Depending on which VB you are using:
VS2008: Go to project properties, under the compile tab you should see a list of warning configurations. Change them to how you see fit.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
I'm using vb2005. I don't want to disable the warning globally. I merely want to indicate that in certain particular instances a certain parameter should be considered 'output only'.
|
|
|
|
|
I am not sure if the changes made in the project properties will become global defaults or not. You can always try.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
Try using Out instead of ByRef .
From this page[^]:
Output parameters are very similar to reference parameters. The only differences are:
The variable specified on the invocation doesn't need to have been assigned a value
before it is passed to the function member. If the function member completes normally,
the variable is considered to be assigned afterwards (so you can then "read" it).
|
|
|
|
|
VB doesn't have an 'out' keyword like C#, but you can use an attribute:
e.g.,
Public Sub Test(<System.Runtime.InteropServices.Out()> ByRef i As Integer)
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
VB & C# to Java Converter
Java to VB & C# Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB, C#, or Java to C++/CLI
|
|
|
|
|
Oh! Thanks, I wasn't aware of that.
|
|
|
|
|
I currently have a report which contains both detail values and subtotal values. What I am trying to do is find the minimum values for the subtotal value. It works fine if I want to find the minimum of a detail value, but when I try to do it for the subtotal value, the Formula editor returns a "This field cannot be summarized." error message.
The formula is: Minimum ({@subMaxFlavorPct})
|
|
|
|
|
I want to add a string to the beginning of my array and still keep the existing strings in the array.
I'm thinking it has something to do with moving the existing items down.
Can anyone help me with this?
|
|
|
|
|
You could move all the items in the array down one by one, but performance-wise that's probably not the best way. You could reverse[^] the array, add the new item, and then reverse the array again, which, depending upon arrays are implemented in .Net, may or may not provide any better performance.
If top performance is a priority, use a linked list[^] or Data Structures : Part 1 - Singly Linked Lists[^][^].
|
|
|
|
|
Hi,
an array can't do that without a performance hit, since all its data has to be moved.
That is exactly why they invented all those other fancy data structures, such as linked lists.
Now linked lists may be too expensive for your needs (depends on how often you want to prefix something
to a loaded array). If only seldom, I would suggest a linked list of arrays, i.e. each node in the
linked list contains an array. So you would start off with a single node containing the original array,
then prefix one node with the one new data item in a single-element array.
Of course, whatever you choose, if it is not an array, then you may not get some of the nice features
an array offers, such as fast indexing, automatic sorting, reversing, etc.
|
|
|
|
|
You can't add anything to an array, as it can't be resized. You would have to create a new array and copy all the data from the current array.
For a collection with a dynamic size, you should use something like a List(Of String) instead. Although you can insert an item at the beginning of a list, you should consider adding it at the end of the list intead, as that doesn't mean that every item in the list has to be moved. Which end of a list is which, only depends on how you look on it. You can just as easily loop from the last item to the first, in which case the last added items comes first.
Perhaps even a Queue(Of String) would be better for what you are doing.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Just a quick note - an array can be resized )
dim Arr(10) as string
redim Arr(100) (works, clearing array first)
redim preserve arr(100) works, preserving data...
However, I agree a list would be a better choice. You can always dump it back to an array using the .ToArray function of the variable:
dim L as list(of string)
<blah code="" filly="" stringy="" list="">
dim Arr() as string=l.ToArray.
Mind you, I guess this would take quite a hefty performance hit if doing it too often.
|
|
|
|
|
I'm pretty sure you'll find that redim creates a new array and (optionally) copies the old data in. Logically an array can't be increased if it's packed amongst other stuff in memory without moving it anyway.
|
|
|
|
|
Jasey9 wrote: Just a quick note - an array can be resized [Red faced] )
dim Arr(10) as string
redim Arr(100) (works, clearing array first)
redim preserve arr(100) works, preserving data...
No, it can't be resized. The ReDim Preserve command creates a new array and copies the data from the original array to it.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Yep. That is how VB resizes an array. I never said it was efficient. I was responding to the statement saying you can’t resize an array. The original statement inferred it was a manual job to copy data from one array to another.
However, from a runtime point of view, the array has been resized. It is not be the most efficient thing to do (well, it may be more efficient on small arrays, but then I am possibly overcomplicating things ), But the end result of a redim will be to have changed the upper bound of the array. I would never use this sort of "feature" in a loop with lots of elements in the array, but for an occasional hit, especially if the rest of the app written is geared towards arrays, then I would say it is appropriate.
I did, however suggest that a list would be more efficient... It was just the word "CANT" I didnt like to see
|
|
|
|
|
Jasey9 wrote: I was responding to the statement saying you can’t resize an array
You can't. Array's dimensions are immutable. Creating a new array and copying the data is NOT resizing an existing array. It's mearly creating a new one using a very expensive process. This is not an ability unique to VB since it can be done in just about any language. The only advantage VB has over some other languages is that it's built into the VB runtime and it supply syntactic sugar to relieve you the stress of coding this little function yourself.
|
|
|
|
|
"The only advantage VB has over some other languages is that it's built into the VB runtime"
Not sure how to quote, but the above says what I mean.
You know, I know, advanced programmers know that behind the scenes, a lot is going on (although, if the compiler has any sense it will be reduced to a "REP MOVSD" command in the end, which is very quick in small data situations).
"It's mearly creating a new one using a very expensive process"
The point I am trying to make is that in VB, there are commands that appear to resize an array. How this is done, to an average user, doesn't matter. I mean, if we were all looking for the "least expensive" ways of doing stuff, we would do most stuff in raw assembler. Sure, it will take more time to develop, but code costs running times would be reduced.
I am not meaning to start any arguments here, all I am saying is that the dimentions of an array can be changed. There are many more, optimal ways of achiving the same thing... but increasing an array using "redim" is cheaper, in terms of man hours, than developing a proper linked list. VB does hide all the inefficiences of the procedure, but to the end user, the array has been resized
|
|
|
|
|
Jasey9 wrote: but to the end user, the array has been resized
More properly, the end user gets the illusion of a array resized array.
Talking intelligently about the process, as you've no doubt have found in this thread, requires that you understand and use specific descriptions of processes. Even though VB, regretably, hides the true inner workings of such a function, this does NOT relieve the programmer from understanding what is truely going on behind the scenes. This is the one drawback to VB that causes the C, C++, C#, (insert flavor here) programmers to belittle VB programmers, saying that they don't know what they're doing.
|
|
|
|
|
Hello every...
I have a VB 2005 application (Express Edition), which i had installed at some place
I did a small bug fix and now went to install at a new place (Used ClickOnce deployment to generate Setup File)
I got this error
"Application validation Dose not succeed. Unable To continue"
On reading the details is got
"Reference in the manifest does not match the identity of the downloaded assembly"
Can any one help me out with this
Regards
Nishkarsh
|
|
|
|
|
|