現在、Excel VBAを使用して図書館システムプロジェクトに取り組んでいます。期限切れの本をチェックし、期限切れの本を持っているユーザーに課せられる罰金を計算するモジュールが必要です。
これは私が持っているコードであり、明らかに機能していません。
Dim fine, count, count2 As Integer
Dim currentdate, borroweddate, difference As String
'this is the amount of fine imposed per day (50 cents)
fine = 1 / 2
'gets number of borrowing records
count = Sheets("borrowing records").Range("K1").Value
'count2 is just a counter for the cells
count2 = 2
'gets the current date
currentdate = Now()
While (count2 < count + 2)
If (Sheets("borrowing records").Cells(count2, 8).Value = "ON LOAN") Then
difference = currentdate - Sheets("borrowing records").Cells(count2, 4).Value
If (difference > 20) Then
'prints the overdue record
Sheets("display").Cells(count2, 1).Value = Sheets("borrowing records").Cells(count2, 1).Value
Sheets("display").Cells(count2, 2).Value = Sheets("borrowing records").Cells(count2, 2).Value
Sheets("display").Cells(count2, 3).Value = Sheets("borrowing records").Cells(count2, 3).Value
Sheets("display").Cells(count2, 4).Value = Sheets("borrowing records").Cells(count2, 4).Value
Sheets("display").Cells(count2, 5).Value = difference * fine
End If
Else
count2 = count2 + 1
End If
Wend
Sheets("display").Select
同様のコードを実行して差の値をテストしようとすると、小数点以下が非常に長い乱数が得られました。どうしてか分かりません。私が得た結果は、実際の日数の差にさえ近くありませんでした。たとえば、3月20日と3月1日の日の違いをテストすると、4.35648920486E32Eのようなものが得られます。そうです、結果に「E」という文字が含まれていました。
私の当初の意図は、コーディングがワークシート(「借用レコード」)を検索することでした。このワークシートには、プログラムが借用された本のレコードを保存します。
プログラムは、本の借用日と現在の日付を比較して、20日の制限が超えているかどうかを確認します。
その場合、日付の差に1日あたりの罰金の額(この場合は50セント)を掛けて罰金を計算します。次に、プログラムは、延滞した記録と課された罰金を別のワークシート(「表示」)に印刷する必要があります。
おそらく日付の形式かそのようなもののために、プログラムが機能しないことを私は知っています。しかし、どうやって解決すればいいのかわかりません。
私のプロジェクトは月曜日に予定されており、これを読んでいる誰かが私を助けてくれることを願っています。ありがとう!