Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8088

Профиль | Отправить PM | Цитировать


artemu88, старайтесь сразу прикладывать готовый проект, так будет проще отвечающим.

Project1.vbp
Код: Выделить весь код
Type=Exe
Form=Form1.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\Windows\SysWOW64\stdole2.tlb#OLE Automation
Startup="Form1"
Command32=""
Name="Project1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

Form1.frm
Код: Выделить весь код
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   2100
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5850
   LinkTopic       =   "Form1"
   ScaleHeight     =   2100
   ScaleWidth      =   5850
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox tbxResultInterval 
      Height          =   375
      Left            =   240
      Locked          =   -1  'True
      TabIndex        =   3
      Top             =   1440
      Width           =   5295
   End
   Begin VB.CommandButton cmdCalculate 
      Caption         =   "Calculate"
      Height          =   975
      Left            =   2760
      TabIndex        =   2
      Top             =   240
      Width           =   2775
   End
   Begin VB.TextBox tbxFinishDate 
      Height          =   375
      Left            =   240
      TabIndex        =   1
      Top             =   840
      Width           =   2295
   End
   Begin VB.TextBox tbxStartDate 
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   2295
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub cmdCalculate_Click()
    Dim dtStartDate As Date
    Dim dtFinishDate As Date
    
    Dim dtPartDate As Date
    
    Dim intYears As Integer
    Dim intMonth As Integer
    Dim intDays As Integer
    
    
    If IsDate(Me.tbxStartDate.Text) Then
        dtStartDate = CDate(Me.tbxStartDate.Text)
        
        If IsDate(Me.tbxFinishDate.Text) Then
            dtFinishDate = CDate(Me.tbxFinishDate.Text)
            
            intYears = DateDiff("yyyy", dtStartDate, dtFinishDate)
            dtPartDate = DateAdd("yyyy", intYears, dtStartDate)
            
            intMonth = DateDiff("m", dtPartDate, dtFinishDate)
            dtPartDate = DateAdd("m", intMonth, dtPartDate)
            
            intDays = DateDiff("d", dtPartDate, dtFinishDate)
            
            Me.tbxResultInterval.Text = intYears & " year(s) " & intMonth & " month(s) " & intDays & " day(s)"
        Else
            MsgBox "Finish date is not a date"
        End If
    Else
        MsgBox "Start date is not a date"
    End If
End Sub

Private Sub Form_Load()
    ' Две следующие строки для примера, в реальном проекте удалите их
    Me.tbxStartDate.Text = "01.01.1980"
    Me.tbxFinishDate.Text = "31.12.1999"
End Sub

Отправлено: 17:17, 05-09-2018 | #2