Question:
Having a problem getting visual basic code to display results?
?
2011-02-03 05:38:23 UTC
I'm new to VB, so I'm sure this is an easy answer but I'm having trouble. I have the following code:

Sub Age()
Dim PATIENT_VIEW_DOB As Date
PATIENT_VIEW_DOB = #4/22/1983#
Dim CLAIM_VIEW_CLAIM_FROM As Date
CLAIM_VIEW_CLAIM_FROM = #12/31/2010#
Dim Age As Integer
Age = DateDiff(DateInterval.Year, PATIENT_VIEW_DOB, CLAIM_VIEW_CLAIM_FROM)
MsgBox (Age)

I want a Message Box to display the results of the formula in the Age variable. I run the compiler and it checks out, however when I run the routine I get "Run-time error '424': Object Required.

Hitting the 'Debug' option highlights the line
Age = DateDiff(DateInterval.Year, PATIENT_VIEW_DOB, CLAIM_VIEW_CLAIM_FROM)

Could somebody help me out? Thanks!
Three answers:
Will H
2011-02-03 07:39:33 UTC
I do not know why Age = DateDiff(DateInterval.Year, PATIENT_VIEW_DOB, CLAIM_VIEW_CLAIM_FROM) does not work. However, this works





Sub Age()

Dim PATIENT_VIEW_DOB As Date

Dim CLAIM_VIEW_CLAIM_FROM As Date

PATIENT_VIEW_DOB = #4/22/1983#

CLAIM_VIEW_CLAIM_FROM = #12/31/2010#



MsgBox DateDiff("yyyy", PATIENT_VIEW_DOB, CLAIM_VIEW_CLAIM_FROM)



End Sub
?
2016-12-11 10:09:15 UTC
Is it seen difficulty-loose 6.0 or 2005? you additionally can do no longer forget having all the variables declared in a module particularly of a variety. (even in spite of the undeniable fact that it is non-mandatory). in the beginning up "valid is" a VB's worth representing a available state of an merchandise and can desire to no longer be used as a variable. you will decide to decide for on yet another be conscious which incorporate "authorized" or "get entry to granted" in spite of the undeniable fact that... all the variables are declared on the severe of the class Form1, so it is mindless to redeclare those variables 2 situations indoors the comparable code. Delete the lines Dim password as String, and the Dave and Poppy indoors the unique Sub BtnGo_Click attitude. question : are all the variables of numerical innovations form? Even the password and Username?
Gardner
2011-02-03 05:57:14 UTC
At first glance the code looks good to me. Is the code written exactly as you have it listed here or did you change something before you posted it?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...