Wednesday, October 13, 2004

Can you use JavaScript to read and write to a file?

Now I was searching high and low for the answer to this question. The big answer that I got was, JavaScript cannot read or write to files. However, it is possible to do this using ActiveX embedded into your JavaScript. The following is the code to do this.

//-------------------------------------------------------
function WriteToFile()
{
    var filename = "data.txt";
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    if (fso.FileExists(filename))
    {
        var a, ForAppending, file;
        ForAppending = 8;
        file = fso.OpenTextFile(filename, ForAppending, false);
        file.WriteLine(name);
        file.WriteLine(password);
    }
    else
    {
        var file = fso.CreateTextFile(filename, true);
        file.WriteLine(name);
        file.WriteLine(password);
    }
    file.Close();
}
//-------------------------------------------------------
function ReadFromFile()
{
    var fso, a, ForReading;
    ForReading = 1;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    file = fso.OpenTextFile(filename, ForReading, false);
    var name = file.readline();
    var password = file.readline();
    file.Close();
}
//-------------------------------------------------------

In IE you can use the FileSystemObject to read and write to/from files.

You can get to a reference on how to do this all here.

Sunday, October 03, 2004

My approach to drop down menus using JavaScript

Drop down menu
<div>
<iframe></iframe>
<div></div>
</div>

Hide outer div by setting the Style.Visibility to "hidden".

Show it when you want to by setting Style.Visibility to "visible".

Be sure to set the z-index of the internal div higher than the z-index of the iframe; if you do not, then the iframe will show over the div instead of under. Div tags are windowed elements while iframes are considered windowless. That means that unless you set the z-index higher, the iframe will always show over the div.

For an example, please contact me until I have a link up for an example.

Thursday, September 16, 2004

Programmer's Genesis

1. In the beginning GOD created the Bit and the Byte. And from those he created the Word.
2. And there were two Bytes in the Word; and nothing else existed. And God separated the One from the Zero; and he saw it was Good.
3. And God said - Let the Data be; And so it happened. And God said - Let the Data go to their proper places. And he created floppy disks and hard disks and compact disks.
4. And God said - Let the computers be, so there would be a place to put floppy disks and hard disks and compact disks. Thus God created computers and called them hardware.
5. And there was no Software yet. But God created programs; small and big...And told them - Go and multiply yourselves and fill all the Memory.
6. And God said -I will create the Programmer; And the Programmer will make new programs and govern over the computers and programs and Data.
7. And God created the Programmer; and put him at Data Center; And God showed the Programmer the Catalog Tree and said You can use all the volumes and sub-volumes but DO NOT USE Windows.
8. And God said - It is not Good for the programmer to be alone. He took a bone from the Programmer's body and created a creature that would look up at the Programmer; and admire the Programmer; and love the things the Programmer does; And God called the creature: the User.
9. And the Programmer and the User were left under the naked DOS and it was Good.
10. But Bill was smarter than all the other creatures of God. And Bill said to the User - Did God really tell you not to run any programs?
11. And the User answered - God told us that we can use every program and every piece of Data but told us not to run Windows or we will die.
12. And Bill said to the User - How can you talk about something you did not even try. The moment you run Windows you will become equal to God. You will be able to create anything you like by a simple click of your mouse.
13. And the User saw that the fruits of the Windows were nicer and easier to use. And the User saw that any knowledge was useless - since Windows could replace it.
14. So the User installed the Windows on his computer; and said to the Programmer that it was good.
15. And the Programmer immediately started to look for new drivers. And God asked him - What are you looking for? And the Programmer answered: " I am looking for new drivers because I can not find them in the DOS". And God said :" Who told you need drivers? Did you run Windows?" And the Programmer said :" It was Bill who told us to!"
16. And God said to Bill - Because of what you did you will be hated by all the creatures. And the User will always be unhappy with you. And you will always sell Windows.
17. And God said to the User - Because of what you did, the Windows will disappoint you and eat up all your Resources; and you will have to use lousy programs; and you will always rely on the Programmers help.
18. And God said to the Programmer - Because you listened to the User you will never be happy. All your programs will have errors and you will have to fix them and fix them to the end of time.
19. And God threw them out of the Data Center and locked the door and secured it with a password.
20. GENERAL PROTECTION FAULT

Monday, September 13, 2004

Capturing the close event.

When programming a thin-client application using HTML and JavaScript and you want to capture the closing event, it is not as easy as one thinks if you are not used to it. It is easy, but you actually have to do some research and think before attempting to do it. I have two examples.

Example 1:

In the onBeforeUnload event of the body tag, you can set the the event.returnValue to something.

ex.
    <body onBeforeUnload="event.returnValue = 'Would you like to close?';">

By setting the event.returnValue to something you are prompted with a dialog that includes the following message:

    Are you sure you wish to navigate away from this page?
    Press OK to continue, or Cancel to stay on the current page.

Your message will appear in between each of the statements.


Example 2:

