1 Replies - 489 Views - Last Post: 09 May 2013 - 06:46 AM Rate Topic: -----

#1 cscchee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-April 13

for next looping

Posted 09 May 2013 - 06:02 AM

Dim dview4 As DataRowView
        'Dim dview3 As DataRowView
        'Dim time_require As Integer

        Dim totalETR As Integer = 0
        Dim ETR_array(100) As Integer
        Dim TotalETR_div_ETR_array(100) As Integer
        'Dim ERTweight1 As Double
        'Dim ERTweight2 As Double

        'Dim total_ERTweight As Double
        Dim ERTweight2_array(100) As Double
        Dim Sum_weight1 As Double
        Dim weight1_array(100) As Double
        Dim weight2_array(100) As Double
        Dim ERTweight As Double
        Dim ERTweight_array(100) As Double

        For Each dview4 In ListBox5.Items
            ETR_array(size) = dview4.Row.Item(5)
            totalETR = totalETR + ETR_array(size)
            size = size + 1
        ' This part is to retrieve all rows of the Estimated Time Required (ETR) from listbox3 (row by row)

        Label18.Text = "total ETR :" & totalETR.ToString

        For count As Integer = 0 To size
            weight1_array(size) = totalETR / ETR_array(size)
            MsgBox(totalETR / ETR_array(size))
            Sum_weight1 = Sum_weight1 + TotalETR_div_ETR_array(size)
            size = size + 1

        Next count
        'step1 calculation

        For count2 As Integer = 0 To size
            weight2_array(size) = (weight1_array(size) / Sum_weight1) * 10
        Next count2
        'step 2 calculation

the whole idea of the coding works is as shown in the image attachment.. :)/>/>/>
my error is the output, weight1_array(size)and weight2_array(size) which im trying to get show 'infinity'
problem : my database only have 5 rows of data but why does the lopping goes 16times..?
may i know which part goes wrong??

TQ so much for ur help and time.. Appreciate so much!

Attached image(s)

  • Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: for next looping

#2 andrewsw  Icon User is offline

  • There's no such thing as the Dog Poo Fairy
  • member icon

Reputation: 5797
  • View blog
  • Posts: 22,952
  • Joined: 12-December 12

Re: for next looping

Posted 09 May 2013 - 06:46 AM

Where does the variable size come from? You seem to keep increasing its value. In particular, I would not be increasing it within this loop:

For count As Integer = 0 To size
    size = size + 1

This is not causing an infinite loop, but it is something I would be wary of doing.

There is a debugging tutorial linked in my signature. I recommend that you take this so that you could step through your code.

This post has been edited by andrewsw: 09 May 2013 - 06:51 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1