Jump to content
Xtreme .Net Talk

Nerseus

*Experts*
  • Posts

    2607
  • Joined

  • Last visited

Everything posted by Nerseus

  1. My mistake - only coded delegates a few time, long ago and quickly forgot how :) Delegates are basically "global". If you define your delegate outside of a namespace then it's truly global. If you define it inside of a namespace, you'll have to reference the namespace when declare an instance of the delegate. For example, say you had ClassLibrary1: using System; public delegate void MyDelegate(); namespace ClassLibrary1 { } And ConsoleApplication1: using System; namespace ConsoleApplication1 { class Class1 { [sTAThread] static void Main(string[] args) { MyDelegate mydelegate = new MyDelegate(test); mydelegate(); Console.Read(); } static void test() { Console.WriteLine("Hello World"); } } } This will work. Now if you change ClassLibrary1 to put the delegate inside of the namespace like so: using System; namespace ClassLibrary1 { public delegate void MyDelegate(); } Now ConsoleApplication1 won't compile unless you give it the namespace of ClassLibrary1, as in: using System; namespace ConsoleApplication1 { class Class1 { [sTAThread] static void Main(string[] args) { [b]ClassLibrary1.[/b]MyDelegate mydelegate = new [b]ClassLibrary1.[/b]MyDelegate(test); mydelegate(); Console.Read(); } static void test() { Console.WriteLine("Hello World"); } } } Obviously, this assumes the delegate is made public. If it were internal, for example, it wouldn't be accessible outside the project/assembly. -Nerseus
  2. Why not just use ReadOnly = true? It doesn't change the background color or foreground color. The only "negative" side is that it can still receive focus and show the caret (cursor). You can tweak that if you want, but I don't see a problem with it. -Nerseus
  3. You can use the DateTimePicker. Set: Format: Time ShowUpDown: True -Nerseus
  4. If you just have one char, just split on the char: splitText = temp2.Split(':'); The Split method has a "params" overload so you don't need to pass an array. If you had two chars to split on, you could use: splitText = temp2.Split(':', '.'); If you wanted to use an array, use this syntax: char[] splitter = new char[] {':'}; splitText = temp2.Split(splitter); NOTE: When you used: char[] splitter = new char[':']; The compiler converted the character colon (':') into it's numeric equivalent: ASCII 58. "splitter" is then initialized to be a 58 character array, with each character taking it's default value (ASCII 0, since this is a value type array). -Nerseus
  5. You could spend time on your own routines or search for some existing library. This article from MS shows a sample "complex math" library - look for "Figure 3". It's in C#, but I'm sure you could convert it to VB.NET fairly easily. If you want to fix up your library, you may consider adding some error handling. You don't currently check for empty strings, non-digits, etc. If you're sure you'll always have "clean" data going in, this may be an unnecessary step... I'd suggest throwing some unit tests at your code as well, to test out all the functions. -Nerseus
  6. The "credit" usually depends on the terms of the contract - you have a contract, right? :) For my company, if we are writing software and they want their name on it, not ours, that generally implies that they want to keep all the intellectual rights and sourcecode. That means they'll pay extra. So scenario 1 would be: They pay for all code - when the project is done they get all the sourcecode. The about box would only show their name (or whatever they want). Often they don't want their users knowing it was contracted out. Since you're working in contractor mode you're really part of their company for that contract. While technically you can't reuse any of that code for another project, you can often reuse some "common" libraries that you spent time writing. For example, say you wrote a library of routines that takes an int and convert it into a SQL String, converting 0 to DBNull, etc. That type of code is too "common" to be included in the above contract so you'd be safe in reusing it later. Which brings up scenario 2: The contract include some common "framework" or "library" of code. You would normally agree to only give them this as a DLL - they don't get the source unless they pay for it. You would generally sell this at a lower rate The other part of the contract is like scenario 1 - most of the code you write is specific to their business and they're paying for it and get the source and their name on the app. Scenario 3: You keep full rights to the software you write and sell to the client. It generally has your name, though you may negotiate to have them put their name on it (with your name somewhere below) for a higher price. The benefit to the client is that it comes at a much cheaper price since you are planning on reselling it. They may negotiate to keep the sourcecode, if you want. These are just 3 common scenarios. The terms of a contract can be changed/defined by whatever you feel is fair. If you DON'T have a contract, then you'd better be best friends in real life - and even then there might be issues at the end of the project. A contract isn't like a pre-nuptual agreement in that one party is feeling like "hmm... why do they want a contract, shouldn't this just be an agreeable thing - maybe they're hiding something". It just states your intentions to use the code (or not) and what price everyone is agreeing on. -Nerseus
  7. No problem. As for team development, you can have the project 1 DLL available on a network if it's not very volatile (changing interfaces every day or so). It would help if the version number of that DLL NOT change for awhile otherwise it won't work - you'll have to recompile Project 3 if Project 1's version changes. You could also make it a requirement that whenever you work on Project 3 you must have Project 1 in the same solution. This works better while Project 1 is undergoing a lot of changes. Once it gets more "stable", it's usually better to put it up on the network just to limit the size of your solutions (if it becomes an issue). -nerseus
  8. Nothing can be declared outside of a Class... A delegate has the "scope" of the class. If you declare the class and the delegate as public then they have, more or less, global scope. Meaning, any class would be able to create a delegate of that type. -Nerseus
  9. I'm not sure I understand the dilemma - Project 3 only requires a reference to Project 1. As you stated, changing the implementation of Project 1 (and hence generating a new DLL) would not require a recompile of Project 2 or Project 3 for those two projects to take advantage of the "fix" to Project 1. You should not have to re-implement any properties in Project 2 or Project 3 if they do what you expect in Project 1. I thought you only re-implemented the UserID property in Project 2 (or was it Project 3) to try and get around having to reference Project 1 from Project 3? If you take that re-implementation out and have Project 3 reference Project 1, you should be fine. -Nerseus
  10. The standard behavior when moving a position is NOT to change the status of the row. My guess is that you have some code that's updating the row when the position changes. It might be something as simple as format/parse event on a textbox (to format a value from 4.56 to $4.56 and back). You can add a ColumnChanged event (or RowChanged event) to a DataTable. In the event you can set a breakpoint and use the CallStack window to see what code, if any, is causing the update. -nerseus
  11. If you want a more type-safe way of doing it, use the SqlParameter objects which take actuall bool values for bool datatypes. Meaning, you can use your check1.Checked property (a bool) to fill a SqlParameter object which will take care of conversion to SQL Server or Access. In other words, let the data adapter take care of the adaptations. If you're really going to use dynamic SQL I'd strongly suggest NOT using the CType to an Integer for at least 2 reasons: CType itself may not be supported in future versions of .NET (it's a carryover from VB6 and under), it's not as clear that a bool is being converted to an int the way you want (not to mention you want a bit in the database). When in doubt, be clear in code. If you must use dynamic SQL, why not use String.Format? Dim sql As String sql = String.Format("UPDATE table SET MyField={0}...", BoolToSQLString(checkbox.Checked)) Public Sub BoolToSQLString(ByVal b As Boolean) If b Then Return "1" Else Return "0" End If End Sub -Nerseus
  12. As the compiler states, you need a reference to the first project in your third project. While project2 encapsulates some logic from project1, you still need the reference (the DLL) so that when code from project1 is run it knows where to get it. When you compiled project2, it did NOT copy all of project 1's code into project 2's DLL. It relies on project 1's DLL to contain all that code and functionality. I'm actually surprised that the code from your second post would compile. I wouldn't think it mattered what if you overrode all properties from the base class or not - you would still need the reference to that DLL. In answer to *that* question, yes - overriding a base class's property to do the exact same thing is a bit overkill just to prevent you from having the extra reference. -Nerseus
  13. You can use the GetChanges() method to return a new dataset of changed rows (inserted/updated/deleted). I didn't take a close look at your bindings, but the GetChanges should get you what you want. If you're finding too many rows being modified when they shouldn't maybe upload a small sample project. -Nerseus
  14. To be clear on why your original code didn't work, the way you were using "DialogResult" was a bit off. The "DialogResult" your program was reading was from the form (which has a DialogResult property). Your code was essentially: If Me.DialogResult.Yes = True Then... As a default, the form's DialogResult is Cancel (I think) unless you set it or have a button's DialogResult property set and you're within the click event - not really that important, just thought I'd elaborate on my elaboration. -Nerseus
  15. I think the question is (again): Why do you want to wait 5 seconds? A solution can't be offered if we don't know the problem. If you just want to wait 5 seconds to see who, then Sleep will work perfectly. If you're working around some issue, we'll need to know what it is to help. -Nerseus
  16. Why not just use ToString with the right format, such as "hh:mmtt"? Dim s As String = Today.ToString("hh:mmtt") -Nerseus
  17. Or make function Add "Shared" and then call it with: MessageBox.Show(Operatie.Add(2, 3).ToString) -Nerseus
  18. Also, you would have to declare all of your variables as type "MyString" (or whatever name you picked). That means any functions that accept a String would have to accept MyString. Anytime you call a built-in function that accepts a string, you would have to use something like: MyString s = "hello"; // Function Test takes a String as an argument Test(s.ToString()); Luckily, not calling ToString will result in a compile error so you can catch these quickly. Not so luckily, if you want to assign the MyString to a DataSet, you'll have to remember to use ToString. If you don't, you won't get a compile error but you'll get a runtime error: // assume ds is a DataSet MyString s = "hello"; ds.Tables[0].Rows[0][0] = s; This will compile just fine as the value being assigned takes an object, which s is. Since MyString isn't a normal DataSet datatype, this will throw an exception at runtime. I tried this with an integer (I made NullInt). You have to overload a ton of things, and you're still left with a number of issues that you must be very diligent about fixing. It might be worth it, if you're careful. -Nerseus
  19. I, too, wish that C#'s intellisense were a little smarter. There's no (good) reason why C# couldn't support intellisense for "true/false" on something like this: bool b = (after typing the "=" sign have intellisense show the values "true/false".) Likewise, having a variable declared as an enum and setting it should offer a nice way to fill in the enum name for you. For example: MyEnumType var = (after type the "=" sign intellisense could let you press Tab and fill in the word "MyEnumType." and show the dropdown.) Similarly, typing "if" and pressing space could fill in "if ()" and leave the cursor inside the parentheses. The XML editor offers similar functionality when adding attributes. The only disadvantage I see with this, and it's VERY minor, is that newcomers to a language might not fully learn some of the constructs. For example, typing in "Try" and having intellisense giving you a "Catch" block. A newcomer to VB.NET might not know that you can have just a try/finally block (no catch). I use these often, especially when changing the Cursor on a Windows Form. It's a minor hazzard and I doubt MS left out some intellisense options for this reason :) We can only hope for Whidbey (.NET 2005) to enhance some of these options. I have the Technical release right now so I'll find out tonight - be jealous :) -Nerseus
  20. A general rule of thumb is store date/time (even if it's just a Date) in a DateTime variable in your program. Only when you want to display it do you format it. You can use the overrides on ToString() to "hardcode" a format if you like. For example, to not show the time portion: string s = DateTime.Now.ToString("MM/dd/yyyy"); If you want a specific time format, or want to ensure that it's the same on every machine, it's probably best to use a "hardcoded" string format or use your own CultureInfo object to do the formatting. -Nerseus
  21. If you're within a child form's code (say a button click event on the child form) then you can just use the current child form's MDIParent property: // chld3 will be the second child form to be shown Form2 chld3 = new Form2(); chld3.MDIParent = this.MDIParent; If you're within the MDI form when you want to show a new child form, then use "this": Form2 chld3 = new Form2(); chld3.MDIParent = this; -Nerseus
  22. Actually, if you need to worry about globalization - or if you just want to see a full .NET version, try something like this: DateTime date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); string s = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames[(int)date.DayOfWeek]; My VB version might not be 100% - in fact, I don't know how you cast from one type to another in VB. Below, change the "(int)" in front of "date.DayOfWeek" to however you cast in VB. Dim date As DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1) Dim s As String = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames((int)date.DayOfWeek) -Ner
  23. Try something like this instead: Dim dr As DataRowView lvw.Items.Clear() For Each dr In ds.Tables(0).DefaultView lvwUser.Items.Add(dr("Username")) Next
  24. You're looking for something like XSLFO. I use a product by AntennaHouse that creates a PDF from the result of a transform - there are a number of companies that do this though. If you search google for "xslfo" you'll find a number of good links to get you in the right direction. I believe from my past searches that there's at least one version of an XSLFO formatter that outputs PDF that's free - I don't remember the link or the site though. Of course, if you have $20,000 per server (or CPU?) you can use Adobe's print management software which does the transform and PDF output for you. :) -Nerseus
  25. First, the glu*.dll is not a com dll. That means you'd have to use ImportDLL to get the functions included - you probably don't want to do this though. Searching google for "opengl vb.net" turned up a bunch of good hits. I'd search through some of the results as it looked as though there were a few sites (at least) that had some "getting started" pages. -ner
×
×
  • Create New...