You can simply provide the users with a button to close/exit and prompt them with a dialog box. One of the easiest ways to do this is with a JavaScript confirm.

ex.
    function myConfirm()
    {
        var saved;

        saved = confirm("Changes have been made.\nClose without saving?");
        return saved;
    }

By assigning the confirm to the saved variable, we are capturing the result. With the result is what you determine what you are going to do. If they click OK, a 1 (one) is returned for true. If they click Cancel, a 0 (zero) is returned for false.

Note: When you use example 2, the user can still click the X, use the close in the file menu, or use the close in system menu to close without you having any control.

Note: These solutions are Internet Explorer (IE) specific.

Friday, September 03, 2004

CSS, DHTML, and Tabs

For work we are writing a thin-client application that uses tabs. We have been boggled in how we are going to do this. Looking at how others have done this we saw CSS, Tables, JavaScript, and a whole slew of different combonations of these. JavaScript was always involved, but some used only CSS, some used only Tables, some used both.

So far in playing with it, I haven't used one table and I have a nice look. One tag that helped with some of the groupings of fields was the
<fieldset>
tag. It creates a frame around the group of buttons, input objects, or plain ol' text. It creates a real nice effect.

At first I was using the CSS like you would a table. Thinking of the rows, but then another programmer said, "Hey..." He made me rethink how I was doing it. Now I'm using the positioning and reusing of classes. It's really nice! I think I'm going to have to redo my website and incorporate some CSS.

Thursday, September 02, 2004

You and Your Boss: The Subtle Differences

If you take a long time, you're slow.
But if your boss takes a long time, he's thorough.

If you don't do it, you're lazy.
But if your boss doesn't do it, he's too busy.

If you make a mistake, you're an goober.
But if your boss makes a mistake, he's 'only human'.

If you take a stand, you're being bull-headed.
But if your boss does it, he's being firm.

If you overlooked a rule of etiquette, you're being rude.
But if your boss skips a few rules, he's being original.

If you do something without being told, you're overstepping your
authority.
But if your boss does the same thing, he's taking initiative.

If you're on a day off sick, you're 'always' sick.
But if your boss is a day off sick, he must be very ill.

If you're out of the office, you're wandering around.
But if your boss is out of the office, he's on business.

If you apply for leave, you must be going for an interview.
But if your boss applies for leave, it's because he's overworked.

Wednesday, September 01, 2004

A recommended blog

http://papproth.blogspot.com/

The author has been a professional programmer for many years. He has worked in a private company, as a contractor, and as a teacher.

The Janitor

An unemployed man goes to apply for a job with Microsoft as a janitor.
The manager arranges for him to take an aptitude test (section: floors, sweeping and cleaning).

After the test, the manager says, "You will be employed at minimum wage, $5.15 an hour. Let me have your e-mail address, so that I can send you a form to complete and tell you where to report for work on your first day."

Taken aback, the man protests that he has neither a computer nor an e-mail address. To this the MS manager replies, "Well, then, that means that you virtually don't exist and can therefore hardly expect to be employed."

Stunned, the man leaves.

Not knowing where to turn and having only $10 in his wallet, he decides to buy a 25-pound box of tomatoes at the supermarket. Within less than two hours, he sells all the tomatoes individually at 100% profit. Repeating the process several more times that day, he ends up with almost $100 before going to sleep that night. And thus it dawns on him that he could quite easily make a living selling tomatoes.

Getting up early every day and going to bed late, he multiplies his profits quickly. After a short time he acquires a cart to transport several dozen boxes of tomatoes, only to have to trade it in again so that he can buy a pickup truck to support his expanding business.

By the end of the second year, he is the owner of a fleet of pickup trucks and manages a staff of a hundred former unemployed people, all selling tomatoes.

Planning for the future of his wife and children, he decides to buy some life insurance. Consulting with an insurance adviser, he picks an insurance plan to fit his new circumstances. At the end of the telephone conversation, the adviser asks him for his e-mail address in order to send the final documents electronically.

When the man replies that he has no e-mail, the adviser is stunned. "What, you don't have e-mail? How on earth have you managed to amass such wealth without the Internet, e-mail and e-commerce?

Just imagine where you would be now, if you had been connected to the Internet from the very start!"

After a moment of thought, the tomato millionaire replied, "Why, of course! I would be a floor cleaner at Microsoft!"

The infamous first...

This first post is just a little about me...

I am a Java programmer working in the hospitality industry. I have experience with the following programming languages: C, C++, C#, VBScript, Visual Basic 6.0, Visual Basic.NET, JavaScript, Java(J2SE, J2EE), J++, J#, HTML, XML, Perl (very little, so far), & SQL.

My website is located at http://www12.brinkster.com/cvermule/.

I also have certifications at http://www.brainbench.com/, transcript ID 4655166.

I have a wife of 2 years this September 21st. No kids, but we're trying. Closest to a child right now is our cat Kira. She is our spoiled brat.