VB.Net CF Scrolling textbox

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

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

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

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

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

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.

More product ideas

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.

Vista/IE7/FCKeditor problems

I have been working on the expanded Club Starter Kit from Codeplex and ran into problems on every page that had a FCKeditor window.  When running the site from VS.Net 2005, I would get a wierd error message.

fckeditor-error.png

I was pulling my hair out.  Googling for IE7 FCKeditor didn’t help.  I wasn’t having that problem with FF2. 

Well, as it turns out, it was a setting in Windows Live OneCare.  After unchecking the box that is circled, the editor came up fine on a test page.

 onecare.png

So here is one solution that may work for you.  Now why didn’t OneCare block the same thing from FF???

First feature request

My IP Status Gadget finally got a review (after being up 3 days).  It wasn’t a review, more of a feature request.  The reviewer requested two things:

  1. User settable background
  2. Smaller size when public IP address isn’t needed.

So now I can improve it and release version 1.1.  I am really liking the idea of the sidebar gadgets.  For me they are a great opportunity to begin development and releasing software without any repurcussions.  The only downsides are they are free and the code can be changed by someone else and re-released.  But since they only took a few hours, I don’t mind giving it away.  I was just impressed to see the number of downloads steadily increasing. 

I have also thought of a way of monetizing it.  Right now, it will not give you your public IP address (if you are behind a router) without hitting a ASP page.  I wrote a simple ASP page on my website that just does a response.write of the IP address.  I am not giving out the URL, because I don’t want my host to get hit with a bunch of requests.  But if I made a site that you have to subscribe to (maybe $15/year or something like that), then I could add that to the settings page and make some money off the gadget.  I don’t know if I will go through with that or not.

Oh, and my Vista Sidebar post is the 23rd result on Google when searching for “gadget vbscript”.  So at least I know Google is checking my blog!

I guess it is time to start doing more posts on developing gadgets with vbscript, since most of the samples you can find are written in javascript.  I don’t have anything against javascript, but seeing how hard debugging gadgets can be, I don’t want to have to debug missing ;s.  And since most of my software development is in VB.Net, vbscript is just a little easier for me to write.