VB.net hour (now ()) is not working

I am trying to create a vb.net program that will be interrupted at a certain time selected by the user. To do this, I need to check every minute every minute if the hour and minute that the user entered correspond to the current time (if there is no better way to do this). I tried to use

Dim CurrentHour As Integer = Hour(Now()) 

But the program gives me an error message:

An expression is not an array or method and cannot have a list of arguments

I'm going to use Loop Loop to check, but of course, to see if these two match, I need the current hours and minutes

+4
source share
4 answers

Your code is correct. What you need to look at us is:

  Dim Now As Date Dim CurrentHour = Hour(Now()) 

What causes error BC30471: the expression is not an array or method and cannot have a list of arguments.

Now you see the problem, perhaps the Now variable hides the Now function. The compiler is now confused, it does not understand why parentheses are present. And rightly complains that Now is not an array, not a method. This is no longer the case.

Besides renaming a variable, you can also solve it by providing a more complete name:

  Dim CurrentHour = Hour(DateAndTime.Now()) 

Although this is becoming rather obscure, using DateTime.Now instead is a .NET path, not Basic.

+2
source

You should use the native DateTime properties:

 Dim CurrentHour As Integer = Now().Hour 

If you want to use the Hour method, you may need to fully qualify it as:

 Microsoft.VisualBasic.Hour(Now()) 

because Hour is most likely a property or method elsewhere in your application.

+1
source

Dim Inputtime As DateTime if Inputtime = Date.Now.Hour Then MsgBox("Success!") End If

I would not use a do loop, as it will consume all the memory for the program. I would go with a timer that ticks once every minute. and run this routine.

+1
source

"Task Scheduler" is an option. I rather use Marshal.FinalReleaseComObject , then loop at the bottom of the code, and GC.Collect needs to be called again after GC.WaitForPendingFinalizers()

0
source

Source: https://habr.com/ru/post/1493551/


All Articles