Jump to content
Xtreme .Net Talk

jmcilhinney

Avatar/Signature
  • Posts

    110
  • Joined

  • Last visited

Everything posted by jmcilhinney

  1. MDI = Multiple Document Interface = many documents inside one parent window SDI = Single Document Interface = each document opened in its own window Microsoft Office used to use an MDI interface but now uses SDI by default.
  2. Create a module (you do this in the Solution Explorer just like for a class) and declare your variable there instead of in your form. Also, only use "Dim" in procedures and functions. At the class or module level you should use "Private", "Public", etc.
  3. If you're talking about column names, this works for actual SQL commands but I'm not sure about the RowFilter property. Put (what I call) reverse single quotes around the table or column name and you shouldn't have to escape any characters. I mean the (`) character, which is on the same key as the tilde (~). If you've ever used the Data Adapter Configuration Wizard, you should be aware that these characters are added by default to all auto-generated SQL statements for just that reason.
  4. If you mean removing every digit, here is a more efficient way. 'Declare string builder with the maximum capacity possibly needed to prevent memory reallocation. Dim tempStr As New System.Text.StringBuilder(myString.Length) For i As Integer = 0 To myString.Length - 1 If Not Char.IsDigit(myString.Chars(i)) Then tempStr.Append(myString.Chars(i)) End If Next Dim str As String = tempStr.ToString()C#: // Declare string builder with the maximum capacity possibly needed to prevent memory reallocation. System.Text.StringBuilder tempStr = new System.Text.StringBuilder(myString.Length); for (int i = 0; i < myString.Length; i++) { if (!char.IsDigit(myString[i])) { tempStr.Append(myString[i]); } } string str = tempStr.ToString();This method avoids the continual memory reallocation that would result from multiple calls to String.Remove, which would be particularly important if the original string is long.
  5. Like I said, the purpose of Len was to return the number of bytes an object would occupy when saved to a file. The happy coincidence was that this was also the length of a string object in the old days. Now that strings are Unicode instead of ASCII, Len no longer functions as it was originally intended. I'm not saying that Len does not return the length of a string or that you cannot use it in that capacity. I was merely pointing out that that is not its originally intended purpose and that is why it returns zero when passed a null reference.
  6. Why would you close the form you just went to the trouble of finding, only to show another?
  7. Well, in my opinion, you are advocating use of the wrong habit. The AcceptButton property has been specifically created to provide "default button" behaviour. You are proposing using a more general, more complex (albeit not greatly) solution when a simple, specific solution to the problem at hand already exists. How about we don't use the designer at all and do everything in the code window just in case the IDE might have a "brain fart"? This is analogous to what you are suggesting. Using the designer is limiting and vulnerable to IDE bugs, whereas you can do absolutely anything that the language permits in code, so why use the designer at all? We use it because it is a tool that has been created for a purpose and it provides a simpler, more efficient option.
  8. If you wanted to use a Timer you would have to put the code that sends the UserName and Password in a separate method that you could call from the Timer's Tick event handler.
  9. Is there a synchronous function you can call on the socket that will wait for those requests to be received? Otherwise, you could just call Thread.Sleep to add your own delay, although hard coding a delay is not the most desirable method.
  10. It works as long as you have declared a variable called ParentForm and assigned the parent form to it, but why do that when you already have the MdiParent property? The advantage might be that your variable would be of the correct specific type whereas MdiParent is of type Form, which would require a cast to use members of the derived class. If you don't use those members, however, it serves no purpose.
  11. Try this for a succinct implementation: Private Function GetFolderSize(ByVal path As String) 'Add the size of each file in this folder. For Each fileName As String In IO.Directory.GetFiles(path) GetFolderSize += (New IO.FileInfo(fileName)).Length Next 'Add the size of each subfolder. For Each folderName As String In IO.Directory.GetDirectories(path) GetFolderSize += Me.GetFolderSize(folderName) Next End Function
  12. The new form must have the original parent form as its parent too, so in the second form you would have to use code like this:Dim newForm As New Form3 newForm.MdiParent = Me.MdiParent newForm.Show()
  13. Forget all that. You make a button the default button of a form by assigning it to the form's AcceptButton property, which you can do in the designer. You then set the Button's DialogResult property to OK and then when the user presses the ENTER key the form will dismiss and return OK. You can also assign a CancelButton, which will be clicked when the user presses the ESC key and the form returns Cancel.
  14. Assuming that myChild is a member of the parent form, use code like this:If Me.myChild Is Nothing OrElse Me.myChild.IsDisposed Then 'Either the child never existed or has been closed so create a new one. Me.myChild = New Form2 Me.myChild.Show() Else 'The child already exists so activate it. Me.myChild.Activate() End If
  15. I think I answered this is another forum but in case you are a different person I'll answer it here. If something is important enough to warrant a global hotkey then you should generally have a corresponding menu item. You can then assign a value to the Shortcut property of the MenuItem and you're done. If for some reason you don't have a corresponding menu item, you need to set the form's KeyPreview property to True and then use the KeyDown or KeyUp event handlers (KeyPress won't work for function keys and some others) to test for the keys you want to handle. Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp If e.KeyCode = Keys.F1 Then MessageBox.Show("F1") End If End SubNote that you need to check separately for modifier keys (Ctrl, Shift, Alt) using the properties of the KeyEventArgs argument.
  16. You put the name of the field in that position. You said "test" so I said "test".
  17. One more thing with regards to the Len function. It was never intended to return the length of a String. This is a welcome side-effect, and its primary use in the real world, but Len actually returns the amount of storage space a variable would occupy in a file. You can use Len on non-String variables and get the number of bytes they would occupy. Len returned the number of characters in a String because that was how many bytes it would occupy. A String that is a null reference would occupy zero bytes, so Len returns zero for a null reference String. Len is not accurate in VB.NET, however, because characters are Unicode and take two bytes each, I believe, so Len no longer does what it was intended to do and return the amount of space it would take to store a String object in a file.
  18. What you are talking about are not actually shortcuts, i.e. not .lnk files. I don't know all the details but I believe they are special objects defined in the registry.
  19. What do you do when they use your Exit button/menu option? Do you destroy any objects that are not being disposed properly the other way?
  20. By the way, you can simply pass the file path to Process.Start for a registered file type to open the file with the default program. It's not a big deal here, but if you had had to provide the full path to WinWord and didn't know it on another machine it would be an issue:Process.Start("C:\\MyDocument.doc")
  21. The numbered place-holders in a format string have braces (curly brackets) around them, not parentheses (round brackets).
  22. I'll assume that the job file name is in the form "JobXXXX.rtf" for this example. If its not then you can adapt it accordingly: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim selectedItem As String = CStr(Me.ComboBox1.SelectedItem) Dim selectedJobNum As Integer = selectedItem.Substring(selectedItem.IndexOf("#"c) + 1) Process.Start(String.Format("C:\\MyJobFolder\\Job{0}.rtf", selectedJobNum)) End SubThis will open the file in the default program for RTF file type, which would probably be Word or Wordpad. If you want to use the file in some other way then do so, but the call to String.Format would be the same to create the file path.
  23. You must know something about the value they are selecting. What does it represent? Can it be any value at all or are there only certain legal values? You may well be able to use a Select statement if you know what the values can be. If it is the name of the file, then you simply pass that name to the method that opens the file.
×
×
  • Create New...