Jump to content
Xtreme .Net Talk

PlausiblyDamp

Administrators
  • Posts

    7016
  • Joined

  • Last visited

Everything posted by PlausiblyDamp

  1. If you put a breakpoint in the ascx's codebehind does it get reached when the page loads?
  2. You can probably remove the OnClick = bit completely, that is not required for a server side event handler - it would be used to call a client side script when the button is clicked.
  3. Have you tried deleting the temporary folder like eramgarden suggested? It can be found at \Microsoft.NET\Framework\\Temporary ASP.NET Files
  4. Generally speaking you are better letting .Net manage the Garbage Collection process - it pretty much tunes itself to the available resources / memory usage patterns of your application and forcing a collection can interfere with this. If you really must for a collection then GC.Collect() forces a full gartbage collection which can take a long time to complete and also have the side effect that some resources may now take longer to be released than if you hadn't forced collection, trying something like GC.Collect(0) may be a bit easier on the system. A better plan is that if a class exposes a Close / Dispose method then calling that function when you are finished with the object will release critical resources, close the file / db connection / etc
  5. If you have access to the .wsdl file then you can generate a proxy class from the command line WSDL.EXE tool. e.g. WSDL /l:vb should generate a vb proxy class - if you omit the /l:vb then it will generate a C# version.
  6. There is a good chance that this is a permissions error - a web application runs as a user on your system called ASPNET and this user will need permission to the c:\temp folder.
  7. You will probably need to create a valid instance for each entry in the array for(int i=0; i{ box[i] = new Panel(); box[i]->BorderStyle = BorderStyle::FixedSingle; //etc. this is a bit of a guess based on C# - much easier than managed C++ ;)
  8. Have you also added a reference to the dll within your project?
  9. Which line do you get the error on? Alsowhat are the values for no_boxes and i when you get this error?
  10. When you backup both file groups to begin you also backup the log - this will cover all the data and clear all commited transactions from the log. If you make any further changes then these will be commited to the main database but will also exist in the log (this is the tail refered to in the error message). If you wish to restore the backup over the existing DB then this tail (remaining log) not being backed up causes the error, so you need to back this up using the NO_TRUNCATE option - this marks it as being backed up and doesn't remove it. Then you would restore each off the filegroups in turn specifying NORECOVERY - this prevents SQL from activating the DB and applying any remaining transactions from the logs. Now depending on if you want to restore up to the point after the first log backup but before the second, or to the point after the second you have two options. For the first case you could now restore the first log and specify RECOVERY and the DB should now be accesible. For the second case restore the first log specifying NORECOVERY and then restore the second log specifying RECOVERY - all updates should now be recovered.
  11. You could just use Dim fs As New FileStream("c:\1.txt", FileMode.OpenOrCreate)
  12. You may be better of using the .Net version of CurDir anyway System.IO.Directory.GetCurrentDirectory() 'or Environment.CurrentDirectory If the folders are always going to be relative to the running application's path then Application.ExecutablePath maybe a better choice.
  13. Can't believe the simple mistake I made before :( try this Panel *box[] = new Panel*[no_boxes];
  14. If you are using MS SQL then you cannot create a new column that doesn't allow nulls, what you could do though is add the column, update the existing data i.e. UPDATE Employees set newcolumn =1 where newcolumn is null and then change the column to not allow nulls and also provide a default if required.
  15. Guide to Object Orientated code in .Net This is a continuation of the series started in here and is preceded by this thread Introduction So far we have looked at creating a class that implements several OO concepts (Methods, properties, data hiding and overloading). In this article we will look at another feature � Constructors. Constructors One of the ideas behind OO code is that as much as possible we try to make code self contained and re-usable, one way to do this is to remove the need for people using our code to know how to initialise the internal data structures or require them to remember to call initialisation routines before using our code. In it�s simplest form a Constructor allows our class to do it�s own initialisation before the object is available to any calling code. The declaration of a constructor differs quite substantially between C# and VB.net. If we wished to perform some initialisation in our BankAccount class we could define a constructor as Public Sub New() _Balance = 0 _AccountNumber = 0 End Sub public BankAccount() { _Balance =0; _AccountNumber =0; } As you can see in VB we simply declare a Subroutine called New, while C# uses the C++ style of constructor declaration which uses a method named the same as the class name. Notice that if we want to be able to create an instance of our class the constructors need to be publicly accessible. If we do not declare any constructor then the compile assumes we wanted one that does nothing and would act as if we had declared a constructor like Public Sub New() End Sub public BankAccount() { } If you add the code above to the BankAccount class from the previous article and step through in the debugger you will notice the constructor is automatically called when we create a new instance � there is no way to call it directly. You may also notice that currently it doesn�t really do anything worthwhile as we can already initialise the variables at the point of declaration anyway. However there is one or two other things we can do with constructors to make them more useful. Parameters Just like normal methods constructors can also be passed parameters at run time. A better example than our simplistic one from above could be: Public Sub New(ByVal accountNumber As Integer) _AccountNumber = accountNumber End Sub public BankAccount(int accountNumber) { _AccountNumber =accountNumber; } Allowing us to pass in a valid account number, note if you remove the previous constructor and use the one just above and attempt a recompile it will now fail! The reason being to create an instance we are now required to provide an account number. The auto generated constructor I mentioned above is only generated if we provide no constructors at all, if we provide a constructor that accepts parameters and still require a constructor that doesn�t we need to provide both. To use the new constructor we need to change the way we create an instance of the class like so: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AccA = New BankAccount(1) AccB = New BankAccount(2) End Sub private void Form1_Load(object sender, System.EventArgs e) { AccA = new BankAccount(1); AccB = new BankAccount(2); } This now forces users of our class to provide an account number at the point of creation for the object. Overloads Like other class methods constructors can also be overloaded, for example we could chose to specify both an account number and an initial balance when we create a valid instance. Just like normal overloaded methods constructors can delegate part of the work to other versions, however yet again the syntax differs between VB and C# Public Sub New(ByVal accountNumber As Integer, ByVal initialBalance As Decimal) Me.New(accountNumber) _Balance = initialBalance End Sub public BankAccount(int accountNumber) { _AccountNumber = accountNumber; } public BankAccount(int accountNumber, decimal initialBalance) : this(accountNumber) { _Balance = initialBalance; } Note how in C# we simply add : this(accountNumber) to the end of the new constructor while in VB we call the New method directly. When we now create an instance of the BankAccount class we could use either the code provided above or alternatively provide a starting balance like: AccA = New BankAccount(1, 1000) AccB = New BankAccount(2, 500) AccA = new BankAccount(1,1000m); AccB = new BankAccount(2,500m); Again you may find it worthwhile to step through the code in the debugger to get a feel for how the constructors are called in sequence. ReadOnly variables As we have seen previously we can prevent external modification of internal values by exposing read only properties such as Balance, now we have provided a value for _AccountNumber we may want to expose this value to other code in the same way. Public ReadOnly Property AccountNumber() As Integer Get Return _AccountNumber End Get End Property public int AccountNumber { get { return _AccountNumber; } } This style has served us well so far � we provide read only access to the balance and all modifications must go through our provided Credit and Debit methods, however the AccountNumber has an additional feature � namely we do not want the account number to change at all once the class has be instantiated. Not only should it be treated as read only to external code but it should never be modified by other methods in the class either. This can be achieved under .Net by marking the variable as readonly when we define it Private ReadOnly _AccountNumber As Integer private readonly int _AccountNumber =0; this now results in a variable that can have a value provided at compile time and can be modified by a constructor, but no other code is allowed to alter the value at runtime; effectively the value we provide to the constructor is treated as read only once the constructor has exited and a valid instance of the class has been generated. Shared / Static Constructors Another thing to be aware of is that if our class contains shared (static in C#) data members that need initialising we can also provide a static constructor. Shared Sub New() �initialise shared data here End Sub public static BankAccount() { //initialise static data here } These cannot be parameterised nor do we have any control over when they are called � the framework will guarantee that they are called before the class is ever referenced but beyond that we have no control over when. Preventing construction A final thing to be aware of is that if you wish to prevent a class from ever being instantiated (e.g. System.Math or System.Windows.Forms.MessageBox) you can achieve this by creating a non-public default constructor and no publicly accessible ones. Private Sub New() End Sub private BankAccount() { } this can be useful if the class has no instance members or is never intended to be created from an external piece of code but by some internal mechanism. Playtime Again find attached a sample project containing working implementations of the above code. I suggest running the app and stepping through in a debugger to see how the constructors get called, you may want to alter the Form_Load and change the number of parameters being passed to see which Constructors get called. As a final exercise you may want to modify (or add) a method other than a constructor and attempt to assign a new value to _AccountBalance to see what the compiler will report. To Come Next will will look at Inheritance BankVB.zip BankCS.zip
  16. When it comes to doing the restore, before you restore the backups you need to backup the remaining log entries with code like BACKUP LOG TestFileGroup TO disk = 'C:\a\TestFG_log2.log' WITH NO_TRUNCATE --this bit is important Then when you do the restore you will need to add the command RESTORE LOG TestFileGroup FROM disk = 'C:\a\TestFG_log2.log' WITH RECOVERY this will restore the DB including the final change. If you wanted to restore to the point before the final update you will still need to execute the BACKUP LOG TestFileGroup TO disk = 'C:\a\TestFG_log2.log' WITH NO_TRUNCATE --this bit is important bit, but then change your original restore code to RESTORE DATABASE TestFileGroup FILE = 'TestFG_1', FILEGROUP = 'testfg' FROM DISK = 'C:\a\TestFG_1.mdf' WITH noRECOVERY RESTORE LOG TestFileGroup FROM disk = 'C:\a\TestFG_log.log' WITH RECOVERY
  17. You may find http://www.xtremedotnettalk.com/showthread.php?t=87770 sheds some light on the issue.
  18. At the top you have Public Class GameEngine Inherits GraphicsEngine Public Graphics As GraphicsEngine this means you are declaring a variable called Graphics of type GraphicsEngine later on you have While Graphics.GraphicsRunning = True 'This is the function wich again calls the Overridable Render() function.. Graphics.GraphicsRenderLoop() Application.DoEvents() End While in this code you are calling the GraphicsRenderLoop method of the Graphics object, within the Graphics object's GraphicsRenderLoop you are making a call to a Render method - because the variable Graphics was declared as type GraphicsEngine you get the GraphicsEngine's version of this method. If you want to call the overridden method declared in the GameEngine class then you need to declare a variable of Type GameEngine. However because your GameEngine class inherits from GraphicsEngine you do not need to declare a variable to access the GraphicsEngine's functionality. You should be able to declare the code within the GameEngine like Imports Microsoft.DirectX Imports Microsoft.DirectX.Direct3D Imports Microsoft.DirectX.Direct3D.D3DX Imports System.Math Public Class GameEngine Inherits GraphicsEngine Public Function Init(ByVal Target As System.Windows.Forms.Form) BackBufferWidth = 800 BackBufferHeight = 600 BackBufferFormat = Format.A8R8G8B8 BackBufferCount = 1 SwapEffect = SwapEffect.Copy PresentInterval = PresentInterval.One CreateFlags = CreateFlags.HardwareVertexProcessing Or CreateFlags.MultiThreaded DeviceType = DeviceType.Hardware GraphicsTarget = Target GraphicsInitDevice() 'This is the map object Map = New GraphicsMap Map.LoadMap(Device, "testmap") Player = New GraphicsSprite(Device, Application.StartupPath & "\objects\human1\human1.bmp", New Point(0, 0), 16, 16, &HFF00FF00) '//-------------------------------------------------- '// Different font types '//-------------------------------------------------- MessageText = New GraphicsText(Device, "Verdana", 8, FontStyle.Bold) MissionText = New GraphicsText(Device, "Verdana", 18) HUDText = New GraphicsText(Device, "Verdana", 22, FontStyle.Bold) While GraphicsRunning = True 'This is the function wich again calls the Overridable Render() function.. GraphicsRenderLoop() Application.DoEvents() End While Player.Destroy() Map.DestroyMap() End End Function Public Overrides Function Render() 'The message box wont pop up... MessageBox.Show("Inside the correct render function!!") End End Function End Class
  19. Use a TimeSpan like the example I showed in your other thread The timespan has a .Days property that will be the number of days.
  20. Sorry - mis-understood your problem. In your init method you are declaring a variable of type GraphicsEngine - so when you call render you will get the GraphicsEngine version of the function. What you need to do is declare a variable of type GameEngine: Public Function Init() Graphics = New GameEngine Messagebox.show("Init Success") Graphics.RenderLoop() End Function
  21. try Panel *box[] = new box*[no_boxes];
  22. You would use a timespan if you need to keep track of an arbitrary range of time (like the difference between two dates) Dim ts As TimeSpan ts = dt.AddDays(30).Subtract(Date.Now)
  23. That's by design. If you want to run the base version you need to call it from the overridden version. Public Overrides Function Render() MyBase.Render() MessageBox.Show("In overrides Render()") End Function
  24. You don't need to convert to strings to compare dates - just compare the dates: chk = (dt.AddDays(30) < Date.Now)
  25. That seemed to work pretty much as I would have expected - what problem are you having exactly?
×
×
  • Create New...