BPSoftware.com
Home   Utilities   Purchase   FAQ   Support   Contact        
Shareware Utilities
 APrintDirect
 AIconExtract
 AFile Attribute Manager
Freeware Utilities
 AddrMon
 AFileSync
 ASysIcon
 B&P Table Utilities
 BPACLer
 BPSNMPMon
 BPSNMPUtil
 CharCount
 Delphi® Components
 MacAddr
Miscellaneous
 BPSoftware Blog
 Purchase Shareware
 Support

 


Sunday, February 26, 2006
Around the network of silken thread

Blogs are becoming a more and more popular part of the ‘World Wide Web’. I think they are a great expression and communication medium. I browse through many blogs, and some grab my interest enough for me to visit daily. During this morning’s rounds I came across this blog posting. I think Jake discusses a number of key points in his posting.

Labels: , ,

posted by Brad Prendergast at 9:29:00 AM (0 comments)
Links to this post
Permalink
Saturday, February 25, 2006
I did not win

Lately, all of my focus has been on the Olympics so things have been a little quiet. In my last post I talked about an ASP.NET Random Number Generator created with BDS 2006. Believe it or not, it is surprisingly simple to get something like this up and running. I have worked on a number of ASP.NET applications developed with BDS 2006, in both the internally and externally hosted environments. Typically, any SNAFUs that I have encountered (excluding code typos and incorrectness) have been due to server configuration issues and not a problem with the tool used to create the application.

To get the Random Number Generator running I first needed a Virtual Directory on the server hosting the application. I started out with a new ASP.NET Web Application and saved it with the same name as the application name for the Virtual Directory (by default it the name of the virtual directory).

I then created a ‘form’ and decorated it with a few items from the Web Controls section of the Tool Palette.


With the layout of the form in place a few lines of code were needed to get things going (I created a few functions of my own for dealing with input):

function TWebForm1.IsNumeric(str: string): Boolean;
var
code: integer;
v: integer;
begin
Val(str,v,code);
Result:= (code = 0);
end;

function TWebForm1.ToInteger(str: string): Integer;
var
code: integer;
v: integer;
begin
Val(str,v,code);
if (code = 0) then
Result:= v
else
Result:= 0;
end;

procedure TWebForm1.txtCount_TextChanged(sender: System.Object; e: System.EventArgs);
begin
if Not(IsNumeric(TextBox(Sender).Text)) then
begin
TextBox(Sender).ForeColor:= Color.Red;
TextBox(Sender).Font.Bold:= True;
TextBox(Sender).Text:= '#ERROR#';
end
else
begin
TextBox(Sender).ForeColor:= Color.Black;
TextBox(Sender).Font.Bold:= False;
end;
end;

procedure TWebForm1.btnGenerate_Click(sender: System.Object; e: System.EventArgs);
var
i, y: Integer;
z: single;
lowerbound, upperbound, counter: integer;
intRnd: Single;
// mylist: System.Collections.Hashtable;
mylist: System.Collections.SortedList;
st: System.Text.StringBuilder;
DictEntry: DictionaryEntry;
Enumerator: IEnumerator;
begin
// mylist:= Hashtable.Create;
myList:= SortedList.Create;
lbNumbers.Items.Clear;
lbStats.Items.Clear;

upperbound:= ToInteger(txtUpperBound.Text);
lowerbound:= ToInteger(txtLowerBound.Text);
counter:= ToInteger(txtCount.Text);

if (IsNumeric(txtUpperBound.Text) and
IsNumeric(txtLowerBound.Text) and
IsNumeric(txtCount.Text)) then
begin
Randomize;
For i := 1 To counter do
begin
intRnd := Int((upperbound - lowerbound + 1) * Random + lowerbound);

// HashTable for statistics
if Not mylist.ContainsKey(intRnd.ToString('#,###')) then
mylist.Add(intRnd.ToString('#,###'),'1')
else
begin
y:= ToInteger(mylist.Item[intRnd.ToString].ToString) + 1;
mylist.Item[intRnd.ToString]:= y.ToString('#,###');
end;

