February 2004 - Posts

First I want to say that I think the work that the Microsoft guys have done on the .NET Framework, Visual Studio, and the associated .NET languages is fantastic. Kudos to you!

That said, here are some comments on Visual Basic .NET that possibly could be fixed or looked at for Whidbey.

1) Inheriting from the CollectionForm does not work.

According to this KB Article I should be able to inherit from CollectionEditor.CollectionForm.  However, when I try to
inherit from the class, I get an error: NodeCollectionEditor.vb(50): 'System.ComponentModel.Design.CollectionEditor.CollectionForm' is not accessible in this context because it is 'Protected'.

Apparently, you can inherit from a CollectionForm in C#. I can work around this problem in my ServerControls library by developing the CollectionForm in a separate (C#) project.  But this should work in VB.

2) Simplify the TypeOf syntax.

In C# if I want to know if an object is of a certain type, I can write

if (object is MyClass)

In VB .NET, I have to include the typeof keyword:

If Typeof Object Is MyClass Then

Here's my opinion of what the ideal scenario is:

Given “If A is B Then“, where “A” is always an instance of an objects

When B is a Type or Interface, “If A is B Then” equates to If TypeOf a is b

When B is an instance of an object, If “If A is B Then” equates to If A is this particular instance of B.

UPDATE


3) The ability to declare common variables to Get/Set routines in Properties

Example:

Public Property MyValue() As String

const lookupstr as string = "MyValue"

Get

Me.ViewState(lookupstr)

End Get

Set(ByVal Value As String)

Me.ViewState(lookupstr) = Value

End Set

End Property

In this example, I have saved myself the the possibilty of mis-typing “MyValue“ in the Getter and Setter, which granted probably wouldn't be a problem here.  But there are many properties that have difficult-to-type names, and more than once I've been bitten because I'm reading from one ViewState variable, and writing to another. 

2) qualifies as more a suggestion I guess, but 1) seems to be a bug.

Comments?

Posted by taganov | 4 comment(s)
Filed under:

I've developed a suite of ASP .NET Custom User Controls that optionally make use of a webservice. Overall, I've found the process of working with webservices very smooth.  However, when I add the controls to the Visual Studio Toolbox, the WebService shows up as a selectable item in that list.  I don't mind the webservice showing up as a dll in the references list, but I'd rather not have it so that it can be drag/dropped onto an aspx page.

Is there any way to have the WebService not show up in the “selected components list”?

What kind of gotchas have you run into while working with WebServices?

Posted by taganov | with no comments
Filed under:

Hi, My name is Chris McKenzie.  I'll be blogging from time to time about my experiences and discoveries regarding .NET programming. My hope is to document the things I learn as I go, and to provide a forum for constructive feedback from other developers.

I guess I'll jump right in.  I'm developing an ASP .NET server control that will accept a report path to SQL Server Reporting Services (RS) and dynamically render UI for the report's parameters.  The control consists of 5 pieces: a containing table, a label for the user prompt, a value control (meaning, textbox, dropdown, radiobuttons, checkboxes, etc.), a required field validator, and a datatype validator. 

For the most part, this is a cut-and-dry composite server control.  However, something wierd happens with the RS DateTime datatype.  The datatype validation for the CompareValidator is limited to the Date (MM/dd/yyyy) only, and RS will only accept a parameter in DateTime (MM/dd/yyyy hh:mm:ss AM/PM) format. However, I want to allow the user to optionally enter the time.  The control should be smart enough to append 12:00:00 AM to MM/dd/yyyy.  This means I have to provide a CustomValidator with a custom regular expression for the DateTime datatype.

This regex works well, for making sure that everything is in the right format:

([0]?[1-9]|[1][0-2])[-/]([0]?[1-9]|[1-2]\d{1}|[3][0-1])[-/][1-2]\d{3}(\s([0]?[1-9]|[1][1-2]):[0-5]\d{1}(:[0-5]\d{1})?\s[AP][M])?$

Basically, I'll accept  (M or MM)/(d or dd)/yyyy or (M or MM)/(d or dd)/yyyy (h or hh):mm(” “ or :ss) (A or P)M. But I'm still not done, because I want the final figure in a standard format.  In other words, I want 1/1/2004 5:30 PM to return as “01/01/2004 05:30:00 PM.”  I can use this javascript to handle the date portion:

s = s.replace(/\b\d{1}[-/:]/g, "0$&"); // // replace M/d/yyyy h:mm with MM/dd/yyyy hh:mm

Now we're getting closer to my problem.  I'm trying to do the time portion.  If time is specified, I want to append “:00” to hh:mm, but only if :ss is not specified.  I experimented using Roy Osherove's excellent Regulator application and came up with:

// \d{2}:\d{2}(?=\s)(?<=\s\d{2}:\d{2})

regExStr = "\\d{2}:\\d{2}"; // where pattern matches ##:##

regExStr += "(?=\\s)"; // and the next character is a space

regExStr += "(?<=\\s\\d{2}:\\d{2})"; // and the preceding characters match " ##:##" (i.e., not ##:##:##)

r = new RegExp(regExStr);

s = s.replace(r, "$&:00 "); // replace hh:mm with hh:mm:ss

When I ran the code, imagine my surprise when I got an error basically stating that regExStr was invalid.  So, I checked the Regulator again, and everything seemed fine.  Then I checked some only javascript regex testers, and found that the (?=...) and all variants created the same error.

I went ahead and coded a workaround, but I'm left with a nagging curiosity: is this documented?  Does the javascript RegExp() object not support sub expressions?  Or is this an IE only phenomenon?  I did a quick google about it, and couldn't find anything.  Does anyone else have answers to these questions?

Posted by taganov | with no comments
Filed under:
More Posts