date入住Vb.net

我有一个问题,在Excel中,一列中包含一个唯一编号,格式如下:mmdd后跟序列号01,02 ..例如:101201(10:月,12:今天的date,01:第一个条目),101202。 ,我需要的是,我的vb.net表单应该采取最后input的数据(例如:101202)检查是否是今天的date。 如果是,那么应该加1并显示在消息框中(是的,那么应该显示101203)。 如果不是,那么它应该采用当前date并从01开始(如果date是2016年10月13日,则为101301)。 我设法从上一行获取数据。 但是,我应该如何检查date? 请帮忙!

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click xlWorkBook = xlApp.Workbooks.Open("C:\Users\Desktop\testing.xlsx") 'xlApp.Visible = True xlWorkSheet = xlWorkBook.Sheets("Sheet1") Dim row As Long row = 1 With xlWorkSheet While .Cells(row, 2).value IsNot Nothing row = row + 1 End While 'MsgBox(row - 1) End With Dim r As Excel.Range Dim t As String = Format(Today, "MMdd") If xlWorkSheet.Cells(row - 1, 4).value Is Nothing Then Me.txtQuote.Text = t & "01" Else r = xlWorkSheet.Cells(row - 1, 4) Me.txtQuote.Text = (r.Value + 1) End If 'this is wrong and I know it's wrong If r.Value = Date.Today Then MsgBox("true") Else MsgBox("false") End If End Sub 

把这个写在你写的地方'this is wrong and I know it's wrong

 Dim rDate As String = CStr(r.Value).Substring(0, 4) If rDate = t Then MsgBox("true") Else MsgBox("false") End If 

rDate基本上从r的前4位数,所以现在你可以比较这个今天的date。 我也用t代替了今天的date,因为你已经不能使用今天的date了。

将variables命名为tr也很难理解它们的用途。