I want to judge whether the memorized year/month/day/hour/minute/second is properly reading the data of the next second.
There is no error message.
IF statement doesn't judge well.
If data(i).date = DateAdd("s", 1, data(i-1).date) Then I = i + 1 Else MsgBox "The data is incorrect." Unload Standbyscreen Exit Sub End If
What I tried
(Only the problematic sentence is pasted)
The solution is completely unknown and untouched...
If the year, month, day, hour, minute, and second that you have just memorized is equal to the value that has been memorized by adding 1 second to the previous date, proceed to the next value.
If not, the data is incorrect and the process is terminated.
The flow is as follows.
This IF statement has the same value on the left and right side, but it goes into the else statement, which is a problem. ..
All numbers are in this notation. 2020/3/1 7:18:04
What I don't understand about this error is that it makes more difference depending on the number of seconds.
In 2020/3/1 7:18:04, it goes to else, but in the next 2020/3/1 7:18:05, it moves normally.
2020/3/1 7:18:06 will move normally, and on 2020/3/1 7:18:07, it will move to else again.
Set the value you saw in the watch window.
Because the data is different, it is different from the above time.
Since the original data is a CSV file and is a string type, it is converted to a Date type when it is stored in data(i).date.
It is exactly the same when you look at the numbers inside using a debug tool.
Does it mean that they look the same, but they are actually different?
Thanks for your response...!
Answer # 1
I checked it with the following code.
Certainly it will be False when compared to the DateAdd result.
Dim d1 As Date, d2 As Date d1 = #1/1/2020 12:45:30 PM# d2 = #1/1/2020 12:45:31 PM# Debug.Print d2 = DateAdd("s", 1, d1)
I tried converting with CDate whether the return value of DateAdd is affected by Variant type, or storing the result in Date type variable and comparing it, it became False.
The cause is a little unknown. It may be called a bug.
As a solution, DateDiff was used to find the seconds difference, and then it returned True.
Debug.Print DateDiff("S", d1, d2) = 1
Answer # 2
I think that it is a specification that an arithmetic error of less than a few occurs, so
How about comparing in Format?
Format(data(i).Date, "yyyy/mm/dd hh:mm:ss") = Format(DateAdd("s", 1, data(i-a).Date), "yyyy/mm/dd hh :mm:ss")
- vba if statement multiple conditions
- Use MySQL update statement correctly
- Use MySQL INSERT INTO statement correctly
- vba for statement arr (n)
- in vba, if a part of the nested structure in the for/if statement occurs frequently, can you write it only once?
- conditional branch of vba if statement
- [excelvba] if statement is skipped in the middle of for statement loop
- i want to incorporate access vba iif processing into an sql statement
- vba - data acquired by worksheetfunctionmatch does not reflect correctly on the copy destination
- vba - excel macro sql statement open error
- vba - i want to put the sql statement as a string into a variable and output it to excel
- i want to get the cell value from python3 vba and use it as an argument when running run python in the xlwings module
- vba - date between specified dates
- vba - for next double loop
- vba - how to convert to half size
- vba - image position and size automatic adjustment paste
- copying a specific sheet in a workbook containing a macro in excel vba causes the macro to be transferred to a specific sheet
- in excelvba, i want to disable the checkbox
- vba iteration method
- vba - does using different data types, long and byte, reduce memory or increase processing speed?
- i want to share a part of the system made with vba with vbnet to solve the problem of modal form