Tuesday, November 16, 2010
Emergency DNS
Found a site that provides free DNS service. Their blog hasn't been updated in four years though…
Tuesday, December 2, 2008
C#: DateTime.ToString()
Looking for simple, direct examples of what the various DateTime conversion functions do which MSDN was completely incapable of providing. Found a great tutorial article that summarized them nicely:
result = theDate.ToString("y"); // result = "January 2007"| Specifier | Description | Example |
|---|---|---|
| d | Short date format. This is equivalent to using ToShortDateString. | "03/01/2007" |
| D | Long date format. This is equivalent to using ToLongDateString. | "03 January 2007" |
| f | Date and time using long date and short time format. | "03 January 2007 21:25" |
| F | Date and time using long date and time format. | "03 January 2007 21:25:30" |
| g | Date and time using short date and time format. | "03/01/2007 21:25" |
| G | Date and time using short date and long time format. | "03/01/2007 21:25:30" |
| m | Day and month only. | "03 January" |
| r | Date and time in standard Greenwich Mean Time (GMT) format. | "Wed, 03 Jan 2007 21:25:30 GMT" |
| s | Sortable date and time format. The date elements start at the highest magnitude (year) and reduce along the string to the smallest magnitude (seconds). | "2007-01-03T21:25:30" |
| t | Short time format. This is equivalent to using ToShortTimeString. | "21:25" |
| T | Long time format. This is equivalent to using ToLongTimeString. | "21:25:30" |
| u | Short format, sortable co-ordinated universal time. | "2007-01-03 21:25:30Z" |
| U | Long format date and time. | "03 January 2007 17:25:30" |
| y | Month and year only. | "January 2007" |
Tuesday, February 12, 2008
MSACCESS: Searching for Wildcards
Still end up using Microsoft Access alot when manipulating data. Since it uses the old Microsoft wildcard characters, I often forget how to search for the wildcards themselves. Found a good article that summarizes how to do just that:
| Search string | Match list setting | Results |
| [*] | Any Part of Field | Returns all records that contain an asterisk (*). This syntax also works for question marks (?), number signs (#), opening brackets ([), and hyphens (-). |
| Whole Field | Returns records that consist only of an asterisk. | |
| Start of Field | Returns records that start with an asterisk. | |
| *[*]* | Any Part of Field | Returns all records that contain an asterisk (*) and any surrounding text. This syntax also works for question marks (?), number signs (#), opening brackets ([), and hyphens (-). |
| Whole Field | Same result. | |
| Start of Field | Same result. | |
| [!*] | Any Part of Field | Returns all records that do not contain an asterisk. Keep in mind that this search pattern can return every letter of every word in a record when you use this setting in the Match list. This syntax also works for question marks (?), number signs (#), opening brackets ([), and hyphens (-). Note The search string *[!*]* will return records that contain asterisks because it finds all the text that surrounds the asterisk. |
| Whole Field | Returns no results at all. | |
| Start of Field | Returns the first letter of any record that does not contain an asterisk. | |
| ma*[ch] | Any Part of Field | Returns all records that contain "ma" and either "c" or "h". For example, this string returns "march" and "match", and it also returns "math" and "manic". |
| Whole Field | Returns all records that start with "ma" and end with either "c" or "h". For example, this string returns "march" and "match", and it also returns "math" and "manic". | |
| Start of Field | Returns all records that start with "ma" and contain "c" or "h". | |
| ma*[!ch] | Any Part of Field | Highlights the letters "m" and "a" and all text that follows those letters until it encounters a "c" or an "h". The following figures illustrate this. | March | | Match | In other words, even though you're trying to exclude records that contain "c" and "h", you may see those records because Any Part of Field matches the text that precedes the brackets. |
| Whole Field | Returns all records that do not contain a "c" or an "h" if those records end in "c" or "h". For example, the find operation does not return "manic" because the word ends with a "c", but it does return "maniacal" because characters follow the "c". | |
| Start of Field | Returns those records that start with "ma". Again, Access matches any text that precedes the characters enclosed in brackets, so you may see unwanted results. |
Tuesday, July 10, 2007
C#: Drag'n'Drop
Been wanting to do an organizer for all the images I steal off the web. One of the first things I need to know how to do is to support drag'n'drop from the browser. Instead of going to a directory, I want the file to go to my vault.
Started out with a "C# drag drop" Google. First thing that came up was a six-year-old article from C-Sharp Corner. Was a simple file brower example that was pretty hard to follow. It was dated information anyway.
There was a very succint Microsoft knowledge base article that was more helpful. The example is doing something akin to what I'm looking to do: receiving a file or files dragged from elsewhere onto a listbox. It was pretty easy to put together and worked on first compile. Dropping an image from IE or Firefox over the list box would show the full path to the image's temporary file.
I wondered what else would be available so I went to the definition of DataFormats—there were twenty-one! They reminded me of clip board data types. Went to the MSDN summary and it covers how to create your own format for use on the clipboard.
Next I was wondering if I could access those other types. From the way I see Paste Special work in Microsoft applications, I suspected that the clipboard could make data available in multiple formats (unless they parse a rich source in your selected way). I was hoping the HTML format might include the URL source of the image I was dragging.
So I added another list box I called lstFormat and added the following code to the DragDrop event:
Now I need to spend some time figuring out how to work with these other formats.
Started out with a "C# drag drop" Google. First thing that came up was a six-year-old article from C-Sharp Corner. Was a simple file brower example that was pretty hard to follow. It was dated information anyway.
There was a very succint Microsoft knowledge base article that was more helpful. The example is doing something akin to what I'm looking to do: receiving a file or files dragged from elsewhere onto a listbox. It was pretty easy to put together and worked on first compile. Dropping an image from IE or Firefox over the list box would show the full path to the image's temporary file.
I wondered what else would be available so I went to the definition of DataFormats—there were twenty-one! They reminded me of clip board data types. Went to the MSDN summary and it covers how to create your own format for use on the clipboard.
Next I was wondering if I could access those other types. From the way I see Paste Special work in Microsoft applications, I suspected that the clipboard could make data available in multiple formats (unless they parse a rich source in your selected way). I was hoping the HTML format might include the URL source of the image I was dragging.
So I added another list box I called lstFormat and added the following code to the DragDrop event:
GetFormats has an overload that I specified false initially. By setting it to true, I got a larger list of all formats the source could be converted to. Very handy.lstFormat.Items.Clear();
String[] formats = (string[])e.Data.GetFormats(false);
foreach (String format in formats)
{
lstFormat.Items.Add(format);
}
Now I need to spend some time figuring out how to work with these other formats.
Monday, June 18, 2007
C#: Modulus Operator
Wasn't sure what the modulus operator was in C#. Google came back with this snippet that shows how it can be used to determine even and odd integers:
The code uses C#'s Modulus Operator (%). How this works is the operator computes the remainder after it divides it's first operand by the second. In the case below, the number of controls (i.e. count) is divided by 2. If it's an even-numbered row there won't be a remainder and if it's an odd-numbered row....I just needed to know it's the percent sign; definitely miss the readability of QuickBasic's MOD command. While that snippet is pretty elementary, it's a good example of how to use the modulus.if (_pnlMenuItems.Controls.Count % 2 == 0)
{
newMenuItem.BackColor = System.Drawing.Color.LightBlue;
}
else
{
newMenuItem.BackColor = System.Drawing.SystemColors.Window;
}
Wednesday, May 2, 2007
ASP.NET: Returning the Name of the Current Page
Couldn't find a VB6 equivalent to Form.Name so I started Googling. Found someone on a random forum wanting to log a page that caused an error, minus the virtual or physical path.
The first response suggested: “Using Page.GetType().Name will return "YourPageName_aspx". Replace the underscore with a dot.” Interesting idea but the filename might contain other underscores, so I'd have to be sure to only replace that last one.
The second response provide a means of iterating through all of the ServerVariables:
Since the first suggestion is a parse anyway, I decided to work with the seemingly appropriate FilePath property on the Request object instead of the type. The page doesn't use regular expressions for anything else, so I settled using String methods:
The first response suggested: “Using Page.GetType().Name will return "YourPageName_aspx". Replace the underscore with a dot.” Interesting idea but the filename might contain other underscores, so I'd have to be sure to only replace that last one.
The second response provide a means of iterating through all of the ServerVariables:
I wasn't aware of the NameValueCollection, so I'll have to look into that for future use. But I don't want to rely on accessing a named hash inside the server variables.using System.Collections.Specialized;
int loop1, loop2;
NameValueCollection coll;
// Load ServerVariable collection into NameValueCollection object.
coll = Request.ServerVariables;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
Response.Write("Key: " + arr1[loop1] + "
");
String[] arr2 = coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++)
{
Response.Write("Value " + loop2 + ": " + arr2[loop2] + "
");
}
}
Since the first suggestion is a parse anyway, I decided to work with the seemingly appropriate FilePath property on the Request object instead of the type. The page doesn't use regular expressions for anything else, so I settled using String methods:
private string GetPageName()
{
String localFile = Context.Request.FilePath;
if (localFile.Contains("/"))
{
Int32 position = localFile.LastIndexOf("/");
localFile = localFile.Substring(position + 1);
}
return localFile;
}
Subscribe to:
Posts (Atom)