Thursday, April 21, 2005

A really handy tip...

I can't remember where I heard or read it, but I remembered a handy tip for when you're having trouble working with datasets.

I was having a mare with a dataset earlier on today, and I thought that something was up with my columns, but I remembered this single method call (luckily!) just before I embarked on a woeful quest of 'for each c as DataColumn in MyDataSet.Tables(0)' and stuff like that.

Here it is:
MyDataset.WriteXML(Response.OutputStream)
Very handy.

Still didn't sort out the prblem, though. The dataset was exactly as I expected. It was just one of the assemblies I was working with that was playing up. Still, we live and learn, do we not?

Monday, April 18, 2005

It's like they reached into my head...

... And put what they found in there on the web.

MSDN's Coding4Fun sitelet (Is that even a real word??) does rock! A whole bunch of great brains doing nothng productive? I'm right on down wit' dat!

Thursday, April 14, 2005

Summer must be coming...

... I've just swatted my first wasp.

Wednesday, April 13, 2005

There are some things in life that I don't need to see...

And one of them is at the end of Scott and Rory's 4th tech-ed video.

The hopeful look on Rory's face. The little half-smile. That'll be haunting me for weeks...

Tuesday, April 12, 2005

Great little Add-in

I've been meaning to give the Copy Source as HTML a go fro ages. I reckon it would make my life much easier when it comes to code samples. And of course it would. Half the reason I don't put too many code samples on my blog is that I don't have the patience to read plain black text, nor do I have the patience to go through and manually highlight big blocks of code.

Lucky, then, that I now have this neat little VS add-in to let me put in things like this:


    Protected Function GetSubordinates(ByVal EID As Integer) As DataView

        GetSubordinates = New DataView(GetEmployees.Tables(0))

        GetSubordinates.RowFilter = "ReportsTo = " & EID

        Return GetSubordinates

    End Function


Useless bit of junk code, but hey neato! Just copied and pasted strainght in.

Nice.

Apologies for only just getting on the bandwagon...

It's the little things...

Now and again I'll have a really productive day. Everything'll fall into place, compile first time and just run.

Sometimes, though, I just think of a really small thing and think to myself 'gee. Y'know, it really would be nicer if it did that.'

Like today. I'll expand on it later, when I've actually finishedit, but suffice to say it involves ASP.NET, Repeaters, home-grown viewstate persistence and a whole load of kludges that I never thought I'd have to go near.

Grrr. The devil is, indeed, very much in the detail!

Apologies for teasiness.

Cheap. Nasty. Dirty.

Just a quick one to tell both my readers that if they don't already, listen to Mondays.

Here is what it's not:

  • Safe for work
  • Intellectually Challenging
  • Mature
  • Educational

Here is what it is:
  • Funny
  • Crass. But in a good way.
  • Alternatively Educational

Well it's good clean fun, anyway. So listen to it. Both of you!

Do I get a Mondays mug now?

Wednesday, April 06, 2005

Blogging on Demand #6

I saw this in my referral whatsit just this evening, in fact, so in the interests of rapid response, here's a little bit about...

"accessing protected methods" vb (via Google)

Any methods in your class can (and usually will) be given a level of access, normally one of four:

There are a couple more as well which are used quite a bit, Shared and Virtual. I won't be going into them right now, since the reasoning behind them is a little different to the other four.
The different levels of access denote which code can 'see' the method, and call it. Briefly, the levels of access look like this:

Public
Public methods (same with public variables) can be seen and called from any code that references it. If you add a reference to your project, and declare an instance of the class, you can call all the methods declared in that class as public.

Private
Private methods and variables are declared within your class and can only be callled from within that class. If you create an instance of your class that has private methods within it, you will ot be able to call those methods. I often use private methods for quick functions that are needed all over the place within that class. They can, in fact, cover a multitude of evils (just between you and me). You'll notice that when you're working in VS, intellisense doesn't list private methods either. It's clever like that. As far as the code calling your class goes, private methods may as well not exist. I think you get the point.

Friend
Methods and variables declared as friend can be called only by code from within its assembly. This is quite handy if you've got some code that's used extensively throughout your application, but has some secret logic in it (for instance). OK, there are ways and means of finding it, through ILDASM and stuff, but for normal developers doing normal things, it's pretty much invisible. It's also something to look out for if you're writing an app that has multiple assemblies. As far as I know, the scope of friend methods is only the individual assembly, rather than the whole application.

Protected
Finally. Protected methods. What this whole post was meant to be about. Protected methods really come into play when you're talking about inheritance. And why? Because protected methods can only be called directly by an inherited class.

Take, for example, the Windows Forms Control class. All Windows Forms controls have a protected sub called OnPaint. As the name suggests, it paints the control. You may want to, however, do some custom action while the control is painting. Because the OnPaint method is declared as protected, you can't call it from the surrounding code. It can only be called from within itself. So how can you do something whizzy and flash with your control's OnPaint method? Well, you can inherit from it.

Create yourself a new class, that inherits from Control, and within that class you can change the way your control is painted. I did this recently with a dial control I was working on. In my case, I used OnPaint to specify where the hand on my dial was going and to draw it in, by declaring this method:

Private Overrides Sub OnPaint(sender as object, e as PaintEventargs)
' Call the original base class' OnPaint, so you don't have to draw the whole thing from scratch
MyBase.OnPaint
'Do some drawing stuff here
End Sub

The important thing to note, however, is that the original MyBase.OnPaint method was available, because it was declared in the base class as Protected.

And that's how you access protected methods.

Tuesday, April 05, 2005

Want to put a Windows Control in your web app?

Mark's written this quick tutorial about how to do it.

Good work fella. I didn't even know this could be done until the other day - I think I might have to have a play about with this shortly...

Monday, April 04, 2005

Isn't life grand?

I've been having one of those weeks when I just wander about rediscovering really cool things. You know what it's like. There's a whole world of cool stuff out there, but we all just breeze past it and don't see just how great everything is.

Washing machines
Washing machines really are cool. They are, I find, essential if you want to keep your friends. I hear there's nothing worse than having a really smelly friend. I just love the way you can load up your manky shirts and they come out clean again. Briliant.

Secure working environments
There's nothing I love more than going in to work and knowing, yes, knowing that I'm safe and secure at my desk. I can sit there and rest easy (except when I get up and get a coffee) safe in the knowledge that I'm unlikely to get assaulted or blown up by anyone. Top notch. I love it.

Self-Documenting databases
One of the pleasant side-effects of relational database design, apart from the obvious benefits of performance, size, and all tha good stuff, if the ability of the data structure to give you a good idea of how things are related in real life. If my database sys there's a zero-or-one-to-many relationship between houses and people, then that suggests, quite logically, that a house can have zero, one, or more people living in it. Fantastic! I get information about how real life works from the structure of a database. Something almost completely unrelated to houses and families. How cool's that? I love that.

The more perceptive of you may have guessed that this week my washing machine packed up, I forgot my building pass and spent a frustrating afternoon trying to work out some database stuff.

Apologies for excess sarcasm.