Friday, May 29, 2009

C# 3.5 Try-Catch-Finally

Will a 'Finally' block be executed if a return statement is called in a Try-Catch?

Yes, the 'Finally' block is always executed, even if a goto, or return statement is called.

Thursday, May 28, 2009

Active Armor Firewall UnInstall

I found out how to uninstall Active Armor firewall for the Asus M2N32-SLI DELUX motherboard. Under ControlPanel Add/Remove Programs on Windows XP Professional, the program to uninstall is NVIDIA Forceware Network Access Manager.  Uninstall this program and active armor will be uninstalled also.

Wednesday, May 27, 2009

Javascript Confirmation Dialog

I was trying to get verification from the user on a delete command. This may not be the correct solution.

I needed a button, when the user clicks, a pop-up form asking "Are you sure?" appears. If the user selects 'Cancel', nothing happens. If the user selects 'Ok', then the data is deleted.

I developed this solution:



I am using the submit, because I have a hidden field that is set with a value depending on what the user has chosen to do. This is the reason for doing nothing on 'ok' and something on 'cancel'.


*************************************************
11/25/2009

I think this is a more versatile solution.

//***************************************************
// Name: Form Submit
// Parameter [formId] : this is the Id of the form to
// submit.
// Parameter [verify] : 'true' if the form needs a
// confirmation before submitting, any other string
// if the form does not need confirmation.
// Parameter [message] : Message to show if the form
// needs validation.
//**************************************************
function formSubmit(formId, verify, message) {
if (verify == "true") {
if (confirm(message)) {
document.getElementById(formId).submit();
}
}
else {
document.getElementById(formId).submit();
}
}

MySQL Log

To have MySQL log queries on the database, you need to locate your mysql server folder,

usually C:/Program Files/MySQL/MySQL Server.../

In this folder, there should be a file named 'my.ini' or 'my.cnf'.

This file contains global options for the MySQL server.  You can modify this file with the 
'log="[Drive]:/[~Path]/[filename].log"' command.  Put this relatively close to the 

'[mysqld]' heading, but below it in the file.

Restart MySQL server.  You should find a [filename].log file where your path was set.

This is the log file for mysql server, it will log all queries on the databse.

If you want to log all errors, put this command close to the previous command,
'log-error="[Drive]:/[~Path]/[filename]error.log"'.  This will log all errors.

This is for my edition of MySQL Server 5.0.

Commands for Windows Command Prompt

This is a list of cool commands:

echo %windir%             - this command is for locating the Windows directory.
. - this command is for the current directory.
.. - this command is for the parent directory.

mysqld & Options

If you want to run the 'mysqld' command with its options, don't forget that you need 

'mysqladmin -u [username] -p[password] mysqld --[option]...'

You need to do the mysqladmin...username stuff or it won't work.  Yes, this seems common sense, but no one ever explains this part.  This is, also, an instruction for Windows command prompt and not mysql.

Friday, May 22, 2009

HTML input checkbox

The html input tag 'checkbox' will beck checked no matter what value it is set to the attribute 'checked'.  For instance,

checked='' ... or ... checked='checked' ... or ... checked='true' ... or ... checked='false'

will all set the checkbox to checked.

The 'checked=[value]' needs to be totally removed from the attribute list if a non-checked checkbox is desired.

Thursday, May 21, 2009

Restore MySQL Database

When restoring a database backed-up with mysqldump ...   don't use the 'mysqldump' command to restore.  

To restore the database use 'mysql'.

'mysql -u [name] -p[password] < [filename].sql'

Wednesday, May 20, 2009

MySQL Dump

I was trying to figure out how to use 'mysqldump', and there are a few KEY points that people leave out when trying to explain how to use it.

1.    DON'T be in mysql command line client when trying to use this command.  It seems common sense, but until you know, you don't.
2.   When trying to give the password -p option, make sure there is NO space between the -p and your password. (e.g mysqldump -u [name] -p[password] --all-databases > alldb.sql)
Notice how there is NO space between the 'p' and 'password'.  There was only one example that used this that I found.  Every other example showed a space.  It may work on MySQL 5.1+, but it does not work on my copy of MySQL 5.0.

Tuesday, May 19, 2009

Adding a DateTime to a MySQL database

I wanted to add a datetime in an ASP.NET MVC application talking to a MySQL database.  I needed the date in the correct format in order to add it to the database.

This is one way to do it.

The data "cell" that will hold the datetime needs to be a 'DATE' type in MySQL.  Then, the user can set the Month, Day and Year needed.  (e.g. 1/2/2009).

This is the format I used, but you can modify it as according to your application.

So, when adding the date to your database, during your query :

table.datecell = STR_TO_DATE(' " + dateVariable + " ', '%m/%d/%y')

The format %m/%d/%y is month/day/year.  This will set the value of the cell to the date and with a time.

Saturday, May 9, 2009

Replacing characters within strings with Javascript

I found out today how to replace characters within a string using Javascript.

It's not hard.

First, you take the string that has characters that need replacing.

You make a regular expression of the characters that need replacing. -> this uses the javascript RegEx("string") function.

You make a variable to hold the new string that is generated from the replacing.

You have a new string with replaced characters.

In the following example, I wanted to replace a string with the empty string, removing the unwanted characters.



temp will have the value of  "1,,3,4".

If you want to take the comma out, also, just put "2," into the regular expression function.

The regular expression function generates a regular expression that is understandable to javascript.  The first code would generate /2/ while the second code would generate /2,/.

Hope this helps.

Wednesday, May 6, 2009

Talking Point

There was just one thing I wanted to say to Ken (4100) about his "settings".

Tuesday, May 5, 2009

C++ list::iterator

So, I found out today that you can't do a "less than" comparison on list iterators.

For instance, if you want to iterate through a list with a for loop, you must do a != comparison, instead of a < comparison usually used in for loops.

for( list::iterator t = myList.begin(); t != myList.end(); t++)
{
// some code
}

This is a sample of proper code to iterate through a list using iterators.