VB.NET Color Dialog Return String Value

Here recently I have been working more and more with Visual Studio again, and more specifically the Color Picker / Color Dialog control. For my purposes, I wanted the user to pick a color, and that color to then populate a text box in the form of an HTML compliant hex value, in other words, I need the result from the color picker as a string. Now, in VB.NET 2010 which is what I am using, the result from the color picker is in a format that is primed and ready to apply to a control, to change its fore or back round color. It does not give you a value in string format. So, I had to do a good bit of searching and work to figure this out.

Basically, what I ended up with was a function that you run the color picker response or value through. It’s pretty simple really:

Public Function Color2Html(ByVal MyColor As Color) As String
  Return "#" & MyColor.ToArgb().ToString("x").Substring(2).ToUpper
End Function

That’s it, that will return to you a hex color code formatted for HTML use. Just in case you are unsure of exactly how to use the function, this is the code I use with my color picker control (I use a standard button to fire it off with the result going into a text box):

Private Sub btnColor1_Click(sender As System.Object, e As System.EventArgs) Handles btnColor1.Click
  Dim NewColor As New ColorDialog()
  NewColor.AllowFullOpen = True
  NewColor.ShowHelp = True
  If (NewColor.ShowDialog() = Windows.Forms.DialogResult.OK) Then
    txtColor.Text = Color2Html(NewColor.Color)
  End If
End Sub

That’s all there is too it. I hope this helps you get your string data from your Color Dialog / Color Picker control. Enjoy!

Bash function for making locate find exact matches

This is one of the coolest and most useful things to add to my UNIX/Linux profile that I have come across in a long time. I use the locate command a lot (slocate naturally) as I am sure all of us command line monkeys do. How many times have you been frustrated by the billions of lines of results flying by your screen, piping through more or less, trying to find the one nugget of goodness that you really need? Especially when you actually know the correct name of it, just not where it lives? This is where this comes in handy (this is where this? man I am eloquent)! Add this function to your bash profile (for some that’s .bash_profile and for others it might be .bashrc, depending on your nix flavor) and you can stop all of that. I haven’t tried this with other shells aside from bash, but I don’t see why it wouldn’t work.

Basically, this function uses the locate command to find whatever you are looking for just like you do, only it uses a bit of scriptology to filter it down to the exact match of what you are looking for. Yep, that’s right, the exact match! This little tidbit can really help out when you are looking for something, take a look:

