Need help on Visual Basic assignement

random , visual basic , programming Irvine, United States
  • 11 years 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

  • 11 years ago

    Think will try out and will let you know. Link Text

Post a reply

Enter your message below

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

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“To iterate is human, to recurse divine” - L. Peter Deutsch