-
January 24th, 2015, 07:58 AM
#1
New to Programming - need help understanding code.
Hi all, sort of new to the programming scene and I was initially going to go in the deep end and try and learn java, but then I was recommended to start off with an easier language like Visual Basic, so here I am taking that advice.
I bought a book called Visual Basics in easy steps, the book was initially easy to follow, howeve I have now come across a few things that have not been explained properly in this book.
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Sales() As Double = {5601, 8502, 6703, 4204, 7065, 8206, 9107, 6508, 7209, 5010, 8011, 7012}
Dim sum As String
Dim counter As Integer
Do Until counter = Sales.length
sum = FormatCurrency(Sales(counter)) //this is what I don't understand, what does this part of the code mean?
counter = counter + 1
sum = sum & vbTab & MonthName(counter) // also this one
ListBox1.Items.Add(sum)
Loop
End Sub
Please look within this code and see where I'm confused.
Thanks.
-
January 25th, 2015, 06:29 PM
#2
Re: New to Programming - need help understanding code.
You are dealing with an array of numbers.
Sales(0) would be 5601 Sales(1) would be 8502 and so on for each number in the array
The code is simply looping through the array, formatting the numbers into currency format and adding them to a listbox along with a month name which is also an array but apparently defined somewhere else.
Always use [code][/code] tags when posting code.
-
February 6th, 2015, 06:40 AM
#3
Re: New to Programming - need help understanding code.
OK, let us have a look - just to add onto what DM has said.. :
Code:
Do Until counter = Sales.length
sum = FormatCurrency(Sales(counter)) //this is what I don't understand, what does this part of the code mean?
counter = counter + 1
sum = sum & vbTab & MonthName(counter) // also this one
ListBox1.Items.Add(sum)
Loop
The do Until loop will loop until a certain condition is met; in this case when counter becomes the same value as the length of the Sales array.
For every loop iteration it will add a currency symbol to the current item in the array ( so let's use the first one ) - it will produce this :
$ 5601
Then, it will increment the loop counter
Then it adds a Tab and the Current Monthname to the existing string - this is known as concatenation, read up on it here and read up on the VB MonthName function here
Lastly, it adds the resulting string to the listbox. The resulting string ( assuming of course we are still dealing with the first item here ) would now look like :
I hope it helps..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|