Click here to Skip to main content
15,895,370 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim i As Integer
        Dim itemcode(100) As String
        Dim qty(100) As Double
        Dim price(100) As Double
        Dim total(100) As Double
        For j = 175 To 255 Step 20

            For i = 0 To DataGridView1.RowCount - 1 Step 1
                itemcode(i) = DataGridView1.Rows(i).Cells(0).Value
                price(i) = DataGridView1.Rows(i).Cells(2).Value7
               qty(i) = DataGridView1.Rows(i).Cells(1).Value                       total(i) = DataGridView1.Rows(i).Cells(3).Value

                e.Graphics.DrawString(itemcode(i), New Font("Times New Roman", 7, FontStyle.Bold), _
        Brushes.Black, 3, j)
                e.Graphics.DrawString(qty(i).ToString, New Font("Times New Roman", 7, FontStyle.Bold), _
        Brushes.Black, 90, j)
                e.Graphics.DrawString(price(i), New Font("Times New Roman", 7, FontStyle.Bold), _
        Brushes.Black, 140, j)
                e.Graphics.DrawString(total(i), New Font("Times New Roman", 7, FontStyle.Bold), _
        Brushes.Black, 180, j)
                'End If
                MsgBox(itemcode(i))
                MsgBox(qty(i))
                'MsgBox(price(i))
                'MsgBox(total(i))
            Next i
        Next j
Posted
Updated 24-Aug-15 20:07pm
v3
Comments
DamithSL 25-Aug-15 2:13am    
what is the issue with current code?
Member 11933076 25-Aug-15 8:03am    
10CBK
2.5
25
0

0
0
This is the output after amended as per your suggestion. those zeros are coming from the variable inside the loop after reading the datagridview. second one is string that is why it is blank
Member 11933076 25-Aug-15 8:07am    
i want to eliminate the zeros only the first 4 things should come. thanks

1 solution

You do not need to declare your temporary variables as an array - replace:

VB
Dim qty(100) As Double
Dim price(100) As Double
Dim total(100) As Double

with
VB
Dim qty As Double
Dim price As Double
Dim total As Double

and assign the variables each time you go round the loop:-
VB
itemcode = DataGridView1.Rows(i).Cells(0).Value
price = DataGridView1.Rows(i).Cells(2).Value
qty = DataGridView1.Rows(i).Cells(1).Value                       
total = DataGridView1.Rows(i).Cells(3).Value


Also - don't use MsgBox for debugging - use System.Diagnostics.Debug.Print and breakpoint on that row.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900