Jump to content
Xtreme .Net Talk

jmcilhinney

Avatar/Signature
  • Posts

    110
  • Joined

  • Last visited

Everything posted by jmcilhinney

  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.
  16. Strictly speaking you should always use Invoke when calling methods of controls created on another thread. I believe that this is actually enforced in .NET 2.0. Also, I've never used a Timer other than the WinForms version but in a multi-threaded environment I'd say that a System.Threading.Timer might be the way to go. No guarantees though, just a thought.
  17. Set the ControlBox property to False to remove icon, system menu and buttons from the title bar. I'm pretty sure there is no way to actually disable that button, i.e. have it be there but "greyed out", in .NET. You need to either get rid of it, which is a bit of a baby and bath water situation, or determine whether it was clicked and act accordingly. You can set a variable when a legal closing method is used and set e.cancelled to True in the form's Closing event handler if that variable is not set. You can also intercept the Windows Message that is sent when that button is clicked using the by overriding the WndProc method. I can't remember what the message is but I've seen mention of it several times in several different places.
  18. Note that your method should either accept integers or do some error checking. Also, I'd be inclined to use something like: Dim measurement As Double If Not Double.TryParse("0" & bigMeasurement & "." & smallMeasurement, _ Globalization.NumberStyles.AllowDecimalPoint, _ Nothing, _ measurement) Then MessageBox.Show("The measurements need to be integers you idiot!") End If
  19. If you're comparing numbers then you should compare numbers. "01" and "1" are not equal. Convert.ToInt32("01") and Convert.ToInt32("1") are equal.
  20. As Machaira says, you can only have one active window. If you mean how can you stop those windows disappearing behind the main window, like the Visual Studio Find and Replace dialogue, you need to make them modeless dialogues by using code like this:Dim myDialogue As New Form Me.AddOwnedForm(myDialogue) 'or myDialogue.Owner = Me myDialogue.Show()If you do this, whenever the main window is active the dialogue will still be in front of it, even if it's not active itself.
  21. I think you mean Array1(3, 120). A multidemensional array is actaully a matrix, not an array of arrays. If you still want to be able to consider your original arrays as objects after they are combined, what you actually want is a jagged array, i.e. ArrayAll(3)(120). In that case, ArrayAll is a 1-dimensional array with four elements, each of which is an Array. In the first case, ArrayAll is a 2-dimensional array with 484 elements, each of which is a Single. If you decide that the jagged array fits the criteria of what you are doing then you can simply assign each of the existing arrays to the four elements of the jagged array. If the 2-dimensional array is the better fit, you're stuck with copying one element at a time.
  22. Start using VS 2005 if it's practicle. The MenuStrip control includes this and other new functionality.
  23. That is different. My apologies. Just give me a minute to get my high horse off this soap-box... I think Microsoft would be happy if everyone migrated to C#, but it ain't gonna happen. A good developer will not be lulled, but removing the temptation is often a solution to preventing bad behaviour in any situation.
  24. So we shouldn't use modules because they are not OO, but if they are OO we shouldn't use them because they can lull us into using some unspecified archaic conventions, but if we understand them and their limitations properly and are not lulled then we shouldn't use them because they have the same name as something in VB6 and VB6 is bad. Now I get it.
  25. Is this VB.NET code? If so, shouldn't it just be Microsoft.VisualBasic.Interaction.AppActivate() and System.Windows.Forms.SendKeys.Send()?
×
×
  • Create New...