Posts Tagged ‘Visual Basic’

How I Created my own Twitter App with Visual Basic

Over the past few weeks, I have spent countless hours programming (and testing and reprogramming and testing and reprogramming, etc.) a Twitter app I created in Visual Basic.  It was the most fun project I could think of for a Visual Basic class I’m taking at UNLV.  In the end, the programming wasn’t so difficult.  It just took me a long time to find something that worked.  After many Google searches, I couldn’t find a straight-forward walkthrough, so hopefully this blog post will be helpful to some lost soul out there (maybe for another school project).  Below is a screen shot of my app.

Twitter App Created with Visual Basic

The only action my form does with Twitter is post an update when the “to Twitter” checkbox is checked.  The other buttons read, write, edit and delete tweets in a Microsoft Access database. First, I created the form above, including the labels, text boxes, and buttons.  I won’t go into the code behind each one of them, but the code for the label with the number of characters remaining was particularly fun to write.  I made its actions similar to what is on Twitter’s webpage.  When the number of characters in the status text box (rtbStatus) goes over 140, the text turns red and the “tweet” button is disabled.  The code is:

Private Sub rtbStatus_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtbStatus.TextChanged lblTweetLength.Text = 140 – rtbStatus.TextLength If lblTweetLength.Text < 0 Then lblTweetLength.ForeColor = Color.Red End If If rtbStatus.TextLength = 0 Or rtbStatus.TextLength > 140 Then btnTweetToDatabase.Enabled = False Else btnTweetToDatabase.Enabled = True End If End Sub

Next, I went to the Twitter Developers webpage and registered my application (funny, I never thought I’d be a Twitter developer).  After filling out a form describing my app, I received a consumer key, consumer secret, access token, and access token secret.  These are needed to authorize your application to access your Twitter account. Then, I went to the TwitterVB webpage, which is an open source project with a .NET library that allows desktop and web applications to communicate with Twitter.  I downloaded the TwitterVB zip file.  The zip file contains many different files, but the only one I used was TwitterVB.dll.  In Visual Basic, I added the dll file as a reference. I included the namespace in my code file with the following:

Imports TwitterVB2

I then added the following code that I found from the TwitterVB webpage to the code that executes when the “tweet” button is clicked and the “to Twitter” checkbox is checked.  I replaced the consumer key, consumer secret, access token, and access token secret in the code with what I had received from the Twitter Developers webpage when I registered my application.

Dim TextToTweet As String TextToTweet=rtbStatus.Text Dim tw As New TwitterVB2.TwitterAPI tw.AuthenticateWith(“consumerkey”,“consumersecret”,“oauthtoken”,“tokensecret”) tw.Update(TextToTweet)

Then, I tested my app.

Testing my Twitter App

After I clicked the “tweet” button, I opened my Twitter timeline in my web browser and saw that my tweet successfully posted to Twitter!  It even shows that it posted via DustinVB, which is what I named my app when I registered it with Twitter.

My Test Tweet in a Web Browser

After I turn this project in to be graded, it will collect dust in my virtual bookshelf.  I don’t plan to use it again.  There are so many good Twitter programs out there that can do so much more than mine can. Still, I feel happy that I figured it out and can now call myself a Twitter developer (even though I’m a novice, at best).

Cash Counting Program I Created with Visual Basic

Twenty, forty, sixty, eighty, one hundred, twenty, forty, sixty, eighty, two hundred, twenty, forty, sixty, eighty … aarrgh!  Where was I? In my previous post, I blogged about all the fun I am having in a Visual Basic class that I am taking at UNLV.  My most recent project is a simple cash and coin counting program.  I will use it for a position I hold in an organization in which I help count cash.  Hopefully, this program will ease the occasional pain and frustration I feel when counting stacks of twenty dollar bills. The user enters the amount of each type of coin and currency.  The program performs the calculations for each type and returns the total amount of coin and currency as seen in the screen shot below. Cash Counting Program
Enhanced by Zemanta

Tax Estimate Calculator Created with Visual Basic – Just for Fun

This fall, I am taking a Visual Basic class at UNLV as one of the electives for my Masters Degree in Accounting.  Projects for the class require application of the concepts learned, but allow for creativity because each student can create whatever design or function for the program he or she desires. My latest project in this class is a form that estimates an amount of tax based on income, itemized deductions and dependents.  It then returns a message to the user in a text box explaining how much tax, if any, is owed.  I know the tax code is much more complicated, but for this project, I used a flat 35% tax rate and $3,000 exemption per dependent.  The project required simple calculations, using IF statements, and returning a message to the user, so there was no need to go into unnecessary detail. The first step I took was to create the form, text boxes, and button to run the code.  I then wrote the code so that when the “estimate my tax” button is clicked, it calculates the tax, enters the amounts in the text boxes, and returns a message as shown below: The code to generate the generate the message in the text box is:
If Tax > 0 Then Message = Name & “, get out your checkbook.  You owe “ & Tax & “.  “ Else Message = Name & “, you don’t owe any tax.  “ End If
The project works, but it’s a little boring, isn’t it?  I decided to have a little bit of fun with the project by adding an additional IF statement:
If Income > 250000 Then Message = Message & “Wow!  You’re making more than $250,000.  You’d better hope Congress extends all of the Bush tax cuts!  “ End If
When the amount of income entered is greater than $250,000, the message becomes: I added another IF statement for the number of dependents:
If Dependents > 10 Then Message = Message & “By the way, you’re not counting your pets as dependents … are you?” End If
When the number of dependents is more than ten, the message becomes: This isn’t a useful program since the tax calculation is inaccurate, but I demonstrated the ability to use IF statements and gave my professor a few laughs while he was grading it (hopefully the laughs were worth a few points)!
Enhanced by Zemanta

Using Excel Macros to Manipulate QuickBooks Reports

Since I began working in accounting, I have observed some fellow accountants exporting data from accounting software programs to Excel and then performing repetitive tasks of reformatting the spreadsheet (moving data to other cells, entering calculated fields, changing fonts, resizing columns, etc).  This has provided me with the opportunity to use and share a valuable skill I learned in one of my classes in college so that these tasks can be completed automatically with the push of a button. One of the powerful features of Excel is Visual Basic for Applications (VBA), a programming language for creating macros.  A macro is a set of instructions for Excel to complete automatically that would otherwise be performed manually by a person. There are countless ways that you could use macros in Excel.  In fact, they can do about anything you would normally do except actually “think” for you.  Completing the tasks I described above of reformatting and manipulating data is just one simple example of what macros are capable of. The video below is a demonstration of a macro I wrote that I call “the trial balance formatter.”  It is designed to take an Excel export of a trial balance report from QuickBooks and automatically make the following changes:
  1. Combine the amounts from the debit and credit columns, show the amounts from the credit column as negative, and rename the resulting column “unadjusted.”
  2. Add four columns to the right of the unadjusted column for adjustments.  Columns C and E are for the amount of the adjustments and have a width of 12.  Columns D and F are for letters identifying the adjustments and have a width of 2.
  3. Add a column to the right of the adjustments titled “adjusted.”  Formulas adding the amounts in the unadjusted and adjustments columns are automatically entered into the cells in this column.
  4. Change the bolded account names and column headings to regular font.
Note: The data contained in this video is completely fictional.  You may want to make the video appear in full-screen mode to better read the text.  If you can’t see the video below, click here. Accountants: If you’re looking to add to your Excel skills, I recommend learning how to write macros.  I don’t write macros very often, but my coworkers and I use macros I’ve written every day. Clients/Potential Clients: If a macro could help you save time by automating a repetitive task in Excel, please let me know!