Hi guys, I want to create a window application from VB, so that a user can enter the OLD Power value in table.
Then line chart will be created in that windows application. My Old Power data already obtained and recorded in Excel.

So, in that window application,

1) The LINE CHART will be always updated when the user change the OLD POWER value.

2) The NEW POWER value will be always updated when the user change the OLD POWER value.

3) There will be two line chart:

3.1) Time vs Old Power
3.2) Time vs New Power

My problem is:

1) How to have NEW POWER value automatically shown in table, when a OLD POWER value is entered ?

2) Is that possible to created a NEW POWER in access? I cant find any ways with my basic knowledge of VB and MS.Access.

Here my Code:

Public Class Form1

    Private Sub Table1BindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Table1BindingNavigatorSaveItem.Click
        Me.Validate()
        Me.Table1BindingSource.EndEdit()


    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the '_5DataSet.Table1' table. You can move, or remove it, as needed.
        Me.Table1TableAdapter.Fill(Me._5DataSet.Table1)


    End Sub

    'CHART1
    Private Sub Chart1_Click(sender As Object, e As EventArgs) Handles Chart1.Click
        Chart1.DataBind()
        Chart1.Update()
    End Sub

    Private Sub Table1BindingNavigator_RefreshItems(sender As Object, e As EventArgs) Handles Table1BindingNavigator.RefreshItems

    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click

    End Sub

    Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click

    End Sub

    'DATAGRIDVIEW
    Private Sub Table1DataGridView_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles Table1DataGridView.CellContentClick

    End Sub

    'SAVE BUTTON
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Table1BindingNavigatorSaveItem.PerformClick()
        MsgBox("Data Updated")
    End Sub

    'DELETE BUTTON
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        BindingNavigatorDeleteItem.PerformClick()
        MsgBox("Data Deleted")
    End Sub
    'ADDNEW BUTTON
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        BindingNavigatorAddNewItem.PerformClick()

    End Sub
End Class

Please do take a look at the attachment cantained Picture's, and Data_Obtained_xlsx

I'm very sorry for my basic knowledge of VB, Im really hope to have your advice/guidance. Thanks and regrads.

Recommended Answers

All 12 Replies

Yes you can change New Power value after changing Old Power Value programmatically. To change of a cell value on changing of other cell value you must use DataGridView CellEndEdit or CellValueChanged event.
To change cell value the codes are

    Private Sub DataGridView1_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
        If e.ColumnIndex = 2 Then
            If Val(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) >= 20 Then
                DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
            Else
                Dim x As Double = Math.Round(20 / Val(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value), 2)
                DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = Math.Round(Val(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) * x, 6)
            End If
        End If

    End Sub

Hope it can help you.

Hi Shark 1,
Thanks for your reply and suggestion.

After I try the code, there was an error underline at DataGridView1. Then I change to Table1DataGridView. Here the code to check:

Private Sub Table1DataGridView_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Table1DataGridView.CellEndEdit

        If e.ColumnIndex = 2 Then
            If Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) >= 20 Then
                Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value

            Else

                Dim x As Double = Math.Round(20 / ValTable1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value),2)

                Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = Math.Round(Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) * x(), 6)

            End If
        End If
    End Sub

but there was a new error at Identifier expected. I try to figure out to chagne the space a delete the space between the code but nothing changed..

Value),2)

ValTable1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value),2)

You have missed a ( after Val. It should be

Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value),2)

thnx.

Thanks..
can I know what the meaning of this error? I get new error at this line:

Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = Math.Round(Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) * x(), 6)

It underline at

x(), 6)

Expression is not an array or a method, and cannot have an argument list

Unless x is a function, it is being interpreted as an array and you cannot use an array in an arithmetic operation unless you index to a specific element.

I tried to declare
dim x as double,

But there is still error. Is there any ways to solve based on the code before?

Sorry I really basic in programming

Try

Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = Math.Round(Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) * x, 6)

Where from you get x() * 6). It has no existance in my posted code snippet.
Here x is a Double Type variable. It is not an Array. So it generates an exception.
It would be x * 6).

Appologies for my mistake. Thanks the code explanation, it is now working.
But when the value is changed at OLD and NEW power, then sure code will be changed for at new specific row and column.

The Value change like this

Here the code I change a little bit

Private Sub Table1DataGridView_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Table1DataGridView.CellEndEdit

        'For e.ColumnIndex + 1
        If e.ColumnIndex = 2 Then
            If Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 5 Then
                Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 5

            ElseIf Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 7 Then
                Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 7

            ElseIf Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 1 Then
                Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 6

            Else
                Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 20

            End If
        End If

    End Sub

I have a problem at the value 1.5, 2, 2.5, 4. Because I cant force the value to be equal.
For example at Row17, Column Expr1 is difference at Row7, Column Expr1. But the OLD is same with value 4.

This type of calculations never depend on a single supplied value. The calculation is related with various conditions and parameters. It is not possible to make an equation to get this type of results on basis of a single value.
What are the relations between 'Time', 'LimitPower' , 'Old' and 'Expr1'? The equation depands on the relations between them. This is not possible to extract the relations and make an equation by looking a table.

The relations between 'Time', 'LimitPower' , 'Old' and 'Expr1' is, I need to plot the 'Expr1' vs 'Time'. Actually the 'Old' power value, I obtained from my experiment from the generator. 'LimitPower' is limited power in that generator that always 25MW.

Thanks for explanation Shark 1.

Due to it is not possible to extract the relations and make an equation by looking a table, the selected cell in the current column and row can multiply with constant?

for example, at Row:7 and Column:3 will multiply with constant: 0.05125 to get 0.205

and at Row:17 and Column:3 will multiply with constant:0.397 to get 1.588
Sorry for my basic level, I cant figured it out in code snippet

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.