Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   Array (http://www.programmingforums.org/showthread.php?t=15687)

A.K.Al Shamsi Apr 23rd, 2008 11:36 AM

Array
 
hi there.... how are you guys??

could somebody help to correct my code??? i have a problem for displaying arrays in the list box


here is the code


:

Public Class Form1

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        ErrorProvider1.Clear()

        Dim total As Decimal
        Dim sales As Decimal
        Dim flag As Boolean

        flag = False

        sales = Val(txtSales.Text)
        total = 200 + (0.09 * sales)
        txtSalary.Text = total.ToString

        If (txtSales.Text = "") Then
            ErrorProvider1.SetError(txtSales, "You shoulde enter the sales")
            flag = True
            txtSalary.Text = ""
        End If
    End Sub

    Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTotal.Click
        Dim salary As Integer
        Dim survey(0 To 8) As Integer

        ListBox1.Items.Add("Salary Range:" + "        " + "Total:")
        ListBox1.Items.Add(salary.ToString)


        Select Case salary
            Case 200 To 299
                survey(0) += 1
            Case 300 To 399
                survey(1) += 1
            Case 400 To 499
                survey(2) += 1
            Case 500 To 599
                survey(3) += 1
            Case 600 To 699
                survey(4) += 1
            Case 700 To 799
                survey(5) += 1
            Case 800 To 899
                survey(6) += 1
            Case 900 To 999
                survey(7) += 1
            Case Is > 100
                survey(8) += 1
        End Select


    End Sub
End Class



and this is what it shows

http://www7.0zz0.com/2008/04/23/16/147803266.jpg


how can i display all of them??:icon_cheesygrin:

Freaky Chris Apr 23rd, 2008 1:15 PM

Re: Array
 
Show all of what, currently you are displaying salery which has only been declared not even had a value assigned to it. Maybe i missed what you are asking.

Chris

A.K.Al Shamsi Apr 23rd, 2008 9:30 PM

Re: Array
 
i want to display
:

        Select Case salary
            Case 200 To 299
                survey(0) += 1
            Case 300 To 399
                survey(1) += 1
            Case 400 To 499
                survey(2) += 1
            Case 500 To 599
                survey(3) += 1
            Case 600 To 699
                survey(4) += 1
            Case 700 To 799
                survey(5) += 1
            Case 800 To 899
                survey(6) += 1
            Case 900 To 999
                survey(7) += 1
            Case Is > 100
                survey(8) += 1
        End Select

all these in listbox i got 0 which is not waht i want

Freaky Chris Apr 24th, 2008 1:40 AM

Re: Array
 
The reason why you are getting a 0 and that is it, is because the only item you are adding to ur list box after the first line is the value of salary.

:

  1. ListBox1.Items.Add(salary.ToString)


if you are looking to print out the value in wach of the survey items from 0-8 then you would need to do something like this, after you case statement. All the case statement is doing is checking the value of salary and then increment the correct item with the array survey. Not adding them to the list box.

Something like this would add all of the items from survey into the listbox.

:

  1. For i = 0 To 8
  2.     ListBox1.Items.Add(survey(i).ToString)
  3. Next i



Cheers,
Chris

A.K.Al Shamsi Apr 24th, 2008 4:11 AM

Re: Array
 
i will try it


All times are GMT -5. The time now is 4:53 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC