Wrox Programmer Forums
|
BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6
This is the forum to discuss the Wrox book Beginning Visual Basic 2005 by Thearon Willis, Bryan Newsome; ISBN: 9780764574016
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2007, 11:08 AM
Registered User
 
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Optional Reversing An Array (pgs. 133 to 134)

I tried the optional way of reversing an array given on pgs. 133 - 134 and it gives me the same array "(0)" four times.

Here is the code for the button:

Code:
    Private Sub btnReverseMethod1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReverseMethod1.Click
        For intIndex As Integer = strSkills.GetUpperBound(0) To 0 Step -1
            'Add the array item(s) to the list
            lstSkills.Items.Add(strSkills(0))
        Next
    End Sub


Here is the code for the Array at the form level:
Code:
Public Class Form1

    'Declare form level array
    Private strSkills(3) As String
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Polulate the Skills Array
        strSkills(0) = "Listen"
        strSkills(1) = "Talk"
        strSkills(2) = "Type"
        strSkills(3) = "E-mail"
    End Sub


When I run the project and click on the button I get "Listen" on the list four times (My wife would probably say it's trying to tell me something).


Thanks,
Tek

edited to have code stand out
 
Old February 24th, 2007, 02:57 PM
Wrox Author
 
Join Date: Mar 2006
Posts: 91
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I did not try this code, but it looks like the issue is on this line in red

For intIndex As Integer = strSkills.GetUpperBound(0) To 0 Step -1
   'Add the array item(s) to the list
   lstSkills.Items.Add(strSkills(0))
Next

Try changing the strSkills(0) which is adding the 0 item each time to strSkills(intIndex ). intIndex should be the variable that contains 4 then 3 then 2 then 1 then 0 which will reverse the array. The new code would look like this.

For intIndex As Integer = strSkills.GetUpperBound(0) To 0 Step -1
   'Add the array item(s) to the list
   lstSkills.Items.Add(strSkills(intIndex))
Next


Bryan





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reversing nodeset sudhish.sikhamani XSLT 3 June 19th, 2008 11:43 AM
Certification in Sharpoint Exam 74-133 Mujeeb Mehdi SharePoint Development 0 September 30th, 2007 10:51 PM
Chapter 4 p. 134 exercise 1 luciano991 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 August 16th, 2006 07:22 AM
Ch 5 Arrays Pg 134 Sadlowski BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 2 February 23rd, 2006 01:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.