2016-10-12 8 views
0

Excelの1つの列にmmddとシリアル番号01,02の形式の一意の番号が含まれています。たとえば:101201(10:月、12:今日の日付、 01:first entry)、101202。 これで、vb.netのフォームで最後に入力したデータ(たとえば:101202)を今日の日付かどうか確認する必要があります。はいの場合、1を加えてメッセージボックスに表示する必要があります(はい、101203を表示する必要があります)。そうでない場合、現在の日付をとり、01で始まる必要があります(101301の場合、日付は2013年10月13日です)。 前の行からデータを取得できました。しかし、どうすれば日付でそれをチェックすべきですか? 助けてください!Vb.netの日付チェック

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 

答えて

1

あなたは'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に置き換えられており、今日は必要な形式で使用しています。

また、trという名前の変数を使用すると、その変数の用途を理解することが難しくなります。

+0

ありがとうございます!それは完璧に動作します! :) – user5538704

+0

あなたの歓迎:) –

関連する問題