The Scary Door

Learn along with me, Brunhilde the happy programmer!

17.6.05

VB6 Annoyances

I'm back working on good old VB6 this week, and after using nothing but VB.NET for several months, going backwards is really frustrating!

Over the last 4 days I have continued to discover more and more reasons to hate using VB6, not because of the actual syntax of the language, but because of flaws in the development environment itself.

Here is the list of my top personal VB6 annoyances

1. No mouse scrolling. It works in Visual Studio 6's C, but not in VB. Why? I have no idea, but it is bloody annoying! The scroll wheel on a mouse was very easy to get used to when it first became available, but once you get used to it, it is very difficult to go back to life without it! I'm sure everyone who has used a scroll mouse knows how sucky it is to go back to a mouse without a scroll wheel, you keep running your finger over the empty spot where it should be and it's terribly frustrating. The problem with VB6 is that the scroll is still there (providing you have a scroll mouse, and why wouldn't you?) but when you wheel it nothing happens. After a week of using nothing but VB6 I still keep trying to scroll, it's too hard a habit to break. A few times I actually thought my computer had frozen up because I was wheeling and nothing was happening. The amount of useless wheeling I have done this week probably accumulates to about half an hour of wasted time. Seriously. All I know is, everyone agrees that this is the single most annoying thing about using VB6.

2. No collapsible region thingies. Now my buddy programmer doesn't use this feature in .NET, but I love it. Every function or sub I am not using gets clicked shut, and groups of subs are separated into regions and kept shut as well. I can get a 3000 line program condensed down into a page and a half, and I love it. In fact I'm a bit obsessive about keeping everything shut, I do a lot of clicking on those + and - symbols, like I always keep all the programs I have opened minimised unless I am using them, I'm picky about that too. Actually .NET bothers me in the way that when you open a project all the subs will be visible again. The first thing I do after loading a project is click everything shut. However I am complaining about VB6 today, so I'll get back to the subject. I like being able to make stuff smaller and VB6 doesn't let me, end of story.

3. You can't comment out a huge block of code at once. .NET has a lovely feature where you can highlight an area, then comment or uncomment it with one click of an icon. VB6 forces you to comment out each line one at a time, and I hate it! The amount of ' key, down key, home key, pushing I had had to do it ridiculous. At least in C you can start a comment area with a nice */ and not have to mark every line, hell even HTML can do it! Commenting out large sections sucks so much that I usually cut them, paste them into notepad, then put them back in later, rather than just commenting them out.

4. It's not that smart. Ok, sometimes .NET drives me nuts cause it's too smart, I comment a line out and a bunch of warnings appear to let me know, but I already know cause I did it on purpose and if it would just wait a few more clicks then everything will be alright again... But at least it will tell you if you have called a function that doesn't exist so you can find out before you crash your program trying to access it. It also would be nice if it could indent stuff for me, and put 'end if' in there automatically, and all the other stuff I have become to lazy to do myself because .NET does it all for you.

5. I like the tab thing .NET has going where you can see every item you have opened at the top of the work area. It's nice to be able to click on the tabs to switch between them instead of having to ctrl-tab, and I like being able to see what I have opened. This going back to my obsession with having everything closed again, after debugging in VB6 I go through all my open pages twice to make sure there are none opened that I will not be using and need to shut.

6. I like to have the line numbers down the side of the page, I don't think Visual Studio 6 can do that. At least I have never figured out how to make them appear.

7. Every time I open a project it opens at visual studios default save location. I don't save my stuff there; I have never opened anything from there, why can't it remember where I opened my last workspace from and take me straight there? I know it knows where I have been cause it can make a recent list. It's insistence that I open things from it's stupid default location makes me angry.

That's all I can think of for now... but I'm sure I have a few more!

A few of these things might be solvable by changing so settings, but as I am only going to be working in VB6 for another week or so (hopefully) I don't think it is worth my time to try and work it out. Ah well, enough complaining and back to my VB forms.

12.5.05

I just want to capture a double click!

Today has been a bit of a waste of time.

What I am trying to do is simple enough, yet it seems that I can't do it.

I have a Datagrid in an ASP.NET form, I want users to be able to click on it and then I want stuff to happen.

Should be pretty easy I thought, until I discovered that there is no DoubleClick event in ASP.

Ok so you can add one in, but not if you let the program build your datagrid for you, only if you specify the column names in HTML. So I added in some crap like:

{Columns}

{asp:TemplateColumn HeaderText="JobName"}

