Jump to content
Xtreme .Net Talk

jmcilhinney

Avatar/Signature
  • Posts

    110
  • Joined

  • Last visited

jmcilhinney's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. The purpose of having a global variable is exactly that, to have access to it from everywhere. It doesn't matter whether you use a module, a singleton class or a class with all Shared members, you can still affect the single value of a global variable from anywhere in your application, so the same issues are applicable. If you don't want global access then don't use a global variable, of any kind, but if you do want global access then do. If someone is at the stage of creating a multi-user application then they should be at the stage of knowing the issues associated with global access to variables. Having a single database accessed by multiple clients is just an extension of this. Basically, good programming is good programming and bad is bad. If someone uses a global variable out of laziness then they deserve to have their application crash and burn, but if they truly need a global variable then the same issues apply, however they implement it.
  2. This code will throw an NullReferenceException if the file does not exist, because no reference will ever be assigned to the rFile variable but the code will still call Close on it. You would need to test for a null reference in the Finally block:Dim rFile as StreamReader Try If File.Exists(frPath) Then rFile = File.OpenText(frPath) ReadString = rFile.ReadToEnd() stubText.Text = ReadString End If Catch ex as Exception Finally If Not rFile Is Nothing Then rFile.Close() End If End Tryor use two Try...Catch blocks: Dim rFile as StreamReader Try If File.Exists(frPath) Then rFile = File.OpenText(frPath) Try ReadString = rFile.ReadToEnd() stubText.Text = ReadString Catch ex as Exception Finally rFile.Close() End Try End If Catch ex as Exception End Try
  3. This question is definitely in the top 10 most asked. Do a forum search and you'll find your answer.
  4. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/listviewsort.asp
  5. There are many third-party managed MaskedTextBoxes available on the net, or you can use the unmanaged Microsoft MaskedEditBox ActiveX control. The MS version is available to be added to the Toolbox from the COM Components tab. .NET 2.0 adds its own managed MaskedTextBox.
  6. This is exactly why I recommended Double.TryParse, because it is probably not safe to assume that the user has entered a number, unless you have used some validation techniques to restrict input to the TextBox. If you make this assumption and the user enters anything that is not an integer then you'll get an unhandled exception. TryParse attempts to convert a string to a number in the format you specify without throwing an exception if it fails.
  7. This MSDN topic contains code to open an Excel spreadsheet, run a routine and then close the file and application. It was result number six returned by the search I suggested.
  8. Search MSDN for "automation excel .net" (without quotes).
  9. Like I said, use the SelectedItems property to get the item that was activated. If you look up the SelectedItems property in the help you'll see it's type and you'll be able to get a single item from it. Once you have a ListViewItem, as I said before, you need to read the Text property of each SubItem.
  10. The Regex class has a Matches method which is what you want to use.
  11. Look at the Regex class, which encapsulates regular expression functionality. You'll need to do some reading on regular expression syntax to make much of a use of it though.
  12. In the DoubleClick event handler use the SelectedIndices or SelectedItems property of the ListView to get the item that was double-clicked and read the Text property of each Subitem.
  13. Every method in the .NET Framework that can throw an exception has that information detailed in the help system. Every method you call that can throw an exception is a candidate for a Try...Catch block. If your code is the only point of access for the objects you are using then in most cases you won't need to use exception handling because if your code is written properly then those exceptional circumstances won't occur. When you should definitely be using exception handling is when you are dealing with objects that can be affected by factors beyond your control, like connecting to a database.
  14. The code provided is basically a recursive file search. It's not meant to delete files. You need to edit it yourself to delete files instead of get their size. You will also need to add some exception handling in case a file is locked and cannot be deleted.
  15. If you would refresh the data if it was different then it might be just as easy to do that anyway. I'm guessing that a comparison would probably take just as long.
×
×
  • Create New...