Solved

Create a display screen

Posted on 2004-08-12
9
395 Views
Last Modified: 2013-11-26
Hi

I REALLY NEED TO GET THIS DONE. And hopefully this will be the last question I am asking.

I select statement which return the following

Col1      Col2
1            a
2            b
3            c
4            d

Depending on the criteria the number of rows returned varies.
From this information I have to display the following.

1     a          a+b       a+b+c           a+b+c+d
2                  b            B+c             b+c+d
3                                c                c+d
4                                                   d


Could someone Please help me how would I display it?
Would it be easier to do in vb.net (I am new to it!) or which other way would you suggest???
0
Comment
Question by:ChanderMadhavi
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 11789368
Use whichever language you're comfortable with - the approach would be the same in all.

You have 16 fields, the bottom left 6 of which will always be blank.  The rest you valued or clear depending on how many row you got.

..unless I've completely misunderstood you (it happens)
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11789492
The problem can easily be solved via a recursive algorithm and shouldn't be hard to implement.
Couple of questions though:

1) Do want the literal values concatentated together with + symbols...or are you computing the sum of the values?
2) What do you want the output to be in?  A text file?  Some kind of grid?
3) Where is the input data coming from?  An array?  Some kind of collection?  A grid?
4) What language do you want?  VB.Net?  VB6? something else?....

Idle_Mind
0
 

Author Comment

by:ChanderMadhavi
ID: 11790576
1) I am computing the sum of the values a, b, c, d are values which need to be added.

2) the output needs to be in a grid

3) the input data comes from a query  The result comes out as a data set. I could use the select statement and create stored procedure in SQL and manipulate results never done it before. Else could do it in VB.net

4) The number of rows returned by a query could differ example if rows are 6 the grid would be

Col1      Col2
1            a
2            b
3            c
4            d
5            e
6            f

Depending on the criteria the number of rows returned varies.
From this information I have to display the following.

1     a          a+b       a+b+c           a+b+c+d      a+b+c+d+e   a+b+c+d +e+f
2                  b            B+c             b+c+d            b+c+d+e       b+c+d+e+f
3                                c                c+d                   c+d+e           c+d+e+f
4                                                   d                      d+e                d+e+f
5                                                                             e                     e+f
6                                                                                                      f

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 6

Expert Comment

by:SCDMETA
ID: 11793607
1)      Create array the size of your recordset.
2)      Move your data from the recordset to the array.
3)      Create a RowIndex loop that goes from bottom of the array to the top of the array.
                a.      Set SUM = 0
                b.      Create a ColIndex loop that goes from the current RowIndex to the top of the array.
                               i.      SUM = SUM + Array(ColIndex)
                               ii.      SET Grid(RowIndex, ColIndex) = SUM

In code it would look something like this:
    numCols = rs.RecordCount
    Dim values(numCols - 1) as long
    ColIndex = 0
    While Not (rs.EOF)
        values(ColIndex) = rs.Fields("Col2")
        ColIndex = ColIndex + 1
    Wend
   
    For RowIndex = 0 To numCols - 1
        sum = 0
       
        For ColIndex = RowIndex To numCols - 1
            sum = sum + values(ColIndex)
            grid(RowIndex, ColIndex) = sum
        Next
    Next

0
 
LVL 6

Expert Comment

by:SCDMETA
ID: 11793615
Opps...need to move to the next record in the loop

