Home > Software engineering >  Who help me take a look at this problem,
Who help me take a look at this problem,

Time:10-09

Vb programming, 5, write a program to achieve: dong zhong input, this day is this the first day of the year, (hint: leap year is different from a leap year),

There is something wrong with the code can't run,
Private Sub Form_Load ()

'subject, dong zhong input, this day is this how many days in a year?

'create a label, which is used to output the results

'create three button, the caption for sure, reset, exit

'at the beginning of the program, let label prompts for data

Label1. Caption="please enter year, month, day, query, don't bring any non-numeric characters"

End Sub

Private Sub Command3_Click () 'button is clicked, triggering event

Dim cyear cmonth cday, 'they three were stored the content of the text box

Dim days' store the results of variable

'to determine whether there is data input

Texts=Text1. Text + Text2. Text + Text3. Text 'if you don't is digital, together can't be a digital

If IsNumeric (texts)=False Then 'function IsNumeric () to determine whether to digital

MsgBox ", you may input is wrong, please input again!" , 48, "date ordinal judging
"
'error automatically after clear text box

Text1. Text=""

Text2. Text=""

Text3. Text=""

', if the data is not wrong to be nested determine leap year, leap year, classification processing

The Else

'to the variable assignment

Cyear=Text3. Text

Cmonth=Text2. Text

Cday=Text1. Text

'VB Select statement format is

'the Select Case & lt; Expression & gt;

'Case & lt; Expression results table column 1 & gt;

'& lt; Statements group 1 & gt;

'Case & lt; Expression result table column 2 & gt;

'& lt; Statements in group 2 & gt;

'...

'Case & lt; Expression result table column n>

'& lt; N> statement value;

'Case Else

'& lt; Statements set of n + 1 & gt;

'to End the Select

'in SelectCase statement, one is used to determine expression, according to the different results of this expression,

'perform different SelectCase expression result judgment, and then perform different operations,

'calculation cmonth before the date of the first few

The Select Case cmonth 'when cmonth take different values, perform the following different statement

Case 1

Days=0

Case 2

31 days=

Case 3

59 days='is initialized to 28 days in February, the number of common year February

Days=90

Case 5

Days=120

Case 6

Days=151

Case 7

Days=181

Case 8

Days=212

Case 9

Days=243

Case 10

Days=273

Case 11

Days=304

Case 12

Days=334

End the Select 'End of the Select process

If ((cyear Mod 100 & lt;> 0 And cyear Mod 4=0) Or cyear Mod=0 400) And cmonth & gt; 2 Then 'judgment leap year leap year

Label1. The Caption=days + cday + 1

The Else

Label1. Caption=days + cday

End the If

End the If

End Sub

Private Sub Command2_Click () 'this is the reset button, restore to begin state can (remove button command code),

Label1. Caption="please enter year, month, day, query, don't bring any non-numeric characters"

Text1. Text=""

Text2. Text=""

Text3. Text=""

End Sub

Private Sub Command1_Click () 'this is exit button

End

End Sub

CodePudding user response:

Don't need to use DateDiff let this date and year on January 1, it is ok to compare,

Dim dt As DateTime
Dim s As String
S="2014/5/5"
Dt=CDate (s)
MsgBox DateDiff (" d ", dt, CDate (Left (s, 4) & amp; "/1/1")) & amp; "Day"

CodePudding user response:

Thank you for your help.

CodePudding user response:

refer to the second floor zuijiazhuangtai response:
thank you for your help.

That's some "button to 25,