2 Replies - 362 Views - Last Post: 24 January 2014 - 08:05 PM Rate Topic: -----

#1 claymore18  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 10-September 13

Using Multiple Looping In One DatagridView

Posted 22 January 2014 - 09:20 PM

Dear All,

would you mind to support me a logic and also sample script.

i have a datagridview and i'am using VB2008. i wish to have 2 looping data at same datagridview in different column.

first column, wish to fill each rows as 1 to 24
second column, wis to fill each rows as 1 to 12 for 1 to 12 as first rows column.. then 13 to 24 start again as 1 to 12

please tell if there any idea about it.
thanks to all

Is This A Good Question/Topic? 0
  • +

Replies To: Using Multiple Looping In One DatagridView

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Using Multiple Looping In One DatagridView

Posted 24 January 2014 - 09:44 AM

This can be done with a single loop and a second variable that you increment inside the loop.

Loop 1 to 24

use the iterator variable of the for...loop to fill first column since it will increment from 1 to 24
use a variable that you increment on each loop for the second column
check to see if second-column variable is greater than 12 and if it is, set it back to 1
add your row using the iterator value for the first column and your increment variable for the second column.


EDIT:
If you really want to challenge yourself, you could do it with just a loop from 1 to 24 and use an inline if statement to check if x> 12 and if so, -12 from it for the second column when adding your row.

This post has been edited by CharlieMay: 24 January 2014 - 09:52 AM

Was This Post Helpful? 0
  • +
  • -

#3 claymore18  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 10-September 13

Re: Using Multiple Looping In One DatagridView

Posted 24 January 2014 - 08:05 PM

View PostCharlieMay, on 24 January 2014 - 09:44 AM, said:

This can be done with a single loop and a second variable that you increment inside the loop.

Loop 1 to 24

use the iterator variable of the for...loop to fill first column since it will increment from 1 to 24
use a variable that you increment on each loop for the second column
check to see if second-column variable is greater than 12 and if it is, set it back to 1
add your row using the iterator value for the first column and your increment variable for the second column.


EDIT:
If you really want to challenge yourself, you could do it with just a loop from 1 to 24 and use an inline if statement to check if x> 12 and if so, -12 from it for the second column when adding your row.




Dear Charlie,
thanks to reply. yes i did that before i read your quote.

i have done the script as below :

Private Sub Loopa()

Dim UrutanAngka, AssetAmount, DepreAmount, HasilDepre, BulanMulai, BulanSelesai, _
TahunMulai, TahunSelesai, DeprePeriod, BarisHitung As String

AssetAmount = TxtASSETAMOUNT.Text
DeprePeriod = CmbDEPREPERIOD.Text
BulanMulai = CmbSTARTINGMONTH.Text
TahunMulai = CmbSTARTINGYEAR.Text

UrutanAngka = 0
DepreAmount = AssetAmount / DeprePeriod / 12
HasilDepre = 0
BulanSelesai = BulanMulai - 1

BarisHitung = DeprePeriod * 12 + 12
TahunSelesai = Val(TahunMulai) + Val(DeprePeriod)

Dim AngkaBulan As New Date(TahunMulai, 1, 1)

For Y = 0 To BarisHitung - 1

UrutanAngka = UrutanAngka + 1

If Month(AngkaBulan) < BulanMulai And Year(AngkaBulan) = TahunMulai Then
HasilDepre = 0

ElseIf Month(AngkaBulan) = BulanMulai And Year(AngkaBulan) = TahunMulai Then
HasilDepre = DepreAmount

ElseIf Month(AngkaBulan) > BulanMulai And Year(AngkaBulan) = TahunMulai Then
HasilDepre = DepreAmount

ElseIf Month(AngkaBulan) < BulanMulai And Year(AngkaBulan) > TahunMulai Then
HasilDepre = DepreAmount

ElseIf Month(AngkaBulan) > BulanSelesai And Year(AngkaBulan) = TahunSelesai Then
HasilDepre = 0

End If

DgvLoop.Rows.Add(UrutanAngka, Format(AngkaBulan, "MM"), Format(AngkaBulan, "yyyy"), HasilDepre)
AngkaBulan = AngkaBulan.AddMonths(1)

With DgvLoop.Rows(Y).Cells(3)
.ValueType = GetType(NumericUpDown)
.Style.Format = "n2"
.Value = CSng(.Value)
End With
Next

End Sub

anyway, again thanks to reply about my trouble...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1