values(ColIndex) = rs.Fields("Col2")
rs.movenext
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 11793744
I ended up just doing it iteratively:

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Panel2 As System.Windows.Forms.Panel
    Friend WithEvents DataGrid2 As System.Windows.Forms.DataGrid
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.Label1 = New System.Windows.Forms.Label
        Me.Panel2 = New System.Windows.Forms.Panel
        Me.DataGrid2 = New System.Windows.Forms.DataGrid
        Me.Label2 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.Panel1.SuspendLayout()
        Me.Panel2.SuspendLayout()
        CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'DataGrid1
        '
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(0, 0)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(584, 168)
        Me.DataGrid1.TabIndex = 0
        '
        'Panel1
        '
        Me.Panel1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Panel1.AutoScroll = True
        Me.Panel1.Controls.Add(Me.DataGrid1)
        Me.Panel1.Location = New System.Drawing.Point(8, 24)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(584, 168)
        Me.Panel1.TabIndex = 2
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 16)
        Me.Label1.TabIndex = 3
        Me.Label1.Text = "Input Data:"
        '
        'Panel2
        '
        Me.Panel2.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Panel2.AutoScroll = True
        Me.Panel2.Controls.Add(Me.DataGrid2)
        Me.Panel2.Location = New System.Drawing.Point(8, 248)
        Me.Panel2.Name = "Panel2"
        Me.Panel2.Size = New System.Drawing.Size(584, 184)
        Me.Panel2.TabIndex = 4
        '
        'DataGrid2
        '
        Me.DataGrid2.DataMember = ""
        Me.DataGrid2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.DataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid2.Location = New System.Drawing.Point(0, 0)
        Me.DataGrid2.Name = "DataGrid2"
        Me.DataGrid2.Size = New System.Drawing.Size(584, 184)
        Me.DataGrid2.TabIndex = 0
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 232)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(72, 16)
        Me.Label2.TabIndex = 5
        Me.Label2.Text = "Output Data:"
        '
        'Button1
        '
        Me.Button1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Button1.Location = New System.Drawing.Point(464, 200)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(128, 24)
        Me.Button1.TabIndex = 6
        Me.Button1.Text = "Generate Output Table"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(600, 438)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Panel2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Panel1)
        Me.Name = "Form1"
        Me.Text = "Generate Display Grid"
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.Panel1.ResumeLayout(False)
        Me.Panel2.ResumeLayout(False)
        CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private data As DataSet = New DataSet("Data")

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As DataTable = data.Tables.Add("Input")
        Dim workRow As DataRow
        Dim i As Integer

        data.Tables.Add("Output")
        dt.Columns.Add("Col1", Type.GetType("System.Int32"))
        dt.Columns.Add("Col2", Type.GetType("System.Int32"))

        For i = 1 To 6
            workRow = dt.NewRow()
            workRow(0) = i
            workRow(1) = i
            dt.Rows.Add(workRow)
        Next i
        DataGrid1.DataSource = data.Tables("Input")
        DataGrid2.DataSource = data.Tables("Output")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim input As DataTable = data.Tables("Input")
        Dim output As DataTable = data.Tables("Output")
        Dim dr As DataRow
        Dim dc As DataColumn
        Dim r As Integer
        Dim c As Integer
        Dim s As Integer
        Dim sum As Integer

        output.Clear()
        output.Columns.Clear()
        output.Columns.Add(New DataColumn)
        For r = 1 To input.Rows.Count
            output.Columns.Add(New DataColumn("Sum" & r))
        Next r

        For r = 1 To input.Rows.Count
            dr = output.NewRow
            dr(0) = r
            For c = r To input.Rows.Count
                sum = 0
                For s = r To c
                    sum = sum + input.Rows(s - 1)(1)
                Next
                dr(c) = sum
            Next c
            output.Rows.Add(dr)
        Next r
    End Sub

End Class
0
 

Author Comment

by:ChanderMadhavi
ID: 11794794
Hi
I really really appreciate your immediate reply. But I realise that the stuff is vb.net windows application. I am looking at the same thing in Vb.net web application. Could you please help me. You were very fast in doing it too.
Thanks
Madhavi
0
 

Author Comment

by:ChanderMadhavi
ID: 11795448
Hi

I got it working with a web application.
THANKS A LOT. Can I award you bonus points!!!. I really would like to!
Madhavi
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11796077
No need for bonus points...Thank you though!

Glad you got it to work with your web app.

Idle_Mind
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 115
recursion example 16 126
simplest php form 3 78
IF ELSE Statement in Excel Macro VBA 16 63
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question