Wednesday, July 21, 2010

C# Determine the pixel length of a string.

This method will determine the length in pixels of the text.

private float FindLengthString(string text)
        { 
            Font _tagFont = new Font("Sans Serif", 8.25f);
            float fWidth = _tagFont.Size;

            Graphics g = this.CreateGraphics();
            fWidth = g.MeasureString(text, _tagFont).Width;
            g.Dispose();

            return fWidth;
        }

Monday, July 19, 2010

VB 6 COM w/ C# libraries

Ok. As much as I love Visual Basic 6 (sarcasm), I was put on a project to ensure that a vb6 app that used C# COM objects compiled and ran.


1. The C# projects, [I used VS 2008], needs special settings in order to work correctly with Visual Basic 6.

a. Go to the project settings. Go to the Compile tab. Go to Advanced Compile option. Change the target framework to 3.5.

b. Visual Studio 2008 changed the location or rc.exe [If you don't have it, you can install the SDK of the .NET framework]. You have to find it on your computer. In the Compile option, there is a 'Build Events...' button. A dialog box appears, and in this box, in the "Pre-Build event command line:" section, there is logic to find rc.exe. Delete all text. Put in --> "[rc.exe location]" /r "$(ProjectDir)InteropUserControl.rc" Now substitute the rc.exe path for [rc.exe location]. /r and $(Project... is exactly the same for all libraries.

c. In References option, remove the Microsoft.InteropFormTools reference.

Ok. Recompile the project. This must be done on the machine that you are going to develop the vb6 on, otherwise, vb6 won't recognize the library.

2. Regasm is a tool that adds assemblies to the registry. Well, when you compile the *.tlb and *.dll files from .NET, use the Visual Studio command line tool. Navigate to the /Release folder of the desired project. Use the command regasm /regfile [dll file name] [reg output file name]. You must have the regasm path in the Environment Variables on MyComputer properties. Regasm with make a [filename].reg. This will be used in the vb6 app to register the COM objects.

3. The Package and Deployment Wizard for Visual Basic 6 is finicky. I couldn't find where to choose the location of the .NET dlls in the *.reg files. I mean, I wanted to be able to choose where the registry knew where my .NET COM object dll files were located, but I couldn't find that. Therefore, I had to change where my dll files were installed. The .tlb files were installed into the /system32/ folder and the dll files were installed into the /apppath/. I'm sure there is a way to change the directory path, but I didn't spend that long on the project.

I may have forgotten a step, if so, I'll update soon.

Monday, July 12, 2010

C# Prefix Casting vs 'as' Casting

The main difference between the two types of casting is what happens when an error occurs.

Prefix Casting: In prefix casting [ Type myVar = (Type)someVar; ] an error will be thrown and must be caught if someVar is not actually of type 'Type'.

'as' Casting: In as casting [ Type myVar = someVar as Type; ] the cast will return 'null' if someVar is not of type 'Type'.

I've read that 'as' Casting is also about five times faster (5x) than prefix casting. I've run my own tests and found out that it really isn't. Or at least not in loops. I've tried converting both 'string' and 'DateTime' objects to object. Prefix was much faster when adding to a list and sometimes faster when just converting the value to another variable.


Tuesday, June 29, 2010

ASP.NET MVC 500.24 Error

This error occurs because Asp.Net cannot apply a detected setting in Integrated managed pipeline mode.

In the Web.config add this line of code in the [system.webserver] block.

[validation validateintegratedmodeconfiguration="false"]

This will ignore the error.


-------------------------


Also, in IIS web.config, in the system.web element, there is the identity impersonate=true element. Delete.

Thursday, June 24, 2010

DataTable Column Mapping for XML

This article will demonstrate how to determine or set a SYSTEM.DATA.DATATABLE.Column as different XML nodes.

// The user must include into their class:
using System.Data;

// ==========
// To determine if a column is an XML attribute after
// loading data

// --- after loading data into the dataset
// --- and finding the table needed
mytable.Columns[].ColumnMapping == MappingType.;

----> There are 4 types
Attribute
Element
Hidden
SimpleType

Columns.MappingType Gets or Sets the mapping type for the column.

Tuesday, June 22, 2010

MySQL Workbench Foreign Key Restraint

In MySQL Workbench, the user can alter tables. When altering tables, the user can add 'foreign keys' and 'indexes' to tables.

MySQL Workbench will not allow the user to add foreign keys in certain situations, and will not give adequate error messages so the user can fix them.

Some important things to remember when altering a table to add foreign keys in MySQL Workbench.

1.
Both columns must be EXACTLY the same type. If one column is unsigned INT(10), the other must be unsigned INT(10).

2.
Since, MySQL Workbench will make an index of a foreign key, the foreign key MUST BE AN INDEX of the referenced table, otherwise the script will not be successful.

Thursday, June 17, 2010

TypeTester

This is a site to test Fonts side-by-side.

Really helpful.


This shows what types look like on different machines.