Am a student novices in vb.net. But task to vb.net for school project.
I want a code to help me add a No fo Months(this is an integer) from date and the result display in a tet box as a date.
I have 2 fields: Months and startdate, the third which enddate get focus, the system the enddate. eg 6 months to make a payments, the payment start from 01-02-2011. i want small code which would determine the enddate of the payment period. or the month/year of thee repayment period

Thanks for your help

Click Hereto check the turiturial of date and time function

Thanks for your help
am getting the error "reference to a non-shared member requires an object reference.

Private Sub msdEnd_Date_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles msdEnd_Date.GotFocus
        Dim start_Date, No_months As Integer
        Dim End_Date As Date
        End_Date = DateTime.AddMonths(txtNo_months.Text + MsdStart_Date.Text)
        Me.msdEnd_Date.Text = End_Date

    End Sub

so if your problem is solve then mark it to solve..............

Am having an error with highlighted line.reference to a non-shared member requires an object reference

Dim start_Date, No_months As Integer
        Dim End_Date As Date = System.DateTime.Now
        End_Date = End_Date.AddMonths(Convert.ToInt64(txtNo_months.Text) + Convert.ToInt64(MsdStart_Date.Text))
        MessageBox.Show(End_Date.ToString())

AddMonths() is a method of class date so need object of that class to call this method and it integer value as a argument not in string.
I hope you understand.

After applying your codes,no error but it does not display any result

 Dim start_Date, No_months As Integer
        Dim End_Date As Date = System.DateTime.Now
        start_Date = MsdStart_Date.Text
        No_months = txtNo_months.Text
        End_Date = End_Date.AddMonths(Convert.ToInt64(txtNo_months.Text) + Convert.ToInt64(MsdStart_Date.Text))
        Me.msdEnd_Date.Text = End_Date
End_Date.AddMonths(Convert.ToInt64(txtNo_months.Text) + Convert.ToInt64(MsdStart_Date.Text))

End_Date.AddMonths() this method take integer value as an argument so you have to supply integer value so please check

Convert.ToInt64(txtNo_months.Text) + Convert.ToInt64(MsdStart_Date.Text)

return integer value or not i mean to say

End_Date.AddMonths(<integer_value>)

If still you get problem then attached your project or post enough code to solve with documentation because it work in my machine

Attached is the forms and codes to analysis the date problem

What you attached? It contain only design of your form without code, you have add your code also with point out your problem line

Imports System.Data.SqlClient
Imports System.Data
Imports System.Data.DataSet
Imports System.Data.Sql
Imports System.Data.SqlTypes
Public Class LoanApproval
Dim ConnectionString As String
Dim Sql1, sql2 As String
Dim da As SqlDataAdapter
Dim ds As New DataSet
Private Bindingsource As New BindingSource
Private DataAdaptor As New SqlDataAdapter
Dim connection As String
Dim con As New SqlConnection
Dim put, fresh As String
Private Sub LoanApproval_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ConnectionString = "Data Source=GYANFI-PC\SA;Initial Catalog=Susuproject;User ID=sa;Password=303444"
End Sub

Private Sub txt_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLoan_no.LostFocus
Try
put = "SELECT * FROM Loan WHERE (Loan_no = @Loan_no)"
Dim mySqlDBConnection As New SqlConnection(ConnectionString)
Dim mySqlDBCommand As New SqlCommand(put, mySqlDBConnection)
mySqlDBCommand.Parameters.AddWithValue("@Loan_no", txtLoan_no.Text)
mySqlDBConnection.Open()
Using myDataReader As SqlDataReader = mySqlDBCommand.ExecuteReader
If myDataReader.Read() Then
txtAccount_no.Text = myDataReader.Item("Account_no").ToString
txtDate_Applied.Text = myDataReader.Item("Date_Applied").ToString
txtAccountHolder.Text = myDataReader.Item("First_Name").ToString & " - " & myDataReader.Item("Surname").ToString
'txtAccount_Name.Text = myDataReader.Item("Account_Name").ToString
txtPrin_Amount.Text = myDataReader.Item("Prin_Amount").ToString

Else
MessageBox.Show("Record Doesn't exit, Try Again")
Me.txtLoan_no.Clear()
txtLoan_no.Focus()
End If
End Using
mySqlDBConnection.Close()
Catch ex As SqlException
MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch err As System.Exception
MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

Private Sub txt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLoan_no.TextChanged

End Sub

Private Sub msdDate_Applied_MaskInputRejected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MaskInputRejectedEventArgs) Handles txtDate_Applied.MaskInputRejected

End Sub

Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
sql2 = "Update Loans set Date_Granted = '" & Me.MsdDate_Granted.Text & "',Approval='" & Me.chkApproval.Text & "',Start_Date ='" & Me.MsdStart_Date.Text & "',Monthly_repay='" & Me.txtMonthly_repay.Text & "' ,Loan_Interest='" & Me.txtLoan_Interest.Text & "',No_months ='" & Me.txtNo_months.Text & "',App_Amount='" & Me.txtApp_Amount.Text & "',End_Date ='" & Me.msdEnd_Date.Text & "'"
da = New SqlDataAdapter(sql2, ConnectionString)
da.Fill(ds, "LoanApproval")
MessageBox.Show("Record Successfuly Updated")

Me.btnupdate.Enabled = False
End Sub

Private Sub msdEnd_Date_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles msdEnd_Date.Leave
Dim start_Date, No_months As Integer
Dim End_Date As Date
' start_Date = MsdStart_Date.Text
' No_months = txtNo_month.Text
End_Date = End_Date.AddMonths(Convert.ToInt64(txtNo_month.Text) + Convert.ToInt64(MsdStart_Date.Text))
Me.msdEnd_Date.Text = End_Date
' MessageBox.Show(End_Date.ToString())

'Dim End_Date, b As Date
''Dim a = Date.Now.Month(txtNo_months.Text)
'b = MsdStart_Date.Text
'End_Date = DateAdd(a + b)

End Sub

Private Sub txtLoan_Interest_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLoan_Interest.LostFocus
Dim no_months, App_Amount, Loan_Interest, Monthly_repay As Integer
txtMonthly_repay = ((Loan_Interest / App_Amount) * 100) + App_Amount
Me.txtMonthly_repay.Text = monthly_repay
End Sub


Private Sub txtLoan_Interest_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLoan_Interest.TextChanged

End Sub
End Class

Private Sub msdEnd_Date_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles msdEnd_Date.Leave
Dim start_Date, No_months As Integer
Dim End_Date As Date=Now 'You have to initialize your date variable 
' start_Date = MsdStart_Date.Text
' No_months = txtNo_month.Text
End_Date = End_Date.AddMonths(Convert.ToInt64(txtNo_month.Text) + Convert.ToInt64(MsdStart_Date.Text))
Me.msdEnd_Date.Text = End_Date
' MessageBox.Show(End_Date.ToString())

'Dim End_Date, b As Date
''Dim a = Date.Now.Month(txtNo_months.Text)
'b = MsdStart_Date.Text
'End_Date = DateAdd(a + b)

End Sub

You have to initialize your date variable to which you like to add month ok
for example
date1=1/5/2011+5 month

for this you have to do some thing like

date1=1/5/2011
date1 = date1.AddMonths(Convert.ToInt64(txtNo_month.Text) + Convert.ToInt64(MsdStart_Date.Text))

I hope it will help you other wise feel free to ask

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.