VB.NET - Automatic textchanged

Asked

Viewed 37 times

1

Come on, you guys! I am trying to realize automatic date. For example, if I choose the year of the field "Up", in the year 2018. The "From" field automatically calculates for year 2013.

As print below:

inserir a descrição da imagem aqui

I was able to automate only this one. But when I want to change the field "Until", from 18/04/2018 to 18/04/2015. The field "From" remains the year 2013.

inserir a descrição da imagem aqui

What I want is to calculate five years difference.

Just follow my code:

Imports Microsoft.Office.Interop

Public Class FormRelatorio
    Dim XcelApp As New Excel.Application()

    'Private Sub carregaGrid()
    '    Try
    '        Dim dt As New DataTable
    '        dt.Columns.Add("Codigo", GetType(Integer))
    '        dt.Columns.Add("Nome", GetType(String))
    '        dt.Columns.Add("Admissao", GetType(DateTime))
    '        dt.Columns.Add("Setor", GetType(Integer))
    '        dt.Columns.Add("Salario", GetType(Double))
    '        Dim dr As DataRow = dt.NewRow()
    '        dr("Codigo") = 1
    '        dr("Nome") = "João Torres"
    '        dr("Admissao") = DateTime.Now
    '        dr("Setor") = 20
    '        dr("Salario") = 20000
    '        dt.Rows.Add(dr)
    '        dr = dt.NewRow()
    '        dr("Codigo") = 2
    '        dr("Nome") = "Jennifer"
    '        dr("Admissao") = DateTime.Now
    '        dr("Setor") = 40
    '        dr("Salario") = 20000
    '        dt.Rows.Add(dr)
    '        dgvDados.DataSource = dt
    '    Catch ex As Exception
    '        MessageBox.Show("Erro" + ex.Message)
    '    End Try
    'End Sub

    Private Sub Label3_Click(sender As System.Object, e As System.EventArgs) Handles Label3.Click

    End Sub

    Private Sub gerarBtn_Click(sender As System.Object, e As System.EventArgs) Handles gerarBtn.Click
        If dgvDados.Rows.Count > 0 Then
            Try
                XcelApp.Application.Workbooks.Add(Type.Missing)

                For i As Integer = 1 To dgvDados.Columns.Count
                    XcelApp.Cells(1, i) = dgvDados.Columns(i - 1).HeaderText
                Next
                '
                For i As Integer = 0 To dgvDados.Rows.Count - 2
                    For j As Integer = 0 To dgvDados.Columns.Count - 1
                        XcelApp.Cells(i + 2, j + 1) = dgvDados.Rows(i).Cells(j).Value.ToString()
                    Next
                Next
                '
                XcelApp.Columns.AutoFit()
                '
                XcelApp.Visible = True
            Catch ex As Exception
                MessageBox.Show("Erro: " + ex.Message)
                XcelApp.Quit()
            End Try
        End If
    End Sub

    Private Sub Relatorio_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'AntaqDataSet.T400_ATRACACAO' table. You can move, or remove it, as needed.
        Dim dbase As New dBase
        Me.T400_ATRACACAOTableAdapter.Fill(Me.AntaqDataSet.T400_ATRACACAO)
        ' carregaGrid()
        dgvDados.DataSource = dbase.GetAllAtracacao()
        Dim dtEscolha As DateTime
        dtEscolha = dtpAtual.Text
        txtBoxDe.Text = dtEscolha.AddYears(-5)
    End Sub

    Private Sub MaskedTextBox2_MaskInputRejected(sender As System.Object, e As System.Windows.Forms.MaskInputRejectedEventArgs)

    End Sub

    Private Sub dgvDados_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvDados.CellContentClick

    End Sub

    Private Sub dtpAtual_ValueChanged(sender As System.Object, e As System.EventArgs) Handles dtpAtual.ValueChanged

    End Sub

    Private Sub txtBoxDe_MaskInputRejected(sender As System.Object, e As System.Windows.Forms.MaskInputRejectedEventArgs) Handles txtBoxDe.MaskInputRejected
        System.Diagnostics.Debug.Write(dtpAtual.Text)
    End Sub
End Class
  • That’s right, you have to use the event of the two fields to calculate the difference of dates... This project is Web?

  • It’s not... It’s Windows Form, Windows platform.

  • I get it... if it was Web I was gonna tell you to use Javascript.... Puts your answer in the answer field to identify platform that your question has been answered...

  • @Joaotorresmoreira, if the question has been resolved, you can post the answer and mark it as such. No need to change the question title

  • 1

    @Rovannlinhalis thanks for the suggestion! I have already put reply :)

1 answer

0


REPLY:

Includes code for dptAtual_ValueChanged event:

Private Sub dtpAtual_ValueChanged(sender As System.Object, e As 
System.EventArgs) Handles dtpAtual.ValueChanged Dim dtEscolha As DateTime dtEscolha = dtpAtual.Text txtBoxDe.Text = dtEscolha.AddYears(-5) End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.