PlausiblyDamp
Administrators-
Posts
7016 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by PlausiblyDamp
-
Just add another constructor... Public Sub New(ByVal valName As String) Me.New(valName, "Default category name here") End Sub
-
Use the Color.FromARGB method 'something like txtFavorite.BackColor = Color.FromARGB(oRegKey.GetValue("FavoriteBackColor"), Integer)
-
The problem is probably the message box, services do not interact with the current user's desktop but have one of their own - the message box is not visible and the service will block till you hit OK. Try writing to the event log instead me.EventLog.WriteEntry("sdf") should do the trick. The second problem is that the on Start method should exit fairly promptly - normally you would launch your 'real' work on a new thread and then let the OnStart exit. If OnStart doesn't complete in a timely fashion then the OS will think it is hung and terminate it.
-
Easy option for you - if you have the service open in the designer (not the code window), right click on it and select the 'Add Installer' menu option, rebuild and try again.
-
Mskeel - I wasn't suggesting that using any function or operator in itself was a bad thing, however when using something in a really non-intuitive way because is can save a clock cycle or two, but needs several minutes / hours of debugging to figure out what it is supposed to do is not a good thing. At the very least this kind of thing demands comments explaining why this method was chosen and acceptable ranges etc. Just how slow was the + operator that using XOR gave any performance benefits. Also take into account the fact that it doesn't seem to be doing an XOR anyway - XOR the ASCII bit pattern for B and then use the above code with a B and compare the results. This has got to make you wonder if this has ever been properly tested or thought through - did somebody try this with the letter A and it worked? Knowing that XOR is faster did they realise that they had hit on a wonderful optimisation and not even try another letter to prove their theory? Sometimes developers 'being clever' can cause a lot more problems than they fix and using odd tricks in a language can seriously hurt if you need to port to another language or these issues are resolved in a later version...
-
Pure luck 65 in binary XOR 50 in binary is 1000001 = 65 0110010 = 50 XOR Gives: 1110011 = 115 Would love to see the rest of the code though as this wouldn't work on many numbers (or letters) try it with "B" for example it returns 112) I get the feeling this could be someone optimising their code to the point of being unmaintainable...
-
If you just wish to store configuration information then you may want to investigate dynamic properties or just use the configurationSettings Class directly in your code.
-
Would something like Array.Copy(baBuff, 0, baData, 0, DataPointer); not work?
-
Attached a simple project to show how you can use .Net's built in XML serialisation support to handle reading the file structure I posted above. Just step through the code and keep your eye on the contents of the variable s just before the End Sub statement. WindowsApplication6.zip
-
Why not create a schema that allows multiple IO elements? COM2 19200 COM4 4800 If you are having problems with a particular piece of code or way of dealing with the XML post it here and see if you can get more specific help.
-
Set(ByVal Value As Integer) testint=value MsgBox("setting a value " + Str(blah)) End Set
-
As a rule if a variable is only needed inside one procedure declare it in that procedure rather than the class level, declaring things with a greater scope can cause problems later if two functions just 'happen' to both use the same variable name. A rectangle is a value type anyway and so will not be the garbage collectors problem, value types are allocated on the functions stack and cleaned up as the function exits. Only reference types (classes) will need to be disposed and even then they will be the exception rather than the rule. In most scenarios just let the garbage collector do it's stuff and don't worry. The only time you will normally need to get involved is if the class encapsulates an 'expensive' resource (db connection, file handle etc.)
-
Quick and easy way... Private Enum Test Apple Orange Lemon Pear End Enum Private Sub TestMethod() Dim t As Test t = System.Enum.Parse(GetType(Test), "Lemon") MessageBox.Show(t) End Sub
-
Just found this link tells you how to add UnReal Scripting syntax support to VS.Net (download a .reg file from the page) - I assume the idea is the same for all languages.
-
If you are working with classes then you are only passing references to the in memory structures anyway, only value type objects (Structures) will cause copies to be created. Although pointer manipulation can be faster you need to weigh up 'how much faster' against 'effort to get it right'. Using pointers may be quicker than a foreach loop over an array or collection - but unless profiling indicated this was a bottleneck and causing appreciable problems I would stick with the foreach loop every time. Also you need to be careful of getting too clever when doing optimisations at the ASM level under windows as you may not see the overall effect of the tweaks you are doing; for example: although forcing a pointer into a register can give better performance - you are potentially hurting the performance of other aspects of your app / system. (IIRC most C/C++ compilers treat the register keyword more as a hint than a command anyway.) Although the .Net JIT is still in it's infancy it does do some optimisations and it's ability to do so will improve with time - certain issues in the 1.x version have been / are being addressed in the 2.x version.
-
If you wish to see if IIS is running and the web service is as well then search for "W3SVC" rather than "IIS" as a service name. alternatively "IISADMIN" will tell you if the IIS admin service is present.
-
Need help on Crystal Report for .Net deployment.
PlausiblyDamp replied to Cell's topic in Deployment
http://www.xtremedotnettalk.com/showthread.php?t=89293&highlight=keycode http://www.xtremedotnettalk.com/showthread.php?t=70273&highlight=keycode -
How the GC decides an object is suitable for collection is a little bit more complicated than just variable references. Each application has a series of 'roots' - global variables, local references, en-registered variables; each of these would keep an object alive. Only guessing here but I would imagine that as the form process a windows message pump windows itself is acting as a root for the variable.
-
Just add a notifyicon control from the toolbar and give it an icon.
-
Generally I would just create a class to encapsulate the user settings and use the built in XML support to serialize it. Too be honest in this respect a fairly readable output is generated with minimal effort on my part, plus if I so desired I could have more control over the output without having to get involved in the actual writing of the output. As to where I would either use the users roaming profile for an application that was being deployed somewhere I knew the security requirements would allow this or use IsolatedStorage if there was any doubt about the capabilities to access the file system. (admittedly IsolatedStorage may also be unavailable but it offers a reasonably safe alternative) Security is another reason I would stay clear of using the registry - a partially trusted application may not have permissions to read and write to the registry but may still have permission to use isolated storage. Sample now attached, ignore the utter lack of error handling, no option strict etc as I was in a rush ;) You will find the settings saved somewhere under you Documents and settings folder (C:\Documents and Settings\Instructor\Application Data\IsolatedStorage - on this PC) SaveSettingsSample.zip
-
IIRC Microsoft's C++ compiler does have a __forceinline (or similar) instruction which always inlines the code - can be useful if you do not want code to be in one single location (think serial number validation etc). I remember reading on some MS blog or other that they are working on improving the JIT compiler in regards to what it can inline as well as making it look at larger methods as candidates for inlining (wish I could remember where I read it though...), guess we just have to sit and wait to see what happens.
-
Don't use the Windows.forms.Keys enumeration in place of ascii characters, it reports the keyboard scan code not the ASCII character. Use either the syntax I posted above or the solution offered by marble eater - they will work with embedded quotes correctly. Rather than using mid you may want to look at the .SubString method of your string variable, also remember the indexes into the string are 0 based, if you want to start at the 4th letter for example you need to specify a start index of 3.
-
Guide to Object Orientated code in .Net This is a continuation of the series started in here and is preceded by this thread Introduction In the previous article we looked at how we could use inheritance to simply the creation of a SavingsAccount class, which contains additional functionality over the BankAccount class, with minimal need to duplicate code and no requirement to alter existing code to work with the new class. The ability to extend a class in this way can be very useful when developing software, however the ability to change how a derived class implements methods defined in the base class can be very powerful. Imagine our fictitious bank wishes to impose a 1% surcharge on all withdrawals made on Savings Accounts, what we would like is to be able to make this change without having to rewrite existing code that uses our BankAccount and SavingsAccount classes. A Solution? In a more traditional procedural application we would need to implement this logic at any point where we debit an account � this includes the user interface response to button clicks, the Transfer method etc. The problem with this approach is similar to the problem we encountered with the Transfer method � every time a new class with a different Debit requirement is added existing (and hopefully working & tested) code will need to be modified, possibly introducing bugs or breaking existing functionality. Rather than take this approach it would be better if we could allow each class to be responsible for its own debit method. If we simply try to give the SaviningsAccount class another Debit method Public Sub Debit(ByVal amount As Decimal) End Sub public void Debit(decimal amount) { } we get a compiler warning regarding a conflict with the base class� Debit method and a suggested fix (adding the keyword Shadows in VB or new in C#), if we follow these instructions then the compiler warning will indeed go away. Public Shadows Sub Debit(ByVal amount As Decimal) End Sub public new void Debit(decimal amount) { } However in either case VB will give a compile time error regarding the conversion from String to Decimal. This error is a result of what the keyword Shadows does � it effectively hides any methods of the same name defined in the base class, therefore the compiler no longer sees the two overloaded versions defined in BankAccount. In C# the new keyword behaves slightly differently as it only hides the Debit method with the same signature � not all Debit methods. The end result is that if we have a variable declared as type BankAccount calling Debit will use the BankAccount version. If the variable is of type SavingsAccount then it uses the version defined by the SavingsAccount class. However if this code (C# version anyway) is run a new problem comes to light, namely that the Transfer method declares it�s parameters as being BankAccount � when it debits the accountFrom it will use the version defined in BankAccount and not our new implementation. This is a limitation that can easily be overcome; we just need to indicate what our intention is to the compiler. Polymorphism revisited Most OO languages (.Net included) provide a mechanism to allow a derived class to re-implement a method provided by the base class without needing unnecessary code duplication. Under .Net we need to state when we need this capability - we do this through the Overridable and Overrides keywords in VB or virtual and override keywords in C#. Firstly we need to modify the BankAccount class to indicate our intention. Public Overridable Sub Debit(ByVal amount As Decimal) _Balance -= amount End Sub public virtual void Debit(decimal amount) { _Balance -= amount; } and then create a new Debit method in the SavingsAccount class to perform the modified Debit. Rather than duplicate code we will just call the base class� method to perform thee �real� update � we will just perform a slight modification in the derived class. Public Overloads Overrides Sub Debit(ByVal amount As Decimal) MyBase.Debit(amount * 1.01D) End Sub public override void Debit(decimal amount) { base.Debit(amount * 1.01m); } Notice how we use the MyBase and base keywords to call the BankAccount�s method; all we do here is add a 1% charge to the amount being withdrawn. Benefits Gained Notice that as well as removing the compiler warnings this has also cured the error generated by VB, we now get a clean compile. However the biggest benefit we have gained is found by looking at the Transfer method, even though the parameters are both declared as being BankAccount if we transfer funds from a SavingsAccount (B to A in the attached project) the 1% charge is applied. Also of note is the code executed behind the button click events; both Debit buttons call the overloaded method that takes a string parameter. This method is declared in the base class and was not duplicated in the derived class; however its functionality is still available and is automatically used when a string is passed in. The usefulness is a lot more apparent if you can see the code in action, run the attached sample and step through the code for the debit and transfer buttons. Try changing the variable declarations and types for AccA and AccB, try creating a 3rd account class and overriding it�s debit method to debit with a surcharge that is only applied after 3 debits. BankCS.zip BankVB.zip
-
Dim sw As System.IO.StreamWriter = System.IO.File.AppendText("") sw.WriteLine("text to append here") sw.Close()
-
The JIT compiler will inline routines if it thinks there is a benefit, there is not way to influence it's decision through code. (Then again in C/C++ the inline keyword is fairly redundant as most compilers ignore it and make the decision themselves anyway). C style #define macros are not supported (thank god) in either VB or C#. IIRC there are some issues with how the JIT decides when it can / can't inline (these are being addressed in the 2005 as far as I am aware) but unless you are experiencing performance issues with this code I wouldn't be overly worried.