Friday, February 18, 2011

VB Constructor - Calling base constructor on overloaded new methods

You can have multiple ways to create a class, passing various parameters when you create a 'new' instance of the object. In the class constructor, you use the
Me.New() to call the base constructor, or any of the constructor signatures

public class MyClass
dim var as string
dim i as integer
dim sConnString as string

public sub New()
var = "Init"
end sub

public sub New(vInt as integer)
Me.New() ' calls base constructor
i=vInt
end sub

public sub New(vInt as integer, vConnectionString as string)
Me.New(vInt)
sConnString=vConnectionString)

end sub

Tuesday, February 1, 2011

ASP TextBox/Label Box Will Not Get as small as you want it

I was trying to get a small label aligned on my form, but no matter what I did, the label was much larger than what I had specified in the HTML. I tried various things but still could not get it to appear the correct size in Visual Studio, though it did look the correct size when I ran the code. I finally realized that I had named the field a large number of characters and the name was displayed on the design screen, as large as necessary to display the ID of the label. I changed the size so that the name was 3 characters and the label appeared the correct size. So watch out for the length of the ID's you use especially when trying to size a small field.