{ItemTemplate}

{asp:Label ID="lblJobName" Text='{%# DataBinder.Eval(Container.DataItem, "JobName") %}' Runat=server /}

{/ItemTemplate}

{/asp:TemplateColumn}

And the datagrid was able to bind itself like it used to except for one thing... My ability to sort by clicking on the column header was gone! I have no idea why, sorting was still enabled and I had an onSortCommand thing in there, but they became unclickable. I could put a separate sort command field in each template column, but then it wouldn't use my custom sort. Infuriating, but not what this post is actually about.

So anyway, I managed to put some code in the ItemDataBound declaration of the datagrid that looked for my column labels that I created as explained above and added an OnDblClick event to each {TR} in the datagrid.

The datagrid now knows when I double click on it!

The problem in, I can't get it to do anything once I do, unless I write the function in Javascript and stick it on the page with the HTML, which I REALLY don't want to do. I can't get it to see a function in the code behind, even though the datagrid sort command lives there and that can be found just fine. It won't recognise anything I put in there, it just says Unknown Object.

It would be alright if all I wanted to do was a little Javascript function, like a pop-up box with the name of the row that was clicked on or something, but I need to write to a file and already have a function for that sitting in the VB part.

So the good news is I am able to handle a double-click event. The bad news is that I can't also have a bi-directional sort and whatever function I want the double click to call has to be in Javascript. Ggaaahh!

So I spent half the day trying to find a good solution to my double clicking problem and I haven't found one. I guess I'll have to put a checkbox column in or something, which I don't want to do cause it's a wide grid already and being any wider will make its layout look lousy.

Ok, I have worked out what I am going to do. I'll put in a textbox and a button and the user will have to put the name of the item in the textbox then click to perform the action. I don't know how I'm going to squish it in, but that is another problem. I probably would have done something like this in the first place if I had have designed the stuff myself, instead of adapting an already existing application and converting it into a web page.

11.5.05

ASP.NET's "I format your HTML however I feel like" bug

I have been adding controls to a multipage today and for some reason you can't just drag them onto it in design mode (as far as I can tell), you have to edit the html so that the items are between the move the pageview tags and then you have to set there coordinates manually. Not hard, just tedious, but having to do it reminded me again of it's stupid HTML formatting issues.

One of the first things I noticed I disliked about ASP.NET is this problem.

My first complaint it about the way it formats the HTML code as you insert components in design view. It doesn't seem to have any logic to it at all! Things appear in strange orders, the line breaks are in bizarre places and it blocks odd pieces of code together.

My first thought after seeing this was, 'No problem, I'll just move it around myself,' which I did, then went back into design view.

That brings us to the second problem; on switching back to HTML view you find that it has rearranged everything again!

The third problem is that there seems to be no way to fix either of the first two problems.

Oh! It also removes extra things you might have added, like a field that lets Firefox read an items height or width, thanks for that Microsoft!

I'm not even going to think about what normal paste does and how you have to use 'paste as html' all the time.

I did a search on the web after discovering this little quirk and discovered that while I was not the only one who found it annoying, no one really had a good solution for it.

Microsoft themselves recommend these two half-arsed half-fixes, which are:

1. Click undo after you switch to HTML view, this may or may not fix the reformatting and may not also undo whatever change you just made.

2. Click save before switching back to design view, then when you switch back to HTML view it might not have reformatted everything. Most of the time.

They also stated that there is no way to turn this 'feature' off, despite the development team considering it to be a bug. Oh well.

If you turn off Word Wrap in Tools / Options / Text Editor / HTML/XML / General - Settings it helps a little because then at least lines that shouldn't be broken up might not be. Instead you will often get a long line of code (not always, it seems to be really erratic) but if you put them on their own lines they will sometimes stay there.

Honestly it's a major pain and some days it just pisses me off... like today!

6.5.05

Browser compatibility woes

IE Webcontrols are awesome, unless you want to use Firefox...

Web page compatibility... So important, yet so difficult at times! When I explained the proglems I was having to my supervisor yesterday he got all angry that after all this time there was no standard for all web browsers to adhere to, though I pointed out that if there was then all the viruses that could get through IE but not others would affect everyone, but still, it would be nice if a website would look the same on every browser.

As we make Windows software with Microsoft products we are not too concerned with stuff like this, but as I am a Firefox user myself, I consider it to be important and try to make everything I make cross compatible.