if (chkDupes.Checked and
(lbNumbers.Items.FindByText(intRnd.ToString('#,###')) = Nil))
or Not(chkDupes.Checked) then
lbNumbers.Items.Add(intRnd.ToString('#,###'));
end;

// enumerate hash for statistical output
Enumerator := Mylist.GetEnumerator;
st:= StringBuilder.Create;
while Enumerator.MoveNext do
begin
st.Remove(0,st.Length);
DictEntry := DictionaryEntry(Enumerator.Current);
z:= (ToInteger(DictEntry.Value.ToString)/counter * 100);
st.Append(z.ToString('00.00') + '% - ');
st.Append(DictEntry.Key.ToString + ' - (');
st.Append(DictEntry.Value.ToString + ' entries)');
lbStats.Items.Add(st.ToString);
end;
end;
end;


That’s pretty much all the code that is needed. In order to ‘manually publish’ the application, after testing the code and ensuring the application functions as desired, copy the .DLL from application’s Bin directory and the form’s .aspx file to the hosting site (if you do not have a web.config file on the published site you will need to copy that file as well).

With BDS 2006 you can get this up and running rather quickly, I think it takes longer to write this post; unfortunately it didn’t serve up any winning numbers for me…….

Labels: , , ,

posted by Brad Prendergast at 12:53:00 PM (0 comments)
Links to this post
Permalink
Saturday, February 18, 2006
Please Pick Me!

With this weekend’s Powerball Jackpot reaching $365 Million, who isn’t tempted to purchase a ticket or two. Let’s limit that question to those that are both geographically and physically capable of purchasing a ticket. I have never been a big lottery participant. When I do venture out to get a ticket, the troublesome task of picking the ‘winning’ numbers makes me sweat. I am a logical guy, and I try to come up with some sort of ‘logical’ reasoning behind my selection, which requires a lot of work. So, needless to say I always opt for the ‘quick pick’ route. That’s right, let the computer pick the numbers for me. Having a little extra time, after reading Marco’s book (for a second time) and having spent an abundant amount of time in Visual Studio in the past few weeks, I decided to whip something up with my favorite IDE. The results: a ‘Random Number Picker’ (notice the logo). Click here for the results.

This random number picker (I am not looking for any debates on the randomness of the numbers) allows you to enter the number of numbers you would like returned as well as the upper and lower bounds of the numbers returned. If you want more of a ‘most popular’ number, each number’s percentage and number of times listed is also displayed.

There are a couple additions I want to make over the next day or so, like an option to allow duplicate numbers or not – (hey, some lotteries allow it) and formatting for my browser of choice - FireFox (it looks fine in IE). After that I will post the source up.

If anyone else has any suggestions pass them along…..

Oh, and use of the random number generator for lotteries or any other ‘thing’ does not guarantee or increase your chances of winning anything. It is intended to be just one other way for me to pick numbers….

‘Random Number Picker’

Labels: , ,

posted by Brad Prendergast at 5:29:00 PM (0 comments)
Links to this post
Permalink
Thursday, February 02, 2006
CursorText

Looking back on a post made in response to a question about changing a cursor to text, I decided to change the code around a little for use in a local utility. The idea is to display ‘text’ as a cursor instead of an ‘image’. I toyed with passing a TIcon (a cursor and icon are the same structure) back as a back as a function result and passing a preexisting TIcon as a parameter. After coming up with an overloaded function, passing it back ‘felt better’. However, I prefer that the ‘cursor’ be created and destroyed outside of the function.

A function is as follows:

