Sunday, April 22, 2012

Measuring the length of each line of a string

I needed to have the ability to measure the length of each line of a string that would be displayed in a text box using vb.net.

This is what it does: You tell it the string that you want to use, the text control that it is going to use and the number of rows you want to display. The function builds line-by-line the string until no more will fit and returns the new string that will fit within that control.


    Private Function fitTextToLength(stringToFit As String, textfield As Object, rows As Short)
        ' This function is very important for displaying text in the alerts properly.
        ' stringToFit is the string that is going to be used to populate the control
        ' textField is the object where teh text will be placed. We will have to consider the size
        '           of the field for this function.
        ' rows indicated how many rows is wanted for the field. Multiline fields would be more then 1
        '           depending on useage requirements
        ' Split the words
        Dim words() As String = stringToFit.Split(" ")
        Dim complete As Boolean = False
        Dim counter As Short = 0
        Dim row As Short = 0
        Dim stringLine As String = String.Empty
        Dim finalText As String = String.Empty
        ' Loop until we find a complete string
        While Not (complete)
            ' Build a string to mesaure
            ' This is built word-by-word until the string is too long for the objects width
            ' Each word is not added to the string until it is known that it will fit.
            Dim myString As String = stringLine & words(counter) & " "
            ' Measure the string length for comparision
            Dim g As Graphics = Graphics.FromHwnd(textfield.Handle)
            Dim f As SizeF = g.MeasureString(myString & "...", textfield.Font)
            ' Determine if the built string fits the width of the object
            If f.Width <= textfield.width Then
                ' Concatenate the string to the main string
                stringLine = myString
                counter += 1
            Else
                ' Check to see if we have reach the max row
                If row = rows Then
                    ' Show that there is more text using "..."
                    finalText += "..."
                    ' Complete the loop
                    complete = True
                Else
                    ' Increase the row 
                    row += 1
                    ' Concat the final text
                    finalText += stringLine
                    ' Clear the stringLine for the next line to build
                    stringLine = String.Empty
                End If
            End If
            ' Make sure that we don't go beyond the array
            If counter >= words.Length Then
                ' Concat the build string to the main string
                finalText += myString
                ' Exit the loop
                complete = True
            End If
        End While
        ' Return the result.
        Return finalText
    End Function

Friday, March 16, 2012

Progress


It might seem like I have lost interest in this project, but I haven’t! I am not rushing it. I have written three different versions so far – the first two I was not happy with – yet I borrowed several things from each version to make the third version. I am really quite happy with what I have going on right now. It fixes so many problems that SGA had.

With classes, work, and my son’s surgery, I really have not had that much time to work on Raven. Like I said above, I am taking it slow. I am trying to make sure it is designed well. I am avoiding shortcuts that just make the program work and trying to be as organized as possible. I have been using some new techniques that I have picked up from various sources.

I will have a lot of time next week to do some work on Raven, so hopefully it is productive. A few of the major parts still need to be written, like the code to save data files. I also have to make it possible to load SGA save files for compatibility. The alerts need more work too, but the basic foundation is definitely there for them.

Thursday, February 2, 2012

Lack of drive

Some times I can write code non-stop and get projects done really quickly. Right now I have very little drive to  work on anything. I have been slowly doing some design work on the user interface; a few designs I really like, while others are not so great. The program can retrieve email, but it is not at all refined.
SGA is having calendar issues and I just don't have the energy to fix it. I feel like I have writers block. I am trying to do other things to get motivated, but honestly I'd rather just sleep all day.

Saturday, January 14, 2012

Starting a project

My wife asked me how I start my programming projects. I explained it is a lot like having to write a paper for a class and is often times the hardest part of the project. Small projects start easily and are finished quickly since they have a goal in mind and relatively little to code. Big projects like Raven take a lot more time.

To start I researched some of the things that I would need in-order to accomplish what I wanted to do. Things like IMAP support and the new features of Windows.

I drew up plans for what the program would do, and the basic outline for the modules. I also planned out an rough guess of what the forms would look like. I spend quite a bit of research trying to find out what interfaces work best for the program I am making so that users will be able to easily use the program.

Something that may seem unrelated is my website, yet it is not. A strong web presence is important since I don't sell my software in stores or anything. Another step in starting my project involved redoing my site and adding a section for Raven. I have decided to do a few things differently then I did with SGA in terms of the website. SGA updates through the update form and can automatically down the files needed on the click of a button. Raven will alert a user to an update and link to the website where the update can be found. This will make the website more of a source for users and will make it possible for me to only maintain one setup version. Each update will have a dedicated page that will have useful information for users so that they can download files easily.

With having the update section of the website started, I was able to begin the Raven project with the updating part of my code. It made sense to add that first because with a project that is underdevelopment, having a way to update to new versions will be important for testing. Rather than using the text file that SGA uses, Raven is using the more robust XML file:

        ' Load data into variable
        Dim update As updateInformation
        With update
            .major = CShort(document...<version>...<major>.Value)
            .minor = CShort(document...<version>...<minor>.Value)
            .month = CShort(document...<version>...<month>.Value)
            .day = CShort(document...<version>...<day>.Value)
            .text = document...<text>.Value
            .URL = document...<URL>.Value
            .requiredUpdate = CBool(document...<required>.Value)
        End With


From there I started designing my forms. It is important to me that all the forms have a uniform look. Coming up with a nice design from the beginning is important so that I don't have to redo all the forms later in development. SGA went through many different versions because the UI was always being improved and the underlying code was always being rewritten for efficiency. I am trying to make Raven better from the start.