Now I expected to have a problem, because I am working in Mircosoft Visual Studio, programming in ASP.NET and using Microsofts Internet Explorer Web Control package to make a neat looking tabstrip with multipage affair. I'd be crazy to even think that this could work in anything but IE, so I wasn't too surprised to see it looking like a jumbled mess.

My problem is this, I have a heap of labels and other components that are all set with left and top values to align them on the page. In IE, it aligns them within the multipage area and everything looks great. In Firefox, it aligns them from the top and edge of the page and as a result everything is in the wrong place. This can be fixed by changing the values, but then it looks wrong in IE. I need a way for it to look right in both. For some reason FF can't seem to keep a {span} object inside the table.

However, I'd like to try to get it looking better, I'd really hate to have to tell people that this application is IE only.

I have a few things to try in this situation.

Step 1, add browsercaps to my Web.config file.

The standard code I use for this is as follows:

* When I tried to post this I realised that by putting HTML code in here the blogger tried to execute it, so I have replaced the "{" symbols with "{" I'll have to see if there is a way around that...

{browserCaps}

{!--NETSCAPE 6 and 7 //--}

{case match="^Mozilla/5\.0 \([^)]*\) (Gecko/[-\d]+ )?Netscape[6|7]/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*)).*"}

tagwriter=System.Web.UI.HtmlTextWriter

browser=Netscape

version=${version}

majorversion=${major}

minorversion=${minor}

frames=true

tables=true

cookies=true

javascript=true

javaapplets=true

ecmascriptversion=1.5

w3cdomversion=1.0

css1=true

css2=true

xml=true

{/case}

{!-- MOZILLA //--}

{case match="^Mozilla/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*)).*"}

{case match="^[5-9]\." with="${version}"}

tagwriter=System.Web.UI.HtmlTextWriter

{/case}

{/case}

{!--

OPERA 5+

//--}

{case match="Opera[ /](?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*))"}

{filter match="[4-9]" with="${major}"}

{filter match="[5-9]" with="${major}"}

tagwriter=System.Web.UI.HtmlTextWriter

{/filter}

{/filter}

{/case}

{!--

GECKO Based Browsers

//--}

{case match="Gecko/[-\d]+"}

browser=Netscape

frames=true

tables=true

cookies=true

javascript=true

javaapplets=true

ecmascriptversion=1.5

w3cdomversion=1.0

css1=true

css2=true

xml=true

tagwriter=System.Web.UI.HtmlTextWriter

{case match="rv:1.0[^\.](?'letters'\w*)"}

version=6.0

majorversion=6

minorversion=0

{case match="^b" with="${letters}"}

beta=true

{/case}{/case}{case match="rv:1(\.\d+)(\.\d)?(?'letters'\w*)"}

version=7.0

majorversion=7

minorversion=0

{case match="^b" with="${letters}"}

beta=true

{/case}{/case}{/case}

{/browserCaps}

I only have about a 50% understanding of what this does and what all that stuff means, but adding it in usually solves a few layout problems, such as textboxes not showing up in their set width, ect.

In this case it had no effect, which was what I anticipated.

Step 2, change the page target XML scheme from Internet Explorer 5 to Internet Explorer 3.02 / Netscape Navigator 3.0.

This has never fixed a problem for me but I always try it anyway. In this case it made no difference, so I changed it back. Doesn't seem like a setting I would want to leave like that without good reason.

I've been mucking around with putting {div} stuff around the trouble spots but haven't really solved the problem and can't waste too much time on it. I guess for now I'll have to just detect the browser type and display a message if it is not IE and tell the client that it is IE compatible only. Although it does still work fine in FF, it just looks wrong.

I suggested to my supervisor that I could install Opera and see what it looks like in there and he said it's probably less stressful not to know. I think I agree!

2.5.05

Commenting on comments

I brought up the program I made the other day to show my supervisor what I had been doing and as it was loading I mentioned to him that I had done of good job of commenting this source and that it was going to be a stunning example of well commented code.

When it loaded we both looked at it, then looked at each other, him with a 'what are you talking about?' look on his face, and me probably looking guilty as a comment-less screen stared at us.

"Wait wait, I'll scroll up. See? There they are!"

He said that was a very nice effort, but five comment lines in one hundred lines of code do not equal well commented code.

It felt like a lot when I was writing it!

Though no one here really comments their code very much, I suppose when there are only three programmers it isn't that hard to have everyone understanding what is going on, and if not you can just ask the person who wrote it. Most things seem so straightforward when I code them that putting in comments seems pointless. The ones I had put into this particular program were mostly there for my own benefit, so I could see what steps had been programmed in and what was still needed.

I wonder if properly commenting your code if a necessary practice in big companies?

28.4.05

I know a Regular Expression for "Really Bloody Complicated"

I recently discovered Regular Expressions. I get the feeling that these are something that every programmer is familiar with, but I had never known about them until I started mucking around with field validation for work's website.

We never covered this when I was at Uni, I wonder if other programming courses do? They seem kind of mathsy, which I don't like, but they also seem pretty useful, which makes me want to learn more about how to use them.

Anyway, today I want to make one to validate a code that customers will enter in our online registration page. There is no way to check if the code they enter is correct on the site (for several reasons) so I want to validate it as much as possible to lower the chance of error.

At the moment I am just using \w{4} to validate the field, which will help filter out the symbols and crap, but there are actually some invalid characters that can still get through, because the registration code they are entering only contains characters "0123456789ABCDEFGHJKLMNPQRTUVWXY" the letters I, O, S and Z are missing because A) I needed only 32 characters and B) those are the ones that might get confused with some of the numbers.

I guess the first thing to do will be to get the lowercase letters out of the mix. Actually, I just realised I can leave them in because I do a ToUpper on the entire string before I use it.

I wonder, is it easier to list the valid characters like [A-Za-z0-9] or to list the characters I don't want to find? My original idea was to put in A-H J-N ect, but I think the second method will probably work better. Just as soon as I figure out how you do that!

Looks like using a ^ in a [] will be a not, so I'm trying to tell it I want 4 alphanumeric characters, but not an 'I'. I mucked around with The Regulator for a while, but it seems a little screwy, I got some weird results out of it, so I decided to go to www.regexlib.com and use their online expression tester instead.

My first test is with the expression ^[\w][^I]{4}$ and it seems to work! Time to try it in an actual ASP application and see if it actually works there....

Ok, for some reason it likes 5 characters instead of 4, I have no idea why. Perhaps it is counting from zero. At any rate, I changed the 4 to a 3, and all is good. Next step, have it look for another illegal letter, not just the 'I'. I have no idea how to put multiple characters in, I'll try just putting them all in there and see what happens.

So I try ^[\w][^IOZS]{4}$ and voila! It filters out all the characters I don't want in there.

But wait, there is a problem....

If the IOS or Z is the first character, it gets through. I guess it is looking for the good characters first. The problem also occurs with the \w check, if there is a symbol in one of the last three slots it also gets through. Guess I'm not so smart after all hey? So what to do?? I will have to leave this for now as it is lunch time, but I plan to have more regex adventures!

26.4.05

ASP.NET, the demon spawn created by the unholy union of several other languages.

I mean, what is it really? I can into the ASP scene after the standard non-.NET version was already out of date, so I never really touched the original and don't really know what it was. I mean, it is an actually programming language?

When you tell people that you are a computer programmer, they always ask, "What language do you work in?" even though most people who ask that probably don't know the names of any languages anyway, except for Basic which they might have learned in high school (probably VB these days).

The point is, I never know what to say. Aside from not wanting to admit that I do a lot of programming in VB (I don't want the hardcore C people to think less of me!) I do most of my work in ASP.NET, but can I really call that a language?

ASP.NET is really just a mash of VB.NET or C#, HTML and maybe some Javascript, so ASP as a language doesn't seem to really exist, unless you count the bits that say <asp:button> ect, but I consider that to be HTML really.

The problem with ASP is that these different languages don't really like working together. Try to wrap a little HTML around some VB controls and the whole thing stops working, so it is kind of like a butchered version of each language, you can't do everything you can do in plain VB and you can't do everything you can in plain HTML.

And as if working in two separate languages isn't enough, people are always throwing scripts into the mix. I really hate looking for information about how to do something in ASP and finding heaps of Javascript examples. For starters, as someone who used to write Java applets, Javascript and Jscript kind of confuse me, cause they look kind of simular (from what I remember) but they are not. I don't even know what VBscript is like and I'd rather not have to. Who the hell wants to write a webpage in three different languages at once? Throw in some SQL statements and you've got a real mesh of crap. Plus scripts won't execute until a postback, no matter where you insert them into your code, it's just not worth the hassle.

So WHY do I find so much Javascript in ASP code samples? I don't want to use Javascript to preload my images, why overcomplicate things?

Oh well, better get started on that Javascript!