Jump to content
Xtreme .Net Talk

Cags

Avatar/Signature
  • Posts

    699
  • Joined

  • Last visited

Everything posted by Cags

  1. I used to use a Visual Studio 2003 addin called Project Line Counter. This seems to have alot of issues however as it keeps disappearing from the toolbar. I think it might not like the fact I often run several instances of VS at the same time. I was wondering if anybody could suggest a tool that can count code lines, comment lines, comment/code lines etc.
  2. As far as I can tell your code will read a file and work as you intend it. Whilst it does somewhat limit you in terms of adding more items, if that isn't a requirement I guess it doesn't matter. Since you've obviously had a go heres the way I would have done it (I just got up, hope it makes sense). Dim reader As New StreamReader(myFile) Dim xmlDoc As New XmlDocument Dim line As String xmlDoc.Load(xmlFile) line = reader.ReadLine() Do While (line IsNot Nothing) ' I'll go ahead and assume these lines of code successfully extract a city and a zip code Dim myCity As String = line.Substring(6) ' Returns City or Town Dim myArr() As String = Split(line, " ") Dim myZip As String = myArr(0) ' Returns ZipCode Dim foundCity As Boolean = False ' loop through nodes For Each myNode As XmlNode In xmlDoc.DocumentElement.ChildNodes ' ' check if its the right city node If myNode.Attributes("name").InnerText = myCity Then ' ' since we have the right node add the zip node Dim zipNode As XmlElement = xmlDoc.CreateElement("Zip") zipNode.InnerText = myZip myNode.AppendChild(zipNode) ' add the zip to that citys node foundCity = True ' store the fact the city was found Exit For ' some say this is bad practice, but its the simplest way to prevent loop finishing ' End If ' Next ' if the city wasn't found If (Not foundCity) Then ' ' create the city node Dim cityNode As XmlElement = xmlDoc.CreateElement("City") ' create node Dim nameAttr As XmlAttribute = xmlDoc.CreateAttribute("name") ' create attribute nameAttr.InnerText = myCity ' populate attribute cityNode.Attributes.Append(nameAttr) ' add attribute ' create the zip node Dim zipNode As XmlElement = xmlDoc.CreateElement("Zip") zipNode.InnerText = myZip cityNode.AppendChild(zipNode) ' add the zip to that citys node ' add node to document xmlDoc.DocumentElement.AppendChild(cityNode) ' add city node to doc ' End If line = reader.ReadLine() Loop reader.Close() xmlDoc.Save(xmlFile)
  3. You pretty much have the code you need, just in the wrong order. You say your struggling to find out if the city node is present yet your code already does it. For Each myNode As XmlNode In xmlDoc.DocumentElement.ChildNodes If myNode.Attributes("name").InnerText = myCity Then ' here its found End If NextThis code checks for the city node, if your code reaches the ' here its found comment, then myNode is the city node you are looking for. From there simply add the zip node to it, you can also store a boolean as true so that when you exit the loop you know it was found. After the loop you check that boolean state, if its true your jobs done, if its not you need to add the city node (as it wasn't found) and then add the zip node to that new city node. I could write the full code out for you, but I fear if I did you wouldn't learn much from it.
  4. Whilst its true it adds lines of code which can in turn lead to errors, changing the Stucture to a Class could be catastropic on the application in the short term. It is quite likely that elsewhere in their code TheWizardofInt has statements that would function differently if the value type is changed to a reference type.
  5. Equals is a method that checks if the calling objects value is the same as the value passed in as a parameter. Thus you are not actually assigning anything with that line of code. In theory the correct line of code would be Class.sVariable.bVisible = True; But this won't work because you cannot assign a value to the child of a value type in this manner. You will either have to change the structure to a class or you will have to create a new instance of the structure with the required fields set and assign sVariable as equal to that.
  6. Well firstly you are appending the cityNode to the document before evening checking if it already exists. This should be done after the loop, and only if the node wasn't already found. Secondly inside the for loop you are attaching the Zip node to the cityNode element, when in fact you should be adding it to myNode because as your loop just checked myNode is the node for that city.
  7. Yes I believe so. At least this is something that I adjusted to doing not long after learning c#. If nothing else it makes objects easier to track.
  8. I really have no idea what your looking for here? Using an objects .SuspendLayout and .ResumeLayout you can prevent flickering of controls. You call .SuspendLayout before removing/adding anything, then .ResumeLayout when everthing is added/removed. Does this help?
  9. I have an application for Pocket PC that allows user input through the hardware keys. My form has a single control on it, which in turn has several controls on. As far as I can work out pressing the hardware keys always triggers the KeyEvents of the main form, not the child (at least it has in all my tests). In order to keep my application segmented I want the control to handle these events. The way I'm doing it currently is to add a public method to the control which accepts the KeyEventArgs as a paramter and then just call this method from the forms KeyEvent (one method for each keyevent I wish to use i.e KeyDown, KeyPress etc etc). Is this the best way forward or am I missing a more OOP method.
  10. Granted relativity was a bad example. I obviously wasn't thinking straight. But that doesn't negate the fact that science, especially in the past has, contained many dirty hacks in an attempt to cling onto outdated thinking. Given the apparent improbabilty of human life, its hard to believe that anythings impossible. Oh, whilst reading back over the posts I also noticed this.. You've got to love the apparent pompousness in that statement.
  11. I've been working on what is essentially a sliding block game for Pocket PC. My game has a few alternative modes to simply sliding however which is causing me a few nightmares. My game has gone through several iterations in terms of 'Graphics Engines' but as usual I'm still not happy and keep changing it. All you really need to understand is a square 'Board' consists of 'Tiles' (currently max size is 5x5). These tiles can move about in allsorts of various manners. Each square will end up on another square when it is moved, but various modes will have animated slides so the tiles do overlap for a time. These are the methods I've tried. 1. Using Controls is the easiest method, once each tile is drawn it can be moved about without redrawing anything. When an effect needs to be added to every tile however you can see each tile refresh independtly (generally only the tiniest delay between, but it bugs me). 2. Using the Graphics objects and GDI+ I wrote a method that redraws all tiles to a backbuffer then the backbuffer to the screen, this works rather slow however and makes animations very slow and not at all smooth. Each idea I have only seems to be perfect in certain situations. The sliding puzzle for example works fine with GDI+, because I can tell it to only draw certain squares. I could do the same with other modes but calculating which squares when they all interact would be far more difficult, and moves away from a standardised Graphics Engine and essentially creates a seperate one for each game mode. I've also considered replacing the Graphics object by using GDI, but I'm not sure if it will be worth the effort. Basically I'm wondering if anyone has any suggests on the best way to proceed.
  12. It's important not to confuse the reality of physics with our understanding of physics. Quick and dirty hacks are not as unusual as you might think in our understandings of physics. This is why we ended up with the general theory of relativity and the special theory of relativity. Einstien came up with a theory, it was discovered that sometimes this theory wasn't sound, so he tacked another theory on to explain these situations. Ok this process wasn't neccessarily quick or dirty, but still. It is worth noting that I'm presenting arguments here as a devils advocate, not neccessarily because I disagree. Random fact:- When asked if he carried a notebook to take down his ideas Einstien replied 'No, I dont have enough of them'.
  13. Over the last few days I've been begining to believe that my PC is involved in an elaborate plot to finally push me over the edge and go insane. I'm writing an xml file with this code... XmlTextWriter writer = new XmlTextWriter(path, System.Text.Encoding.UTF8); writer.WriteStartDocument(); writer.WriteStartElement("Settings"); writer.WriteElementString("Difficulty", Difficulty.ToString()); writer.WriteElementString("MyType", MyType.ToString()); writer.WriteElementString("AnimationType", AnimationType.ToString()); writer.WriteElementString("UserImagePath", UserImagePath.ToString()); writer.WriteElementString("InternalImagePath", InternalImagePath.ToString()); writer.WriteElementString("UserImage", UserImage.ToString()); writer.WriteElementString("DrawIndex", DrawIndex.ToString()); writer.WriteElementString("DrawGrid", DrawGrid.ToString()); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close();The xml file looks like this... <?xml version="1.0" encoding="utf-8" ?> <Settings> <Difficulty>Hard</Difficulty> <MyType>Slide</MyType> <AnimationType>None</AnimationType> <InternalImagePath>Images.image1</InternalImagePath> <UserImage>False</UserImage> <DrawIndex>False</DrawIndex> <DrawGrid>True</DrawGrid> </Settings> I'm reading it in with this code... XmlTextReader reader = new XmlTextReader(path); while(reader.Read()) { System.Windows.Forms.MessageBox.Show(reader.NodeType.ToString() + "," + reader.LocalName); if(reader.NodeType == XmlNodeType.Element) { if(reader.Name == "Difficulty") { string text = reader.ReadInnerXml(); System.Reflection.FieldInfo fi = typeof(PzlDifficulty).GetField(text); Difficulty = (PzlDifficulty)fi.GetValue(null); } else if(reader.Name == "MyType") { string text = reader.ReadInnerXml(); System.Reflection.FieldInfo fi = typeof(PzlType).GetField(text); MyType = (PzlType)fi.GetValue(null); } else if(reader.Name == "AnimationType") { string text = reader.ReadInnerXml(); System.Reflection.FieldInfo fi = typeof(Animate).GetField(text); AnimationType = (Animate)fi.GetValue(null); } else if(reader.Name == "UserImagePath") { UserImagePath = reader.ReadInnerXml(); } else if(reader.Name == "InternalImagePath") { InternalImagePath = reader.ReadInnerXml(); } else if(reader.Name == "UserImage") { UserImage = bool.Parse(reader.ReadInnerXml()); } else if(reader.Name == "DrawGrid") { DrawGrid = bool.Parse(reader.ReadInnerXml()); } else if(reader.Name == "DrawIndex") { DrawIndex = bool.Parse(reader.ReadInnerXml()); } } } reader.Close();This is the output from the messagebox... XmlDeclaration,xml Element,Settings Element,Difficulty Text, EndElement,MyType Element,AnimationType Element,InternalImagePath Text, EndElement,UserImage Element,DrawIndex Text, EndElement,DrawGrid EndElement,Settings Did I miss some logic behind the structure of xml? Any suggestions?
  14. What exactly do you mean by a control that can act as a container? I would assume by this you want a control that can be used at design time similar to a panel? I've never tried it, but I would suggest writing a control that inherits ContainerControl.
  15. I hate to disagree (well actually I don't but still :)), but I don't think you pooped on anyones parade, you just disagreed with us.
  16. As you say marble_eater drawing lots of small images is really slow which is what I have been doing. With more calculations it would undoubtably be possible to increase my performance using GDI+, but I decided to have a go at writing my own wrapper. DrawString is also horrendous in terms of speed. I have a few questions about the best way to proceed with a game I'm working on. I'll probably make a seperate thread about it tomorrow.
  17. Because quite frankly its too slow, I was testing out the API method to see how much of a performance boost I could get.
  18. Cags

    2005 Question

    I suspect its Visual Studio 2005 Express.
  19. Took me awhile to track this down. But as far as I can tell the Refresh method of Control objects seems to function differently in the .Net Compact Framework 1.1 to the full .Net Framework 1.1. When calling Refresh it doesn't appear to call Refresh on its child objects, hence they don't update. I think the only way to get around this may be to override the Refresh method and loop through the children calling Refresh. It seems weird that I only found one reference to this issue by searching google. The only solution offered was by the person who found the issue, saying they used a loop. I just thought I'd post it so theres at least another reference to this issue for anyone else searching. I guess I'm not really expecting an answer, but if somebody can think of a reason please let me know.
  20. The fact is that many scientific 'facts' aren't set in stone they are just our current understanding. Many things accepted as fact are based on very loose interpretations and should be refered to more correctly as 'Theories'. Now based on current theories, the transfer of data through quantum entanglement is impossible. It is always possible of course that by this time next week a new discovery will have been made that will prove mskeel's theory possible, i.e. controlled quantum entanglement. The fact is if everyone subscribed to all current theories, alot less scientific advancement would have been made. Scientists once claimed that it was impossible for a Bee to fly. This falacy was caused by a simplified model that represented the Bee as having fixed wings like an aircraft, failing to take into acount the extra lift afforded by 'flapping'. If it wasn't for the fact people had seen Bees flying, this could have forever been accepted as fact. Incidently this is one of the problems involved with identifying extinct creatures.
  21. Showing some code might have been helpfull so we can see exactly whats going on. I suspect your problem is this. The OnLoad method is only called when the page is first loaded not everytime you call a forms .Show() method. Thus whenever you are creating the form and then calling Show() the OnLoad event is triggered. But if the object it already Initialised the OnLoad event isn't triggered.
  22. Inheritance public class ClassName : InheritedClass { } // Example public class OptionsForm : System.Windows.Forms.Form { } Public Class [i]ClassName[/i] Inherits [i]InheritedClass[/i] End Class ' ' Example Public Class MyForm Inherits System.Windows.Forms.Form End ClassMore information about Inheritance can be found in PlausiblyDamps tutorial Intro to Object Orientated Programming Part 2 - Simple Inheritance and Constructors Properties private ObjectType localVariable public ObjectType PropertyName { get { return localVariable; } set { localVariable = value; } } // Example private string _name; public string Name { get { return _name; } set { _name = value; } } Dim [i]localVariable[/i] As [i]ObjectType[/i] Public Property [i]localVariable[/i]() As [i]ObjectType[/i] Get Return [i]localVariable[/i] End Get Set(ByVal Value As String) [i]localVariable[/i] = Value End Set End Property ' ' Example Dim _name As String Public Property Name() As String Get Return _name End Get Set(ByVal Value As String) _name = Value End Set End PropertyMore information about Properties can be found in PlausiblyDamps tutorial Intro to Object Orientated Programming Part 2 - Properties Constructors public class ClassName { public ClassName() { // this is the constructor without parameters } public ClassName(ObjectType variableName) { // an overloaded constructor accepting parameters } } // example public class Person { public Person() { // this is the constructor without parameters } public Person(string pName) { // an overloaded constructor accepting parameters } } Public Class [i]ClassName[/i] ' Public Sub New() End Sub ' Public Sub New(ByVal [i]variableName[/i]As [i]ObjectType[/i]) End Sub ' End Class ' ' Example Public Class Person ' Public Sub New() End Sub ' Public Sub New(ByVal name As String) End Sub ' End ClassMore information about Constructors can be found in PlausiblyDamps tutorial Intro to Object Orientated Programming Part 2 - Constructors
  23. Igor Sukhov is correct. I believe the default seed for the Random object is the TickCount it was created on. Since all your objects are probably created at the same time, they all have the same seed. Thus given a standard algorithm to calculate a random number they will all follow the same sequence. You would be better storing the Random object so that it is globally accessible, whether this be through static (shared) declaration or by reference. That way each object will call Next() getting a differen't number.
  24. Entangled pairs to the best of my knowldege have only been witnessed performing equal and opposite reactions hence this 'qbit' would infact be the opposite.
  25. I'm sorry but the question begs to be asked here, did you actually try and do it yourself? It's not that I'd mind helping, but the solution to this is practically identical to the question about updating a node which we helped you with in davearia's thread. This is the logic behind what you need todo.. 1. loop through text file 2. if city node exists add zip node to it 3. else add city node 4. add zip node to new city mode The code you posted goes straight from 1 to 3 without even attempting 2. As you will see if you look back at that update question, this is a very similar problem. If you have trouble implementing then don't hesitate to ask questions about your code.
×
×
  • Create New...