Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. orca may be right, in the code you've posted you don't actually create the array. Might I suggest you ditch the array and go with the nifty List(Of T) class. It's a rare case these days that a collection class doesn't make things simpler. There are some other things I might have done differently, as well. These are only suggestions (except for the Exception issue, which is a very strong suggestion). Take em or leave em. Public tabs As New [color="Blue"]List(Of Tab)[/color] Public wbs As New [color="Blue"]List(Of WebBrowser)[/color] Public Sub NewTab(ByVal url As String) Try [color="Blue"]Dim newWb As New WebBrowser Dim newTab As New Tab[/color] newWb.Name = "wb" & count.ToString() newWb.Location = New Point(0, 69) newWb.Size = New Size(903, 517) newWb.Navigate(url) newTab.Name = "tab" & count.ToString() [color="Blue"]Dim IsFirstTab As Boolean = tabs.Count = 0[/color] If (IsFirstTab) Then newTab.Size = New Size(212, 32) newTab.Location = New Point(120, 0) Else newTab.Size = tab(count - 1).Size newTab.Location = New Point(tab(count - 1).Location.X + 212, tab(count - 1).Location.Y) End If [color="Blue"] wbs.Add(newWb) tabs.Add(newTab) [/color] Me.Controls.Add(newWb) Me.Controls.Add(newTab) Catch ex As Exception [color="Blue"] ' Bad plan, man. You only want to capture exceptions you are prepared to handle. ' You should make a point of NOT catching things like OutOfMemoryException. [/color] MessageBox.Show(ex.Message()) End Try End Sub
  2. What do you mean by refreshes? The paint event triggering? Or the form flickering? What is the actual problem you are trying to solve here?
  3. The short answer is yes. This syntax is inherited from C. It does seem inconsistent. However, consider the structure of the for statement (not sure if this is 100% technically correct, but it gets the idea across): for ([i]statement[/i]; [i]expression[/i]; [i]expression[/i]) [i]statement[/i] Normally, a semi-colon denotes the end of a statement. As you can see, the last two are expressions. In this case, we are using the semi-colon as more of a delimiter. You don't normally write code with a trailing delimiter. int x, y, z[color="Red"],[/color]; At the same time, C# does accept trailing commas in some cases. One reason for this is because it makes code generation simpler. (I use trailing commas in enums and initializers if they are declared across multiple lines.) int[] x = {0, 1, 2, 3[color="Red"],[/color] }; var x = new { A = "Aye", B = "Bee"[color="Red"],[/color] }; enum x {a, b, c[color="Red"],[/color] }
  4. When you encode the text into the XML, these characters should be escaped. When you read it back, you need to parse the escape sequences to get the original text. XML isn't my strong suit, but a quick google search gave me this result, which explains how to encode/decode these escape sequences.
  5. Just like any other reference type, a string can be null. There is, in fact, a difference between a null string and an empty string. An empty string is a string object that has a length of zero. It might not contain anything, but it is still an object. You can still access it. [color="Green"]// Assuming line is empty...[/color] int len = line.Length;[color="Green"] // Returns zero[/color] char[] chars = line.ToCharArray(); [color="Green"]// Returns an empty array.[/color] string padded = line.PadLeft(2); [color="Green"]// Returns a string containing two spaces[/color] A string variable can also be null. That means that the variable doesn't point to any string object (not even an empty object). Although this seems like a pointless distinction, it makes quite a difference in what happens with our code. [color="Green"]// Assuming line is NULL...[/color] int len = line.Length;[color="Green"] // Throws NullReferenceException[/color] char[] chars = line.ToCharArray(); [color="Green"]// Throws NullReferenceException[/color] string padded = line.PadLeft(2); [color="Green"]// Throws NullReferenceException[/color] There is a school of thought that believes variables should never be allowed to be null unless you declare it as nullable. Accidentally using a null variable can cause so many headaches, and in many cases there is no advantage to having null variables. On the flip side, being able to have null as a default value for variables has performance advantages and simplifies some scenarios. There are many cases where you need to distinguish between an empty string and no string at all. The ReadLine function returns an empty string when it encounters an empty line in a file, and it returns null when it reaches the end of the file. In this case, the distinction is very important.
  6. We're gonna need more info to go on than that. What kind of interface does the C++ project expose? Is it managed? COM? None of the above? The approach varies depending on the nature of each project and how they need to interact.
  7. Well, instead of only looping over the checked items, why not loop all items and use an "if" statement to test each item and see whether it's checked. Assuming you have no duplicates in your list, you can use this little bit of code to test whether an item is checked. Dim ItemIsChecked As Boolean = CheckedListBox1.CheckedItems.Contains([color="Blue"][i]item[/i][/color])
  8. Jumpy, it looks to me like it's still free. You have 30 days to register, but no purchase required.
  9. If what you are asking is how to uncheck the button that was clicked, note that the button that was actually clicked is passed as the sender argument. Cast to the appropriate control type, and you can access its properties, like so: DirectCast(sender, Button).Text = "I've been clicked!"
  10. It sounds to me like the purpose of this excersise is to learn and practice loops. To that end, StrReverse is not the correct approach. That would be like a student using a calculator on a long division test. If you're looking to do the reversing yourself, here are my thoughts. You can get individual characters from a string using the Chars property. (Since Chars is the "default property", you could also just use parens.) Dim SomeString As String = "ABCDEFG" [color="Green"]' Get the third character of a string[/color] MessageBox.Show(SomeString.Chars(2)) [color="Green"]' This is equivalent and produces identical results.[/color] MessageBox.Show(SomeString(2)) You can reverse a string with a loop that goes from the last character to the first, taking each character and appending it to a variable. Remember that the character indecies start at zero, so the last character would be one less than the length of the string: Dim LastIndex As Integer = SomeString.Length - 1 To run a loop backwards, you need to specify a negative step. [color="Green"]' A value of -1 is added to i each iteration, until endValue is reached[/color] For i As Integer = startValue To endValue [color="Blue"]Step - 1[/color] And, just to cover all my bases, you use the & symbol to combine strings. Dim ABCD As String = "ABCD" Dim DCBA As String = ABCD(3) [color="Green"]'D'[/color] DCBA = DCBA & ABCD(2) [color="Green"]'D' & 'C' -> 'DC'[/color] DCBA = DCBA & ABCD(1) [color="Green"]'DC' & 'B' -> 'DCB'[/color] DCBA = DCBA & ABCD(0) [color="Green"]'DCB' & 'A' -> 'DCBA'[/color] That's everything you would need to reverse a string if StrReverse did not exist.
  11. This doesn't really have anything to do with the settings of the text file, per se, so much as how one program or another is using the text file. Normally, when a program opens a file, the file is locked so that no other program can open the file. There is a straightforward way around this, but it requires that you access the file via a FileStream (i.e. you can't do this with methods such as File.ReadAllLines). var fileStream = System.IO.File.Open( "MyFile.txt", System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, [color="Red"]System.IO.[i]FileShare[/i].ReadWrite);[/color] The FileShare value specifies how the program is willing to share the file. You can allow other programs to read the file, or to write to the file, or both. But before you slap file-access-sharing into your programs, first consider why .NET (or any self-respecting API) would default to locking a file. If one program is writing while the other is reading things can go terribly wrong. Things get sketchy when the file is being modified under your feet as you read it. The only way I would feel safe doing this is if the two programs were working together and communiticating what was going on to eachother, but if the two programs are communiticating to eachother they should be able to skip the file and send the info in question directly to eachother. Beyond that, when you share the file access, you can't pick and choose who else can access the file. It won't be limited to your other program, and that sounds a little sketchy to me, too.
  12. Hi ScottN. It's generally best to put a new question in its own thread, with a link to a related thread if appropriate. I would expect the TV out to behave as a normal display. As for detecting changes and activating/deactivating, again, I don't know.
  13. VB's bit-shift operator supports practically all integral types:
  14. You're in the right section, but what you're asking isn't a simple question. Assuming you've got the general principles down, you still need to know the details of how the phone communicates with the software. The specifics are probably proprietary, which means nobody here can help you with that.
  15. Sorry, we don't write your code for you or search for DLLs for you. If you're trying to code something and you're stuck, please ask a more specific question and we'll be glad to help.
  16. Sorry, completely missed that. I guess you can disregard my post. Off the top of my head I don't know any more about doing a file drop via messages than you do.
  17. If an exception occurs in your property's set accessor, the property grid will show the user an error dialog with the exception's message. This means that in your set accessor you can check a value to make sure it is in range, and throw an exception with the appropriate message if the value is invalid or out of range.
  18. My whole point is that the exception may be getting handled. Try catching any exception thrown, not just those that are unhandled.
  19. No simulation necessary. DotNET comes with drag-drop support built in; no need for mucking around with messages. The Control.DoDragDrop method initiates a drag-drop operation. You'll want to look at the documentation: If you want to drag files to another application, you can populate a DataObject with a file list, then specify that as the data when you call DoDragDrop, with the appropriate DragDropEffects (probably move or copy). someDataObject.SetFileDropList(someFileList); DoDragDrop(someDataObject, DragDropEffects.Move);
  20. Under the debug menu you can select "Exceptions..." where you can choose whether to handle all exceptions, or only those that are not handled in your code. You can apply this setting differently for different types of exceptions. If you are only catching unhandled exceptions, your code (or, possibly, framework code) could be catching exceptions and swallowing them. In this case you need to make sure you handle all thrown exceptions, otherwise you'll never see them.
  21. You might want to look into something like this CodeProject article. You can get a lot of control over the property grid by using custom TypeDescriptors and PropertyDescriptors.
  22. Is MAINTENANCE_MODE a constant? If so, it would be the same as typing: if (true) { result._response = LoginResult.MAINTENANCE_MODE; } else { result._response = LoginResult.INVALID_REQUEST; } The compiler is just clever enough to realize that only one block of the if statement can ever be executed. The other block is unreachable. One alternative would be to define a symbol used for conditional compilation. [WebMethod] [color="Blue"]#define MAINTENANCE[/color] // Omit for non-maintenance build public LoginResponse Authenticate(string username, string passwordmd5){ LoginResponse result = new LoginResponse(); if (DataBaseManager.CheckIPBan(Context.Request.UserHostAddress)) { result._response = LoginResult.IP_BANNED; } else { [color="Blue"]#if(MAINTENANCE)[/color] result._response = LoginResult.MAINTENANCE_MODE; [color="Blue"]#else[/color] result._response = LoginResult.INVALID_REQUEST; [color="Blue"]#endif[/color] } return result; } Another alternative would be to suppress the warning for the code in question.
  23. Well, a quick google search gave me this discussion on examining a folder's permissions.
  24. Sorry, but I'm having an awfully difficult time following either the code or the question. I think you need to break them both down a bit. As far as the code is concerned, a little formatting would go a long way.
  25. I would imagine that it would always return all directories. A user's preferences for Explorer shouldn't affect the way file I/O works in .NET. What you need to do is examine the Attributes property of the DirectoryInfo object, and just filter out those directories that you don't want.
×
×
  • Create New...