Click here to Skip to main content
15,894,646 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: compare files with hash tables, find dupe files in folder, manage hash table [modified] Pin
NikWing6-Apr-10 2:21
NikWing6-Apr-10 2:21 
AnswerRe: compare files with hash tables, find dupe files in folder, manage hash table Pin
NikWing6-Apr-10 13:02
NikWing6-Apr-10 13:02 
QuestionVb.net & SQLite Pin
Ben Magee5-Apr-10 3:25
Ben Magee5-Apr-10 3:25 
AnswerRe: Vb.net & SQLite Pin
Sebastian Br.5-Apr-10 21:18
Sebastian Br.5-Apr-10 21:18 
QuestionRecursive Function [modified] Pin
Andy_L_J4-Apr-10 16:51
Andy_L_J4-Apr-10 16:51 
AnswerRe: Recursive Function Pin
riced4-Apr-10 23:41
riced4-Apr-10 23:41 
GeneralRe: Recursive Function Pin
Andy_L_J5-Apr-10 2:35
Andy_L_J5-Apr-10 2:35 
GeneralRe: Recursive Function [modified] Pin
riced5-Apr-10 4:19
riced5-Apr-10 4:19 
Here's some code that does what I think you are trying to do.
It's a function that returns a DataTable with the additional rows.
I'm not keen on adding/inserting rows in loops where the loop is controlled by the count of items in the table. I've seen situations where the count is evaluated only when the loop is entered so when rows are added/inserted in the loop fails to deal with some records. Don't know if VB.Net does this in it's For loop.

Private Function SummRow(ByRef dt As DataTable) As DataTable
 'EDIT - Oops - has a bug that causes runtime error
End Function

OO buffs will not like the arr() of objects because it's not type safe. It also assumes the DataTable rows have a string followed by up to 13 numeric values.

This fixes bug.
Private Function SummRow(ByRef dt As DataTable) As DataTable
   Dim tmp as DataTable = dt.Clone()

   Dim rowNum As Integer = 0
   Dim arr() As Object = {"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
   Dim fNo As Integer = 0
   Dim column0 as String

   'Loop through the DataTable
   While rowNum < dt.Rows.Count
      'Set controls for next group of rows based on column0
      fNo += 1
      column0 = Left(dt.Rows(rowNum).Item(0).ToString, 4)
      arr(0) = "F"& fno.ToString & " Totals"

      'Loop through rows with same entry in column 0
      While (rowNum < dt.Rows.Count) AndAlso (column0 = Left(dt.Rows(rowNum).Item(0).ToString, 4))
         For colNum As Integer = 1 To dt.Columns.Count - 1
            If Not TypeOf dt.Rows(rowNum).Item(colNum) Is DBNull Then
               arr(colNum) += CType(dt.Rows(rowNum).ItemArray(colNum), Double)
            End If
         Next colNum
         tmp.Rows.Add(dt.Rows(rowNum)
         rowNum +=1
      End While

      'Add the running totals row on change of column0
      Dim newRow as DataRow = tmp.NewRow
      newRow.ItemArray = arr
      tmp.Add(newRow)
   End While

   Return tmp
End Function

Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
modified on Tuesday, April 6, 2010 3:32 AM

AnswerRe: Recursive Function Pin
William Winner7-Apr-10 8:18
William Winner7-Apr-10 8:18 
QuestionGet the parent objet or parent level in nested lists Pin
norrisMiou4-Apr-10 0:51
norrisMiou4-Apr-10 0:51 
AnswerRe: Get the parent objet or parent level in nested lists Pin
DaveAuld4-Apr-10 2:28
professionalDaveAuld4-Apr-10 2:28 
GeneralRe: Get the parent objet or parent level in nested lists Pin
norrisMiou4-Apr-10 2:56
norrisMiou4-Apr-10 2:56 
GeneralRe: Get the parent objet or parent level in nested lists Pin
DaveAuld4-Apr-10 5:36
professionalDaveAuld4-Apr-10 5:36 
AnswerRe: Get the parent objet or parent level in nested lists Pin
Alan N4-Apr-10 6:04
Alan N4-Apr-10 6:04 
GeneralRe: Get the parent objet or parent level in nested lists Pin
norrisMiou5-Apr-10 7:26
norrisMiou5-Apr-10 7:26 
GeneralRe: Get the parent objet or parent level in nested lists Pin
Alan N5-Apr-10 13:19
Alan N5-Apr-10 13:19 
GeneralRe: Get the parent objet or parent level in nested lists Pin
norrisMiou5-Apr-10 15:29
norrisMiou5-Apr-10 15:29 
QuestionLinking Databases to VB Applications Pin
Razanust3-Apr-10 19:36
Razanust3-Apr-10 19:36 
AnswerRe: Linking Databases to VB Applications Pin
riced3-Apr-10 23:59
riced3-Apr-10 23:59 
AnswerRe: Linking Databases to VB Applications Pin
εїзεїзεїз4-Apr-10 0:19
εїзεїзεїз4-Apr-10 0:19 
GeneralRe: Linking Databases to VB Applications Pin
Razanust4-Apr-10 4:40
Razanust4-Apr-10 4:40 
GeneralRe: Linking Databases to VB Applications Pin
riced4-Apr-10 4:57
riced4-Apr-10 4:57 
AnswerRe: Linking Databases to VB Applications Pin
Luc Pattyn4-Apr-10 5:09
sitebuilderLuc Pattyn4-Apr-10 5:09 
AnswerRe: Linking Databases to VB Applications Pin
Luc Pattyn4-Apr-10 5:13
sitebuilderLuc Pattyn4-Apr-10 5:13 
GeneralRe: Linking Databases to VB Applications Pin
Razanust4-Apr-10 8:15
Razanust4-Apr-10 8:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.