## BASH locate function for exact match
## Thanks Dark_Helmet : http://solarum.com/v.php?l=1149LV99
function flocate
  if [ $# -gt 1 ] ; then
  while [ ${current_argument} -lt ${total_arguments} ] ; do
    if [ "${display_divider}" = "1" ] ; then
      echo "----------------------------------------"
      echo "Matches for ${current_file}"
      echo "----------------------------------------"
    filename_re="^\(.*/\)*$( echo ${current_file} | sed s%\\.%\\\\.%g )$"
    locate -r "${filename_re}"
    (( current_argument = current_argument + 1 ))

It’s just that easy! Copy and paste this into your profile and add a cool helper addon companion function thingy 🙂 I wish I could say I came up with this myself, but I didn’t, I found it in some forums posted by someone named Dark_Helmet (just like the attribution link in the script). I don’t know who you are Mr. Helmet, but I thank you for your sharing this with us all, and I am passing it on! Enjoy!

Solarum’s Open Source Project – nix32

I thought I would post some information about a project that I started a few months ago called nix32.  It’s hosted on SourceForge for the most part, with a handy website that I host myself mainly because it’s just easier to manage that way.  The basic goal of this project is to create native command line tools for Windows that operate much like the commands that we know and love from Linux and UNIX.  Things like ls, mv, cp, df and so on.  I have become so used to, comfortable with and productive with the UNIX/Linux command line environment, that when I have to leave it behind on Windows, it’s pretty tough.  Not just changing from what I am used to, but also because I think the command line of a UNIX/Linux server is much more powerful and flexible than the Windows command line, even including the power shell.

I have been working on the more popular commands, and I have a few basics out now with basic functionality.  I hope to have more and better (improved) tools in the future.  I am writing everything in PERL and then compiling each one on Windows as a standalone exe using tools from ActiveState, and so far, they run very nicely.  It’s all completely open source, you can download the PERL scripts as well as the executable files if you want to take a look or help improve them.

Now, I know you can get similar results with other projects and products out there, CYGWIN comes to mind first.  However, that’s a whole separate shell and almost a little mini-Linux setup in and of itself, especially looking at the directory structure after it’s installed.  Here with the nix32 project I wanted to have native Windows executables that you can stick in your path somewhere and call right from the Windows Command Prompt, without ever leaving the Windows environment and without having to install anything.  So far that is exactly what we have, just copy the files somewhere, make sure it’s within or added to your PATH variable, and you are good to go!

So check it out, see what you think, spread the word and maybe even help out a bit and crunch a little code too.  Do whatever you feel and keep both feet on the wheel … or, keyboard maybe.  🙂

Awesome Source Code Library

(Click to enlarge)

OK, boys and girls, I have a really cool treat for you.  For a long time now I have been looking for the right application to use as a source code library.  I say application because I have been trying to be open minded about what to use.  I have tried Wiki’s (which actually aren’t too bad), note taking programs, and a great many other tools, including a couple that were specifically written to be source code libraries … but in the end fell quite short of my expectations.  Also, when I say source code library, I am not and have not been looking for tons of canned code to take advantage of, that’s the problem I have now, 20+ years in IT and I already have tons of code, I just need a way to store it, sort it, search it, export it, back it up, and anything else I can think of!  I’d like to note too that in addition to all of the other features I may list here, this tool does a superb job at syntax highlighting as well.

Let me digress for a moment to mention a site called Donation Coder (www.donationcoder.com), these guys are great!  Lots of free software from some really talented developers.  There are some apps there that beat their commercial competition by a country mile, hands down.  That’s one reason why I like to hang out there, in the forums for example, these guys write software because they enjoy writing software.  Therefore they create some wicked cool stuff.

How does this pertain to the issue at hand?  Well, it was in the forums there that I ran across a thread where people were talking about their own search for a source code library much like my own search.  I found one post among others recommending different things that mentioned a free tool called “Developer’s Tips & Tricks (DTT)” from Freesoftland.  I had never heard of this group before, but I liked what I had seen posted in the Donation Coder forums, plus I really liked what I saw when reading up on their DTT tool.

Continue reading

Visual Basic dot NET – Making a button the form default

Here is a quick tip for any and all of you VB slimming pills that work.NET heads out there.  Need to make a button on your form the default one to fire off when you hit the enter key (while that form has focus naturally)?  In the old days, it was a button property, and now it has become a form property.  It actually kind of makes sense when you think about it.  I mean, you can only have one default button on a form, right?  Anyway, go to the properties of the form in question and look for an option called “AcceptButton”.  This will be a drop down list comprised of all the buttons that have been placed on the form.  Pick the one you want as the default and there you have it, your button is ready to go!  Hope that helps …

Hosted Subversion and a whole lot more at CodeSpaces

CodeSpaces LogoGreetings folks, I’d like to take a moment to share with you something that I found a while back and have been using since I found it.  What I found was a service, a source code hosting service fully integrated with Subversion.  Now, I had already been using Subversion, I had it setup and running on my own servers in my lab.  I had even looked at the idea of commercial Internet based Subversion hosting since it would put my source code archive off-site and accessible from outside my lab, but the providers and plans I found were either expensive, feature light, or just didn’t seam to be a quality service provider.  Usually more than one of those things.  Besides, I am very picky about where I put my source code.  Call me paranoid, but I don’t toss code around anywhere, I have to be comfortable that it’s in a safe and secure place.

So, now enter Code Spaces, the best hosted Subversion I have ever seen, even over hosting it myself.  The service is superb and the features included go way beyond simple Subversion hosting.  In the end, between the ease of use and the extra goodies that they include with the service, not to mention the reasonable price, I believe in the long run I am saving money over hassling with doing it myself.  Not to mention my code is now safely archived off site, which is great for disaster recovery.

Now, what all do they provide other than great Subversion hosting?  Take a look:

  • SSL Encryption
  • Real Time Backups
  • Project Management Tools
  • Bug Tacking Tools
  • Project Milestones and Task Setup
  • A 45 Day FREE Trial
  • A Money Back Guarantee

There’s more to it than that, but you really have to go check out their site to get a handle on all that they offer.  Frankly, if this type of service is something that you want or need, I’d give them a shot for the 45 day free trial.  That’s what I did and I was blown away by how good their service is.  Check them out at http://www.codespaces.com today!  By the way, if anyone is interested, this is not a paid endorsement.  I don’t get any kickbacks or consignments if you sign up and they didn’t pay me or give me a credit/discount for this post, I just like the service that much that I wanted to share it with all my visitors.  Enjoy!