入住日期 Vb.net
Date Check in Vb.net
我遇到一个问题,在 excel 一列中包含一个唯一的数字,格式为:mmdd 后跟序列号 01,02.. 例如:101201(10:month, 12:today的日期,01:first 条目),101202。
现在,我需要的是我在 vb.net 中的表单应该采用最后输入的数据(例如:101202)检查它是否是今天的日期。如果是,则应该加 1 并显示在消息框中。(是,则应显示 101203)。如果不是,那么它应该采用当前日期并从 01 开始(如果是 101301,日期是 13/10/2016)。
我设法从上一行获取数据。但是我应该如何检查日期呢?
请帮忙!
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 位数字,所以现在您可以将其与今天的日期进行比较。我还用 t
替换了今天的日期,因为您 t
已经按照要求的格式使用了今天的日期。
还将变量命名为 t
和 r
让人很难理解它们的用途。
我遇到一个问题,在 excel 一列中包含一个唯一的数字,格式为:mmdd 后跟序列号 01,02.. 例如:101201(10:month, 12:today的日期,01:first 条目),101202。 现在,我需要的是我在 vb.net 中的表单应该采用最后输入的数据(例如:101202)检查它是否是今天的日期。如果是,则应该加 1 并显示在消息框中。(是,则应显示 101203)。如果不是,那么它应该采用当前日期并从 01 开始(如果是 101301,日期是 13/10/2016)。 我设法从上一行获取数据。但是我应该如何检查日期呢? 请帮忙!
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 位数字,所以现在您可以将其与今天的日期进行比较。我还用 t
替换了今天的日期,因为您 t
已经按照要求的格式使用了今天的日期。
还将变量命名为 t
和 r
让人很难理解它们的用途。