Wednesday, August 4, 2010

Wednesday, August 4th 2010

Hi! Today I am going to begin by looking back at looping - going off of a tutorial written by Anne Boehm.



Dim sum As Integer
Dim i as Integer
For i = 0 to 10
sum += i
Next


This loop will add the numbers 0-10, which is extremely important as we are all forgetting how to count.

It's important to note that on the Next clause above I did not add the counter i. It is not necessary to add the counter name, although it helps to add the counter name as it adds clarity, especially when you are nesting loops

Anne Boehm also directs our attention to Do loops, which, since they seem to do the same thing as For loops I want to skip over. Do loops have one thing that is really worth mentioning here, which is that the condition can be tested either before or after the series of statements is executed. As I understand it, For loops always tests the condition before the series of statements is executed (again, as I understand it).

Generally speaking, a For loop is a count-controlled loop and a Do loop is a condition-controlled loop...

As part of an expansion of the Invoice Total application I wrote the following code:


ElseIf txtCustomerType.Text = "T" Then
If subtotal < discountpercent =" 0.4" discountpercent =" 0.5"


I also changed the text entry box for selecting the customer type to a combo type (doesn't this make more sense?) If the customer type selected is "other" or if nothing is selected than the program uses the default discount amount.

I decided to expand the Invoice Total tutorial with code from a previous tutorial.

I added the following variable definitions to the load form event (where else was I supposed to put them?) This didn't work, by the way, I had to move this code to above the click event for the "Calculate" button


Dim numberOfInvoices As Integer
Dim totalOfInvoices As Decimal
Dim invoiceAverage As Decimal


There are now two subtotal text boxes - txtSubtotal.text and txtEnterSubtotal.text. txtSubtotal.text is set to read only, and txtEnterSubtotal.text is of course where you actually enter the amount.

There is also a counter to count how many of each kind of invoice is issued - C type, T type, etc.
I wrote the following If statement


If cmbCustomerType.Text = "R" Then
RInvoices += 1
ElseIf cmbCustomerType.Text = "C" Then
CInvoices += 1
ElseIf cmbCustomerType.Text = "T" Then
TInvoices += 1
Else : OtherInvoices += 1
End If


For actually producing the information on screen, I wrote:


txtCinvoicesTotal.Text = CInvoices
txtRinvoicesTotal.Text = RInvoices
txtTinvoicesTotal.Text = TInvoices
txtOtherInvoicesTotal.Text = OtherInvoices



Is it not necessary to add ToString the end of the variables? In one of the tutorials Anne Boehm writes:


txtNumberOfInvoices.Text = numberOfInvoices.ToString


Next I am going to look and coding procedures and event handlers. I have already coded some sub procedures for Jesse Liberty tutorial, which I hope to be getting back to soon.

When writing a Sub procedure you can declare the the parameters that are required by the procedure in the parameter list that follows in parenthesis the parameter name.


ByRef allows you to change the value of the variable itself, whereas ByVal does not.

No comments: