Converting *nix files to Win text files

June 25, 2009

I don’t know why it took me so long to do this.  I regularly download files, only to open them up to see that they were created on a *nix computer.  That means it uses CR to symbolize the end of a line rather than CRLF, which is the common end of line on a Windows system.  As part of another project that I am working on, I downloaded a huge archive of spam and regular email.  The only problem was all of the files used CR instead of CRLF.  That, and they didn’t have an extension, so I had to choose each time to open it with Notepad.

So I went into VB.Net, and made a quick and dirty form that recursively looked at each subfolder and converted each file.  As part of the conversion, it was changed to a .txt file, and the original was deleted.

Here is the code to do that:

Private Sub ConvertFile(ByVal fi As FileInfo)
  If fi.Extension = ".txt" Then Return

  Dim r As New FileStream(fi.FullName, FileMode.Open)
  Dim d As New StreamReader(r)
  Dim s As New FileStream(fi.FullName & ".txt", FileMode.Create)
  Dim w As New StreamWriter(s)
  Dim str As String = ""
  Do While Not d.EndOfStream
    w.WriteLine(d.ReadLine)
  Loop
  d.Close()
  r.Close()
  fi.Delete()
  w.Flush()
  w.Close()
  s.Close()
  _fileCount += 1
  lblOutput.Text = "Converted " & _fileCount & " files."
  Application.DoEvents()
End Sub

Hopefully this will help anyone having the same type of frustrations.


Idiotic decisions

June 27, 2008

Today my company purchased a new 1TB external drive.  My laptop has 2 120GB hard drives in it, but I keep running out of room. 

The hard drive I purchased is a Western Digital.  When I got home I started copying files from the internal hard drives to the external one.  Did I pay attention to the format of the drive?  Of course not.  Why would a company make a 1TB drive and format it as FAT32?  Beats me.  When I tried copying all of my virtual machines to it, I got the error that the drive was full.  It wasn’t full, but FAT32 cannot hold a file that is larger than 4GB.  Some of my virtual hard drives are 16GB.

So I had to move everything back off of it, format it as NTFS, then start the moving again.  Oh well, at least my laptop hard drives will have room to breathe again!


VB.Net CF Scrolling textbox

March 24, 2008

It took me awhile to figure this one out.  I needed a textbox that would scroll the text off the left side of the textbox.  It also needed to be able to have more than one string to display.  It would cycle through the strings, changing from the current string to the next string when the current string has scrolled off the screen.

I was able to find a lot of examples on the Net, but none of them worked quite right.  One didn’t work at all, one caused the program to crash while debugging (which kicked VS out of debug mode like I had clicked stop debug!), and the last one worked, but did not meet my requirements.  The one that worked scrolled the text to the right.  And it had some interesting code to it.  That example was found here .

What I came up with was a UserControl as follows:

  Private mStartPos As Integer
  Private mText As Collection
  Private mTextNum As Integer = 1
  Private mScrollSpeed As Integer = 1

Public Sub New()
  ' This call is required by the Windows Form Designer.
  InitializeComponent()
  mText = New Collection()
  mStartPos = 0
  Timer1.Enabled = True
End Sub

This sets up the form. I added a Timer to the designer that is used to update the scrolling. There are also some public accessor subs/properties:

Public Sub AddMarqueeText(ByVal str As String)
  If str <> "" Then
    mText.Add(str, str)
  End If
End Sub

Public Sub RemoveMarqueeText(ByVal str As String)
  If str <> "" Then
    mText.Remove(str)
  End If
End Sub

Public Property ScrollSpeed() As Integer
  Get
    Return mScrollSpeed
  End Get
  Set(ByVal value As Integer)
    If value < 1 Then
      mScrollSpeed = 1
    ElseIf value > 10 Then
      mScrollSpeed = 10
    Else
      mScrollSpeed = value
    End If
    Timer1.Interval = mScrollSpeed * 10
  End Set
End Property

These should be pretty self explanatory. Now the code for the Timer Tick event and Paint event:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  If mStartPos >= CStr(mText(mTextNum)).Length Then
    'Change to the next text
    If mTextNum = mText.Count Then
      mTextNum = 1
    Else
      mTextNum += 1
    End If
    mStartPos = 1
  Else
    mStartPos += 1
  End If
  Invalidate()
