Jump to content
Xtreme .Net Talk

Bucky

*Experts*
  • Posts

    803
  • Joined

  • Last visited

Everything posted by Bucky

  1. How do I throw an Exception in a method of a class and have it travel upwards until it reaches an error handler? In other words, I want the method to raise an error and the method's caller to handle the error. Currently I have the method call surrounded in a Try...Catch block, but when I Throw the error in the method, the error occurs inside the method itself. If this isn't possible, should I just have an Error event and raise the event when an error occurs? Thanks
  2. Since the .NET framework was released after Office 2000 (and XP, I believe), the VBA in these versions most likely does not support .NET add-ins. In fact, the only thing I know of that supports .NET add-ins and VBA is Visual Studio .NET itself.
  3. I believe that VC may be Visual C++. For what language are you creating the project?
  4. The Paint event is the correct event to paint in. The WithEvents keyword goes in the Form1's declaration. The declaration also has to be outside any methods, in the General Declarations section of a class. Dim WithEvents myForm As New Form1() To create an event handler for the Paint event, you'd have a sub declaration like this: Private Sub myForm_Paint(sender As Object, e As PaintEventArgs) Handles myForm.Paint
  5. I don't know about anyone else, but those VB code tags look awfully tiny on this theme (Lite). The regular code and quote tags are okay, but the rest are too small... smaller than before, at least.
  6. In a word, no. Window transparency is only supported on Windows 2000 and XP, whether you use the windows API or a form's Opacity property.
  7. It certainly is a wild question, considering that everything you need to know about classes can be found in the help collection that comes with VS.NET and the .NET Framework SDK, and in the Object Browser in VS.NET (View -> Other Windows -> Object Browser). Also, if you need help on a specific class in some code, place the caret on that class name and hit F1.
  8. Bucky

    Macros

    How do you write humorous C# code? :D
  9. Bucky

    Macros

    You may also want to look into Addins. You can create an addin project from the New Project dialog, and then you can have VS.NET load this addin on startup. A wizard will set up the project for you. divil, I didn't know the class viewer did that. Thanks for the info.
  10. The top line of your ASPX page should state that the code you're using is VB, not VBScript. This may fix the problem. <%@ Page Language="vb" %> If that does not fix anything, I'm afraid I don't know what could be wrong. Everything looks declared to me. :-\
  11. Sorry to dig up this thread, but I'm having the same problem, only with trying to open a file for reading. How do I change the IIS settings to allow file reading?
  12. The XML Schema (.xsd) is just an outline for an XML file, telling how nodes and attributes should be applied. The XSD file does not actually hold any data. The XML file that uses this schema is what contains the data. Instead of using the ReadXmlSchema() method, try the ReadXml() method.
  13. You will need the XslTransform class to transform XML files with XSLT. It is found in the System.Xml.Xsl namespace. The Transform() method is overloaded several ways. Read all about it (with examples) in the documentation: [mshelp]ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemxmlxslxsltransformclasstopic.htm[/mshelp] If you go to "XslTransform Members," and then click on the Transform method, all the overloaded versions will be listed.
  14. Well VS.NET does not actually do the compiling itself... instead it uses the command-line tools that come with the .NET Framework SDK. This is installed along with VS.NET. I'm not familiar with these tools, but the ".NET Framework SDK" section of the documentation has explanations for how to use them. Here it is for VB: [mshelp]ms-help://MS.VSCC/MS.MSDNVS/vblr7/html/vaconBuildingFromCommandLine.htm[/mshelp] And C#: [mshelp]ms-help://MS.VSCC/MS.MSDNVS/cscomp/html/vcgrfBuildingFromCommandLine.htm[/mshelp]
  15. ASP.NET uses compiled code, unlike classic ASP which is interpreted from the .asp page at runtime. Whenever you make changes to the code-beind page or in code blocks inside the ASPX page, you need to compile the project and then upload the DLL's found in the /bin directory.
  16. There are several ways you can do this. If ALL you want to show up is asterisks, no matter what, then set the PasswordChar property of the TextBox to "*", and then any character in the textbox will be represented by a *. If you want to change the text in the textbox later to show some actual letters, then you can use the String's constructor to deuplicate the * character a certain number of times. ' Method #1: txtWord.PasswordChar = "*"c txtWord.Text = myWord ' Method #2: txtWord.Text = New String("*"c, myWord.Length) Or, in C#: // Method #1: txtWord.PasswordChar = '*'; txtWord.Text = myWord; // Method #2: txtWord.Text = new string('*', myWord.Length);
  17. I ran the code on my computer just fine... which line is the error occuring on?
  18. As it turns out, you need to cast the result from GetElementsByTagName to an XmlElement, because the result is the more generic XmlNode, which could be an element, an attribute, or anything. So, here we go: using System.Xml; // Stick this line at the top of your code file XmlDocument doc = new XmlDocument(); // Load the file doc.Load(fileName); XmlElement appearanceElement = (XmlElement)doc.GetElementsByTagName("Appearance")[0]; XmlElement titleColorElement = (XmlElement)appearanceElement.GetElementsByTagName("TitleColor")[0]; // Get the string inside the TitleColor node string titleColorText = titleColorElement.InnerText; // Convert the color name to a Color class Color titleColor = Color.FromName(titleColorText); // Now let's change that color to red titleColorElement.InnerText = "Red"; // Save the file doc.Save(fileName);
  19. Hmm, I've never considered the speed and memory required for serialization... I'm afraid I don't have enough knowledge to answer your question. If they both turn out to be memory and resource hogs, I'd go for serialization because it is much easier to use.
  20. Ah, I'm terribly sorry... You should use GetElementsByTagName(), which returns an XmlNodeList. Since you will only have one Appearance element (I'm assuming), you can just get the first element in the list returned and use that. So chose lines should be as follows: // Get the string inside the TitleColor node string titleColorText = doc.GetElementsByName("Appearance")[0].GetElementsByName("TitleColor")[0].InnerText; // and... // Now let's change that color to red doc.GetElementsByName("Appearance")[0].GetElementsByName("TitleColor")[0].InnerText = "Red";
  21. Another thing I noticed is that keywords in the C# tags are not colored if they immediately follow a comment line: // This is a comment, yo string blah; string anotherBlah;
  22. The XML Document Object Model (DOM) can be accesed through the XmlDocument class, found in the System.Xml namespace. With the XmlDocument class, you can read and write nodes, attributes, and all kinds of juicy stuff. The class requires a lot of overhead, however, and for the situation you're describing you may want to have a look a XML Serialization: [mshelp]ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemxmlserializationxmlserializerclasstopic.htm[/mshelp] [mshelp]ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemXmlSerialization.htm[/mshelp] But in the meantime, you can load the XML file into an XmlDocument class, read nodes, change them, and write back out to the file, although with serialization you don't need any of this code; the .NET framework takes everything and sticks it in the properties of classes which you can use right away. Here, fileName is a string containing the path of the XML file. The value of the TitleColor node is stored in the string titleColorText, then converted to the Color class titleColor by using Color.FromName(). Finally, the TitleColor is changed to red and the file is saved. using System.Xml; // Stick this line at the top of your code file XmlDocument doc = new XmlDocument(); // Load the file doc.Load(fileName); // Get the string inside the TitleColor node string titleColorText = doc.ChildNodes["Appearance"].ChildNodes["TitleColor"].InnerText; // Convert the color name to a Color class Color titleColor = Color.FromName(titleColorText); // Now let's change that color to red doc.ChildNodes["Appearance"].ChildNodes["TitleColor"].InnerText = "Red"; // Save the file doc.Save(fileName); For more info: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvssamp/html/vbcs_WorkwithXML.asp
  23. Well, if you really insist on calling the ReadToEnd() method 100 times, you actually can call it more than once. The Stream that the StreamReader is reading has a Position property, which gets or sets where the Stream is read from. After calling ReadToEnd(), set the Stream's Position property to 0, and then you can call ReadToEnd() again. If the Stream class that you created is not readily accessible, you can refer to it in the StreamReader's BaseStream property. So... string a = SR.ReadToEnd(); Stream baseStream = SR.BaseStream; baseStream.Position = 0; string b = SR.ReadToEnd();
  24. Why couldn't you just set SR.ReadToEnd() to a variable, and then set every other variable after that to the new variable? string textFile = SR.ReadToEnd(); string a = textFile; string b = textFile; I should also point out that ReadToEnd is relatively slow, since it reads the stream one byte at a time. Instead, use Read() or ReadBlock(), and read the file into a Byte array all at once, and then you can convert it to a stringwith the System.Text.Encoding class.
  25. I don't see why you need to declare a new StreamReader every time... are you changing the file in between reading the 100 settings? If you are changing the file, then yes, you will need to declare a new class to read it every time, whether it be an XML deserializer or a StreamReader. Otherwise, you should be able to read the entire file at once.
×
×
  • Create New...