Community discussion forum

Need help on Visual Basic assignement

  • 30 days ago

    Hey I am trying to use arrays, form load event, sub procedures, and for next loops for this coding. Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Agegroup1, agegroup2, agegroup3 As String
        Dim male1, male2, male3, female1, female2, female3, total1, total2, total3, total4 As Double
        Dim fmtstr As String = "{0,-14}{1,10}{2,12}{3,14:P2}{4,12:P2}{5,13:P2}"
        Dim sr As IO.StreamReader = IO.File.OpenText("Pop.txt")
    
        lslbox.Items.Clear()
        lslbox.Items.Add(String.Format(fmtstr, "Agegroup", "Males", "Females", _
                                       "%Males", "%Females", "%Total"))
    
        agegroup1 = sr.ReadLine
        male1 = CDbl(sr.ReadLine)
        female1 = CDbl(sr.ReadLine)
        agegroup2 = sr.ReadLine
        male2 = CDbl(sr.ReadLine)
        female2 = CDbl(sr.ReadLine)
        agegroup3 = sr.ReadLine
        male3 = CDbl(sr.ReadLine)
        female3 = CDbl(sr.ReadLine)
    
        total1 = male1 + female1
        total2 = male2 + female2
        total3 = male3 + female3
        total4 = male1 + male2 + male3 + female1 + female2 + female3
    
        lslbox.Items.Add(String.Format(fmtstr, Agegroup1, male1, female1, _
                         male1 / total1, female1 / total1, total1 / total4))
    
        lslbox.Items.Add(String.Format(fmtstr, agegroup2, male2, female2, _
                         male2 / total2, female2 / total2, total2 / total4))
    
        lslbox.Items.Add(String.Format(fmtstr, agegroup3, male3, female3, _
                         male3 / total3, female3 / total3, total3 / total4))
    
    End Sub
    

    End Class

    This is what I have now and I need help. Any suggestions?

    Public Class Form1 Dim agegroup(3) As String Dim male(3) As Double Dim female(3) As Double Dim total(4) As Double

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sr As IO.StreamReader = IO.File.OpenText("Pop.txt")
        Do While sr.ReadLine <> System.DBNull
            agegroup(3) = sr.ReadLine
            male(3) = CDbl(sr.ReadLine)
            female(3) = CDbl(sr.ReadLine)
        Loop
        'For i As Double = 1 To 9
        'agegroup.GetUpperBound(0)
        'male.GetUpperBound(0)
        'female.GetUpperBound(0)
        'Next
    End Sub
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim male, female As Double
    
        DoComputations(male, female)
        DisplayResults(male, female)
    
    End Sub
    
    Sub DoComputations(ByVal men As Double, ByVal women As Double)
    
    End Sub
    Sub DisplayResults(ByVal men As Double, ByVal women As Double)
        ListBox1.Items.Clear()
        Dim fmtstr As String = "{0,-14}{1,10}{2,12}{3,14:P2}{4,12:P2}{5,13:P2}"
        ListBox1.Items.Add(String.Format(fmtstr, "Agegroup", "Males", "Females", _
                                               "%Males", "%Females", "%Total"))
    
    End Sub
    

    End Class

    Post was edited on 25/10/2009 00:50:32 Report abuse

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!