End Sub

Private Sub ScrollingTextBox_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
  Dim str As String = CStr(mText.Item(mTextNum))
  Dim g As Graphics = e.Graphics
  Dim tmpStr As String = str.Substring(mStartPos)
  g.DrawString(tmpStr, Me.Font, New SolidBrush(Me.ForeColor), 0, 0)
End Sub

And there you have it. A simple CompactFramework UserControl that holds a collection of strings, scrolls the text as needed, and changes the text that it is displaying.  Right now I am using VS2008 and v3.5 of the CF.Net, but I don’t think there is anything in here that is version specific.


Hair pulling

October 30, 2007

I finally just figured out why my database wasn’t updating.  Such a simple matter really, but it wasn’t easy to find through Google so I am posting here, mainly as a future reminder.

I am writing a small app to use as a podcast listener.  Since I don’t own an iPod, I listen to podcasts throughout the day.  Well I was at the point that I wanted to start adding data to the database.  But no matter what I tried, the data wasn’t updated.  It was getting very frustrating.  What I finally figured out was VB was copying the database to the debug directory each time.  A simple setting on the SQL Server Express properties, changing the Copy to output from Always to Copy if newer fixed it.

Hopefully this will save you some time in the future.


Vista Sidebar Gadget Updated

July 9, 2007

I just finished posting the v1.1 of my IP Status gadget.  But you can’t get it yet.  Why?  Because it is “Pending approval.”  When it gets approved, you will notice a couple differences.  One, it now has a shiny blue background.  Two, it no longer requires you to load an asp page on a public website in order to get your public ip address.  It uses a web service from whatismyip.com.  Three, there is no longer a settings page, as it didn’t make sense to have one.  The only thing that I could put into a settings page is maybe the refresh interval, but I am not worried about that at this time.

As soon as it gets approved, I will post the link here.  Maybe now it will get more than 2 stars :)

Here is a picture of it:
thumbnail.jpg

EDIT: It just got approved.  Here is the link: http://gallery.live.com/LiveItemDetail.aspx?li=44a5ddd7-daa1-46cc-a9fa-7204b734f074


An example of poor customer service

July 3, 2007

My wife has a doctor’s appointment today.  About 2 weeks ago, she received a letter in the mail from the doctor’s office asking her to fill out a web form with information.  It seems that the doctor’s office has jumped on the web bandwagon and are having all of their patients create a digital web-based chart.  So what’s the problem with this?

The web form was multiple pages (upwards of 50) and took at least 45 mins to complete.  The questions asked were of her entire health history, not just what has happened since her last appointment.  My wife said over and over how they already had all this information in her (paper) chart at the office.  Since she used to work in that office, she knows exactly what is contained in her chart.  The endless duplication grated on her endlessly.  And my wife does not get upset very easily.  The worst part is that even after she completed this monstrosity, she still got a phone call from the office asking her to please complete the process before her appointment.

I don’t have a problem with the doctor’s office going digital.  But they went about it the wrong way.  So what is the right way?

Her appointment was made months ago.  When her appointment was made, the office should have had someone upload all the information from her paper chart to the digital storage.  Then, she should have gotten a letter that asked her to answer the questions based on health changes from her last appointment.  What took 45mins as it is would have only taken about 10 mins.

Sure, this would have cost the doctor’s office $ for labor.  Maybe they would have had to hire a couple medical transcriptionists to do the work.  But since it was a decision of the practice it digitize their charts, they should eat the cost of this, rather than pushing the pain onto their patients.


Use Cases

May 31, 2007

I forgot to post this in my last post, so why not another one?

I put together 3 use cases for my web application.  What are use cases?  They are short paragraphs listing your typical users and how they will use the app.  My use cases are for the three primary types of users that I envision.  As I get deeper, I will probably add more cases, but will not be removing any.

What are use cases good for?  They mainly serve to remind me that I have to put the app together in a way that is intuitive for the different types of users.  They may be good at computers, or they may just be the email/surfing type.  So every decision that I make in regards to design and usability have to work for these users.  They are also part of the spec for the app, as the use cases flesh out the different things that the app has to do.


Sample ASP script for getting your public IP address

May 21, 2007

Wrap this in HTML, BODY and % tags

Dim UserIPAddress
UserIPAddress = Request.ServerVariables(”HTTP_X_FORWARDED_FOR”)
If UserIPAddress = “” Then
UserIPAddress = Request.ServerVariables(”REMOTE_ADDR”)
End If
response.write(UserIPAddress)

Post this on a webserver that you have access to as something.asp, and use that address in the gadget.


Free program for using WMI

March 27, 2007

Microsoft has a free download called WMI Creator that gives you code in C#, VB, vbscript and javascript for any WMI call you can think of. Click here for WMI Creator.  Hopefully this will help everyone that wants to expand on the available Vista sidebar gadgets.


More product ideas

March 27, 2007

It seems like I am at the same point, no matter what time it is.  I have some great ideas.  Some of them would be great products, some of them are too fuzzy to begin research on, and some of them are not-so-great ideas.  I think that I just need to talk to some people that are not power-users or programmers to see if there would be any interest.

Right now, I have been thinking of two completely different ideas.  Both of them I have some experience with.  The first idea is to write a canasta card game.  Strictly windows only, maybe multiplayer over the internet, maybe just single player.  It would be different than any other canasta program as my family plays canasta differently than you will find in any rule book.  We call it Hollywood Canasta, but the Hollywood portion probably just comes from a version of 500 Rummy that we call Hollywood Rummy.  The rules of Hollywood Canasta are not that much different from American (or Modern) Canasta that they would be difficult for someone already familiar with canasta to learn them.  The playing strategy is different though.  What I would envision doing is release Hollywood Canasta (probably named Windows Canasta or WinCanasta rather than Hollywood Canasta) first, then maybe Hollywood Rum next.  To me, these games are a lot more fun than the original versions.  For Hollywood Rum, my aunt and cousin decided the set hands were too easy, so they added two additional hands that are quite difficult!  But that is part of the fun!

The second idea is for an inventory management app for plumbing companies.  I would probably start out targetting companies doing repair work first, then expand to target companies doing new construction.  This is in reverse to what I first thought of doing, but when I thought about it some more, repair companies have a bit larger profit margin than new construction companies do.  I definitely have the background for this app, as I was a licensed plumber for a few years, working for both types of companies.  From being in the business, I know the similarities and differences between the two types of plumbing companies.  Repair companies have to stock their vehicles with a lot of small parts (or eat the time where their tech has to get parts at the supply house) and keep some inventory in the warehouse.  Since they bill by the hour, they don’t tend to keep a lot of inventory (because the inventory sitting on the shelves eats into their profit margin).  Some of the small 1 or 2 man companies don’t even have warehouses/offices and just have their trucks.  The new construction companies tend to have larger warehouses, because they tend to make their $ on the margins.  For example, I can buy one tee for $4.00 (not real prices).  If I need 6 tees for a house, that is $24.00.  But if I know that I am doing 5 houses this month, I can buy 30 @ $3.25/ea. for a total of $97.50.  If I bought 30 at the local supply house, it would cost $120.00.  So for this one part (with not real prices), I have potentially saved $22.50.  Now if I had the necessary cost supply, and could forecast how many houses I would be doing this year, I could purchase a years worth of supplies and have them on-hand.  Or maybe my supplier will only give me the special discount price for 50 tees.  How long would they sit on my shelf before I could use them all up.  How much lead time would I need to re-order?

I have worked for some companies that would have a year’s worth on hand at all times.  So if their cashflow started to suffer, they could work off of their stock until things improved.  When your profit per house is low (and generally speaking, it is lower than the per hour the repair plumber gets), you need to squeeze all the profit out that you can.

So now I just need to decide which one I want to work on.  I have had one person tell me they would want the canasta game (my mom).  I do not know what kind of market there is for the plumbing app.  So I think that I will need to do some research on that.  I keep going back and forth on which one to do.  Both of them would probably be windows apps, not web apps.  One would be B2C, probably at $25 or $30 price.  The other would be B2B, and I would have to do the research even to come up with a price point.  Well, I guess since I have a friend that owns a plumbing supply house, I will probably be talking to him soon.