|
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
|
|
|
|
|
|
Thanks for the links...
I was able to do install by deploying the solution again...
Can you plz explain me what exactly is "obfuscation" which ppl are talnkin about...
Is is safe to assume that "ClickOnce in Visual Studio 2005" is having some issue and we have to always deploy the solution twice...
Regards
Nishkarsh
|
|
|
|
|
Hi,
I'm pretty new to the forum and to VB.Net 2008
I use the express version at the moment and try to copy over files and folders from a userprofile within windows XP.
How do I skip the hidden files and folders and/or files that are in use?
I get an exeption everytime it finds something I don't have permission to.
Any idea's?
here is my code so far:
Imports System.IO
Public Class frmProfileCopier
Dim SourcePath As String, DestPath As String, ExactPath As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
SourcePath = "C:\Documents and Settings\" & tbUserName.Text & "\"
ExactPath = "UserData\" & tbUserName.Text & "\"
DestPath = fbdDestDrive.SelectedPath & "\" & ExactPath
CopyDirectory(SourcePath, DestPath)
End
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
End
End Sub
Public Function CopyDirectory(ByVal Src As String, ByVal Dest As String, Optional _
ByVal bQuiet As Boolean = False) As Boolean
If Not Directory.Exists(Src) Then
Throw New DirectoryNotFoundException("The directory " & Src & " does not exists")
End If
If Directory.Exists(Dest) AndAlso Not bQuiet Then
If MessageBox.Show("directory " & Dest & " already exists." & vbCrLf & _
"If you continue, any files with the same name will be overwritten", _
"Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2) = DialogResult.Cancel Then Exit Function
End If
'add Directory Seperator Character (\) for the string concatenation shown later
If Dest.Substring(Dest.Length - 1, 1) <> Path.DirectorySeparatorChar Then
Dest += Path.DirectorySeparatorChar
End If
If Not Directory.Exists(Dest) Then Directory.CreateDirectory(Dest)
Dim Files As String()
Files = Directory.GetFileSystemEntries(Src)
Dim element As String
For Each element In Files
If Directory.Exists(element) Then
'if the current FileSystemEntry is a directory,
'call this function recursively
CopyDirectory(element, Dest & Path.GetFileName(element), True)
Else
'the current FileSystemEntry is a file so just copy it
File.Copy(element, Dest & Path.GetFileName(element), True)
End If
Next
Return True
End Function
Private Sub btnDestDrive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDestDrive.Click
fbdDestDrive.ShowDialog()
Label1.Text = fbdDestDrive.SelectedPath & "UserData\" & tbUserName.Text & "\"
End Sub
End Class
I get an exeption on the line with :
File.Copy(element, Dest & Path.GetFileName(element), True)
Also my label1 doesn't work when I use ExactPath instead of the "UserData\" & tbUserName.Text & "\"
Greetzzz,
CornElvis
www.jackied.nl
|
|
|
|
|
You can check to see if a file is marked as hidden using FileInfo . See How to: Determine if a File is Hidden in Visual Basic[^].
To handle the error on files that are currently in use and cannot be copied, I would wrap the File.Copy line in a Try...Catch block and in the Catch part I'd save those files to a log just so you can see which files were not copied.
|
|
|
|
|
thanks, I'm going to try that and come back to tell if it works or not.
Update:
I tried multiple things, but I get a permissions issue with I file I guess is either read only or in use.
How do I skip the hidden folders, because I think then everything is sorted for this purpose, although I might want to copy the Application Data folder as well.
Maybe it's better to skip the files it can't copy and then write them to a text file as you said, but I can't seem to fit the code in (I'm a rookie remember... )
Can you tell me how to do this and when it finds one it needs to jump to the next file, because then I'm done with this part and I can try to build the progress bar in....
Let me know please
Greetzzz,
CornElvis
www.jackied.nl
modified on Thursday, July 10, 2008 10:20 AM
|
|
|
|
|