function TForm1.CreateCursorText(thecursor: TIcon; const cursortext: string;
fontcolor: TColor; fontsize: Integer; hs: TPoint): Integer;
var
iconwidth,
iconheight : integer;
bmpColor: TBitmap;
r: TRect;
iconinfo: TIconInfo;
begin
bmpColor:= TBitmap.Create;
try
iconwidth:= GetSystemMetrics(SM_CXCURSOR);
iconheight:= GetSystemMetrics(SM_CYCURSOR);
r.Top:= 0;
r.Left:= 0;
r.Bottom:= iconheight;
r.Right:= iconwidth;

bmpColor.Height:= iconheight;
bmpColor.Width:= iconwidth;
bmpColor.Canvas.Brush.Color:= clBlack;
bmpColor.Canvas.FillRect(r);
bmpColor.Canvas.Font.Size:= fontsize;
bmpColor.Canvas.Font.Color:= fontcolor;
bmpColor.Canvas.TextOut(2,2,cursortext);
bmpColor.TransparentColor:= clBlack;

iconinfo.fIcon:= False;
iconinfo.xHotspot:= hs.X;
iconinfo.yHotspot:= hs.Y;
iconinfo.hbmMask:= bmpColor.MaskHandle;
iconinfo.hbmColor:= bmpColor.Handle;
thecursor.Handle:= CreateIconIndirect(iconinfo);

DeleteObject(iconinfo.hbmColor);
Result:= 1;
finally
bmpColor.Free;
end;
end;

An example of how to use it would be something like:

const
crMyCursor = 5;

var
aicon: TIcon;
oldcursor: TCursor;
hotspot: TPoint;
begin
aicon:= TIcon.Create;
try
hotspot.X:= 3;
hotspot.Y:= 2;
CreateCursorText(aicon, edit1.Text, clBlue,8,hotspot);
oldcursor:= Screen.Cursor;
Screen.Cursors[crMyCursor]:= aicon.Handle;
Screen.Cursor:= crMyCursor;
//do something
finally
Screen.Cursor:= oldcursor;
aicon.Free;
end;
end;

Labels: , ,

posted by Brad Prendergast at 5:58:00 PM (1 comments)
Links to this post
Permalink
Wednesday, February 01, 2006
A Few Good Shows

I have never been a television or movie buff. A vast majority of my time is spent in front of a computer. A typical day finds me with about 13 hours in front of ye ole' monitor, followed up by some technical reading (two of my recent selections are here and here). This has been going on for so long that I haven’t a clue about much primetime television. If I am watching television it is typically sports, TLC, Discovery or the History channel. (TechTV used to be there until G4Tv completely killed it) Besides the Revolution, Patriots, Red Sox and the morning news it is rare for me to have a ‘must see’ television show.

I do have shows that I enjoy a lot (Dirty Jobs), but none I can say that cause me to drop everything. Someone did recently tell me to watch The Office. I caught an episode last week and though it was hilarious. The jury is still out though....

Over the past few months I must say I finally found a 'must see' --Criminal Minds. This show has me hooked and I can now say that there is a show that without a doubt I’d turn of the computer for. Wednesday nights now are on my calendar. With my luck, they’ll end up canceling it, which, well, would piss me off. Remember The 4400?

Labels:

posted by Brad Prendergast at 8:34:00 PM (2 comments)
Links to this post
Permalink
Recent Posts
 Command Line: Visual Source Safe
 SQL: Remove / Delete Orphan Users
 SQL Delete/Drop a User from each Database
 Is there an 'I' in phone?
 SQL Optimization: Am I missing any indexes? - Part...
 Meaningful Signature File Quotes
 My Shared RSS Items
 Edit those XML files
 A little System.Diagnostics
 Wi-Fi Detector Shirt


Labels



Archives
 October 2005
 November 2005
 December 2005
 January 2006
 February 2006
 March 2006
 April 2006
 May 2006
 June 2006
 July 2006
 August 2006
 September 2006
 December 2006
 January 2007
 February 2007
 March 2007
 September 2007
 October 2007
 November 2007
 July 2008
 November 2008
Powered by Blogger