Jump to content
Xtreme .Net Talk

Nerseus

*Experts*
  • Posts

    2607
  • Joined

  • Last visited

Everything posted by Nerseus

  1. Don't know about urgent... Can you send us the code that's causing the problem. Also, send us a sample of your connection string AND the code that calls the webservice. The more info the better. Much better to have too much than too little. -Nerseus
  2. For things like phone numbers, you'll have to convert yourself. Assuming your Database always stores the number as "5551112222" then you can easily format this to meet your needs. Since you don't want to use a MaskEdBox (a good thing), you'll have to manually parse the string into a valid phone number. A regular expression is an easy (relatively) way to validate the data they typed is in a "good enough" format such as "(xxx) xxx-xxxx" or "xxx xxx-xxxx" or other combos. Using regular expressions, you can name each group and extract out the info so that you can use one regex to test AND extract data without having to worry "did they use format #1 or format #2". As for where you do the parsing, if you're not using the binding features, you can use a couple of events (GotFocus and Leave are two common ones). If you're binding, you can use the Format and Parse events which are meant to do exactly what you want. Converting numbers are easier since you can use the built in parse and format functions for each datatype. You will still have to decide which events to use or go with binding. -Nerseus
  3. This is untested, but try this. It adds one optional decimal point followed by 0 or more digits: "=\s+(?<MyPat>\d+[.{0,1}][\d]*)" You might need a backslash in front of the "." but I don't think so. The {0,1} says 0 or 1 occurrences of the ".". The final \d with a * says 0 or more digits. If you really want 0, 1, or 2 digits you can change it. -Nerseus
  4. You can manually call any event handler as they're just functions that happen to get called by the event handler (through a delegate). The "special" work is done by the event, not the function that gets called. Many people would rather move the code out from the TextChanged event into a function, say UpdateFirstName (if the textbox is txtFirstName for instance). Then call UpdateFirstName() from the event handler (TextChanged event) and from wherever else you're changing the textbox's value manually. -Nerseus
  5. You could also use Regular expressions to find groups and matches, though what you have seems fine, especially for such simple code. I'd keep it simple and clean since it sounds like you've already got a lot going on with reading from a microcontroller. Why messy up working, readable code with regular expressions (powerful, but not very intuitive). For the record, a string object has a built in Split method. You can use the following instead of the Split function: Dim s As String s = "A=100, B=200" Dim a() As String a = s.Split(",") ' instead of a = Split(s, ",") If you want to try out regular expressions, let me know. -Nerseus
  6. You'll need to use the performance counters from the Win32 API. Here's some sample code that doesn't do anything, but shows you the functions. You can search Google for more help (search on the function names): [system.Security.SuppressUnmanagedCodeSecurity] [DllImport("kernel32")] private static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency); [system.Security.SuppressUnmanagedCodeSecurity] [DllImport("kernel32")] private static extern bool QueryPerformanceCounter(ref long PerformanceCount); long qwTicksPerSec; // Number of ticks per second. Based on your computer, only set this once long qwTime; // If bUsingQPF returns false, you can't use these - you'll have to use timeGetTime. // I think it's for Win98 or Win95 and earlier (can't remember which versions don't support them) bool bUsingQPF = QueryPerformanceFrequency(ref qwTicksPerSec); QueryPerformanceCounter(ref qwTime); // Use QueryPerformanceCounter to get the current time. Subtract // from previous calls to get the difference. // Use qwTicksPerSec to get how many ticks per second you have. -Nerseus
  7. I can honestly say that I don't care what math anyone has on their resume. I look at experience (for placement), ability to learn (subjective per the interview process) and personal skills (relating to other team members). I took a lot of advanced math but I've not once used it in anything I do (no calculus for sure). The higher math is good for analysys in case you're working on some super program that may take longer to run than to write and you need to analyze your algorithm for efficiency OR if you're writing software for the scientific community where the math is the focus of the application. Now for graphics, I'm surprised your classes didn't go into a lot of geometry/trig type of discussions. At the very least, SIN, COS, and some other "simple" math for calculating angles of normals and where a line intersects a plane, etc. One final word of advice. If you feel like you could learn more from school, you might consider staying. If you're only staying to say "I got the degree", it might not be worth it. Some jobs (government mostly) may require a BS or associates degree for the job, but most private sector companies just want someone that's good. Now if you don't have any experience AND you don't have a degree, then you'll have to sell yourself more (very charismatic in the interview, let them know you LOVE programming and are willing to learn fast). An entry level position will quickly turn into more (in a year or two) if you're enthusiastic about learning. It's not uncommon to get large increases in pay and skills in a matter of 2 or 3 years, often getting to 40k or more with just a few years of experience. Good luck! -Nerseus
  8. wyrd: Your example would (and should) work perfectly in C++, as the bool values are really ints (C++ has overloads for BOOL and values like TRUE and FALSE - there is no native Boolean datatype). But in C#, it's a bit "sloppy" to have the | operator be a bitwise OR in case and a logical OR in another, based on datatypes. C# was supposed to be more type safe but I consider the single pipe a "slip". Since C# doesn't define what int value a bool type has (0, 1, -1, etc.) internally, you shouldn't be able to use an operator that *normally* is used for bitwise operations (which only work on numbers, not abstract datatypes like a boolean). The fact that it does work is only a convenience in case you forget which to use (one pipe or two). Since most people would call this "sloppy" and choose to only use the two pipes, I thought it worth mentioning (since we're on the topic of "sloppy" coding in VB.NET versus the "clean" coding of C#). -Nerseus
  9. This is ADO code, not ADO.NET. First, you're in the wrong forums. Second (answer), in ADO you can't guarantee the RecordCount will be accurate until you've gone to the end of the RecordSet by using MoveNext to the end, or MoveLast. You may be able to read the RecordCount in some cases (it sounds like it works sometimes), but definitely DO NOT count on that. You should use the .EOF property like you are - it's safer. If you really need the record count, you'll have to first check BOF or EOF, then loop through using MoveNext til the end, then check the RecordCount. Don't forget to go back to the beginning before trying to use your Recordset. -Nerseus
  10. Can we see ALL of the code in question? -Nerseus
  11. I heard differently awhile back. If you issue two separate calls to Access, one to do the INSERT and one to do the "SELECT @@IDENTITY" to get the last inserted AutoNumber value, it should work. This assumes each user has their own always-on connection to the DataBase (usually how you program against Access). It's a bit easier in SQL Server since you can do the INSERT and SELECT @@IDENTITY in one calls, but it doesn't work in Access for dynamic SQL. If you're calling a stored proc in Access (which you must create using dynamic sql using something like "CREATE PROC...", you *might* be able to have the proc do an INSERT and SELECT, but I haven't tried it (nor have I tried creating procs in Access, though I hear-tell you can). -Nerseus
  12. Have you tried using this.SuspendLayout() or Me.SuspendLayout()? Don't forget to call ResumeLayout when you're done. -Nerseus
  13. To really understand what happens, you have to know how memory is used (including pointers and the actual data structures they point to). For most people, that's WAY too much knowledge and just hearing that all non-primitive types are passed byref is good enough. It only comes to byte :) you later, when something isn't quite working as expected and you can't quite figure it out. As long as you understand what's happening and can accurately predict what's going to happen when you call a function, you can call it By Val, By Ref, or Sally Sue Sea Shells. :) -Nerseus
  14. Technically, as far as C++ is defined, false is 0 but true is any number except 0 (usually 1 in C++ or -1 in VB). But the single pipe is supposed to do bitwise ORs, such as when using enums with flags: [Flags] public enum Seasons { None = 0, Summer = 1, Autumn = 2, Winter = 4, Spring = 8, All = Summer | Autumn | Winter | Spring, } Seasons season = Seasons.Winter | Seasons.Spring; if((season & Seasons.Winter) == Seasons.Winter) { Debug.WriteLine("true"); } But if you try the following, it won't even compile (as I'd hope): int a = 4; int b = 7; if(a | b) ... -Nerseus
  15. Deciding when to use a Property verseus a function isn't always clear, but it will become clear over time. A good book will help explain their syntax (which is a good start), but only practice will let you know when and how best to use them. If you have a class to define a person, you might have an Age property and a Name property. You *could* define a method called GetAge() but it's generally bad practice. What makes it bad? Nothing but the fact that "professional" programmers call it bad - it's a standard to make code more readable and easier to understand (from your coding perspective and the from the perspective of the person using your class, even if you're both). A delegate is completely different. It's a way for you to define what a function will look like. I've used them in two ways (though more exist - depending on what you need). First, an event is a delegate. Meaning, a click event is basically a function that gets called when a click is made. The function is not known when the user created the control. So a delegate is used to say "I want to call a function that takes two parameters". The control can then raise this event (basically, just call a function) and call your code. Normally, you have code that calls a function that you know about. You call that function by name (if the function is named Test and it takes a string, you can use Test(string1) or Test(string1);). But in the case of events, the function being called isn't known but as long as it's known at runtime, ANY function can be called (as long as it's hooked). To get hooked, it MUST follow the exact syntax specified by the delegate definition. The other main use is to define your own function - or rather, what a function will look like. You can decide later what function to call. Suppose you have a function that takes a string and a DataSet and saves the DataSet. Before it can do the save, it needs to run a bunch of conversions on the data in the DataSet and the types of conversions are based on what the string contains. You could do this: private void DoAction(string code, DataSet ds) { bool result = false; if(code=="A") result =DoActionA(ds); else if(code=="B") result =DoActionB(ds); else if(code=="C") result =DoActionC(ds); if(result==true) { // Do something on success } else { // Do something on error } } private bool DoActionA(DataSet ds) { // Do some checking specific to action A } private bool DoActionB(DataSet ds) { // Do some checking specific to action B } private bool DoActionC(DataSet ds) { // Do some checking specific to action C } The above works fine. But, if you need to have an error handler in DoAction(), you might want/need to wrap it around the big IF. Or, you could write 3 error handlers, one for each call to DoActionX. You could also simplify it (simplify is a relative term :)) by using delegates. Take this example: private delegate bool DoAnAction(DataSet ds); private void DoAction(string code, DataSet ds) { // Create the delegate like any other variable DoAnAction action = null; if(code=="A") action = new DoAnAction(DoActionA); else if(code=="B") action = new DoAnAction(DoActionB); else if(code=="C") action = new DoAnAction(DoActionC); // Use the delegate as if you were calling any other function: try { bool result = action(ds); } catch{/* Do something */} if(result==true) { // Do something on success } else { // Do something on error } } private bool DoActionA(DataSet ds) { // Do some checking specific to action A } private bool DoActionB(DataSet ds) { // Do some checking specific to action B } private bool DoActionC(DataSet ds) { // Do some checking specific to action C } The above shows that you can create a delegate just like any other variable. It's constructor always takes a function name. Once created, you can call the delegate like any function only it will call the function you pointed to in the constructor. You can also create multicast delegates that automatically call multiple functions in ONE call. Events work this way since you might have multiple event handlers (for instance, when you see C# code that does "control1.Click += new ..."). I'd strongly suggest looking over a book and playing around with everything you read (don't just read through 3 chapters in one sitting). Playing around and tinkering with code is the best way to get familiar with (and remember) a language. -Nerseus
  16. And C# has some goofy syntax, just like VB. For example (just found this the other day). Normally you use one pipe (|) to do bitwise compare, and two pipes for logical boolean compares. So: bool a = true; bool b = false; if(a || b) { // Do something... } else { // Do something else... } But, we found out that in C# you can actually use one pipe for logical boolean compares (unlike C++): bool a = true; bool b = false; if(a | b) { // Do something... } else { // Do something else... } It's not big, but it's a little sloppy in that we had two different developers working on a form and each was using a different syntax for it. Good thing we do code reviews :) -Nerseus PS Yes, I know this has nothing to do with VB/C# differences. Just giving some fuel for the VB developers who get hit with (VB is sloppy, let's you do sloppy things, blah blah).
  17. My code is easy to read and efficient - but it's more of a means to ends than an art. Maybe the process of getting the code in the final state (production code) is an art. But that's more the process as an art (including debugging, UI design tweaking, etc.), not really the code itself. I've changed my mind over the years. Once upon a time I thought of it as sculpting - carving out a program using nothing but the IDE's text editor. Now I see it as more functional - a process more than art. But it's a fine line, in my opinion. I don't really care what it's called anymore (artist, programmer, developer, architect), as long as I have fun and the client loves it (more or less my two rules). -Nerseus
  18. Can you post the sample project you're using that loads a bmp from a resource? I'll see if I can't get the JPG to load. -Nerseus
  19. You'll have to use the Win32 API to measure the strings you want to output with DirectDraw's DrawText. I can't rememeber the exact function, but it's something like MeasureTextExtent or something like that. There's another thread on Drawing strings in DirectX in the Graphics forum. You should take a look there for a link on the problems with GDI+'s MeasureString. -Nerseus
  20. I would try using positive 1 for your SetNormal calls. You really want your normals to be normalized unit vectors. If you're not sure what that means, don't worry :) Just replace the "-1" parts of SetNormal(...) to "1". If all else fails, zip up your project (minus any binaries - the bin folder) and let us take a look. -Nerseus
  21. I hate to jump in so late, but saying that non-primitive types (classes, not structs) are always passed by ref is misleading. While it's true you can change the contents of a class when passed to a function, you can't change the original pointer to the class inside of the function. Meaning, a class variable (pointer) is passed by value - but just the pointer, not the contents of the class. So, if you have the following: // First, a function private void Test(Class1 c) { c = null; } Class1 c1 = new Class1(); // Call a function - pass by value Test(c1); // c1 is NOT null and the contents are still intact If the function Test were to modify any member variables in Class1, they WOULD show up as changed outside of Test() since only the pointer (c1) is passed by value. Structs are copied when passed to a function (unless ref is added to the parameter) so changing a value inside the function only changes that local copy. Of course, if the parameter is a class, you'll again be changing the actual class's contents. -Nerseus
  22. I would recommend using the API functions to measure text and draw text. You won't get the anti-aliasing features of GDI+, but you also won't encounter the known bugs that exist in .NET GDI+. -Nerseus
  23. I think you want to check the Tables.Count property first. Try something like: if myDS.Tables.Count = 0 Then Dim dr As DataRow Dim table1 As DataTable table1 = myDS.Tables.Add("Table1") for o = 0 to 18 ' I have 19 colums in the final tables table1.Columns.Add() next dr = table1.NewRow() for o = 0 to 18 dr(o) = "" table1.Rows.Add(dr) next o end if -Nerseus
  24. I've seen lots of little issues with Expression columns. I'm not sure what the problem is with yours, but I can offer one possible solution. Try clearing the expression column's value (setting the Expression property to string.Empty) before using HasChanges. I've written a function that loops through all columns of all tables in a dataset and saves out the Expression string if it exists. Then I perform my checks (I use an XmlDataDocument and get similar errors with expression columns), then loop back through the DataSet and restore the expression columns. An alternative would be to use a new object type, such as MS's . It's custom code but mimics a DataView that supports columns from different DataTables, through a relationship. -Nerseus
  25. First, let me check on a few things. Your select to fill the DataTable/DataView looks something like this: SELECT t1.Col1, t1.Col2, t2.Col1, t2.Col2 FROM Table1 AS t1 INNER JOIN Table2 AS t2 ON t1.Col1 = t2.Col1 or something like that - essentially two (or more) tables, joined together. Now you want to delete from Table1 only? You need to set the DeleteCommand of the DataAdapter to a statment that deletes from Table1. Something like: DELETE FROM Table1 WHERE Col1 =... Or whatever you need. If you're using the CommandBuilder, don't. Use it once to see the commands it builds then manually cut-n-paste the commands into the DataAdapter yourself. The CommandBuilder is good for simple updates only - anything even slightly complex and you're better off coding the commands yourself. -Nerseus
×
×
  • Create New...