So since I stated the actual coding, I figured it would be best to make a documentation file of all the things that I actually finished for my own record. It helps to know what you worked on and what your ideas were, my memory is not good enough where I can just remember everything.


     NOTES


     Things to do:
     Add application variables to remember system settings.
     Implement detection for the computer going idle so that alerts show once 

       user returns.
     Start alert windows, and client GUI.
     ------------------------------------------------------------------------
     January 8, 2012
     Cleaned up code and removed additional form that was the startup form.
     Moved account code to the same file into a new module.
     Started making send email window.
     Some performance enhances.
     More testing of present functions.
     Added IMAP stop function
     Added power mode handler
     Added windows shutdown handler
     Added display changes handler
     ------------------------------------------------------------------------
     January 7, 2012
     Experimented with IMAP IDLE (push) support
     Worked on client UI and added meesages to display
     ------------------------------------------------------------------------
     January 5, 2012
     Created a account management window UI
     ------------------------------------------------------------------------
     January 4, 2012
     Designed message checking system that loads new messages in to each accounts       

       queue and to a new message queue.
     Using events to alert the program to completed message checking, messages 

       are passed to the function to initiate alerts and update the ui
     various supporting functions were added.
     A toolstrip along the bottom showing the progress of message checking and 

       program status added.
     Did some testing to get emails to see if program would run correctly.
     ------------------------------------------------------------------------
     January 3, 2012
     Updates:
     Started working on the startup commands. Switch -exit shutdown the program.
     Added some IMAP support
     Added classes to cover accounts and messages
     Added the start of an alert messaging system
     Did research on how IMAP works.
     ------------------------------------------------------------------------
     January 2, 2012
     Icons:
     http://www.webiconset.com/category/free-icons/
     http://mediadesign.deviantart.com/art/HP-Dock-Icon-Set-71481581
     http://www.freeiconsweb.com/Free-Downloads.asp?id=1700
     Updates:
     Fixed debug error that was prevening me from using breakpoints
     Added update function the the application startup as a seperate function 

       that can be easily called from anywhere.
     Included forced update for alpha and beta versions
     created sample xml file on server for updates
     Designed update window interface
     Added taskbar icon that looks like an envelope
     Started settings window design
     Made post on dream in code for UI designs on settings.
     Added tabless tabs to the settings page to ease design process and make 

       things more efficient.
     Add my name and a link to my website.
     setup general, display, connection, sounds, technical, security, contacts, 

       and credits tabs.
     Started design on a comments window to allow users to easily contact me.


I am working slowly on Raven to make it better. My college classes have resumed and I am back to work after having a holiday break, so development will probably be even slower now. Yet so far, Raven is interfacing with IMAP and able to display messages. It is far from finished, but it is a start.

Monday, January 2, 2012

Progress


It has been bugging me lately because I haven’t gotten much complete with Raven. I have wanted to work on it, but haven’t had the energy. I sat down today with a blank project and just started designing what came to mind. I started with the update section of the program so that all future versions will be able to get instant updates about new versions. From there I continued with the design on other forms and did a little interface code. It looks like a basic shell for the program is coming out of the work I did today. It feels good to have something started, that is always the hardest part for me. Tomorrow I hope to get some of the core functions implemented.

Tuesday, December 13, 2011

Website


I am starting slow. I know that I need to have a good foundation in order to be able to have a stable product. I cannot rush this.  I have started by updating my website; this serves two purposes: firstly, I am taking an easy HTML class and needed to get reacquainted with it, and second, the website is the first thing people see before trying the product. My site was too simple and plain.

While it is still in progress, it is getting better. I have the basic layout designed, and now need to add content. What is present is enough to get you around, but it is lacking. Everything will be uniform, even the update pages.

I have decided that updates will be different in Raven, rather than being downloaded from the program, updates will by only available for the web page. Raven will tell you there is an update and take you to the webpage. Each update will have its own page with information dedicated to that update; this should help when there are major changes through the development.

Lastly, getting some creativity from making the website better will help the rusty cogs in my mind to start turning fast enough for me to get some code into the IDE. I am trying to get myself into the programming state where I can write good code very quickly. I aam getting close to that point.

Sunday, December 11, 2011

Raven design


I am doing Raven differently. I started with paper drawing and designs of what it could be like. I wrote out all the things that it could do and determined the things that it will need to have. This is much in contrast to how I did things with Scott’s Gmail Alert.

Scott’s Gmail Alert was designed around the alerts. Once the alerts were made, I added more options until it continued to grow. Where in the problem lies, this ended up making it so that parts had to be rewritten since they were not compatible with the new code, or duplicate code with very minor differences had to be added. That is not very efficient. Also, SGA relied on the computer’s memory too much.

Raven is going to combine the strengths of SGA, Terrie’s Recipe Manager, my group project for Advanced Visual Basic class and Smart Thinking. SGA was great for its alert management and large number of options. Terrie’ Recipe Manager has a very useful interface. Smart Thinking made good use of modular code that was independent. My group project was able to maintain data using databases.

Raven needs all of these things to be successful. Memory management, being lightweight and able to silently run in the task bar are going to be the main attributes that will allow Raven to be a great email alerting client.

While I have not written any code yet, it will start soon. I am trying to get over being sick at the moment, so that I will have a clear mind when I start. I am going to begin with setting up a special directory and try to start organized – so that I finish organized.