Solved

Need help with a VBScript to evaluate text field values

Posted on 2012-03-15
8
927 Views
Last Modified: 2012-03-27
My existing script checks 2 text fields, MEDI_INPATIENT_FILE and MEDI_MEDICAL_FILE to see if they have a value of N/A and compares this value to its corresponding integer fields, MEDI_MEDICAL_COUNT and MEDI_INPATIENT_COUNT.  This validation is working to assure that if the text value is not N/A, that the integer field value is greater than zero (via the CheckCDate function).

What I need to do now is check and see if BOTH the text fields to assure that AT LEAST ONE of them has a value <> to N/A or Null.

Now, I need a Function to take care of this.  The reason I need a Function is that I will have other text fields to check (like this Medical example) that have scores of text fields like MEDI_MEDICAL_FILE..  In this small example, the “Medical” data type only has 2 such text fields.  Others could have up to 50.  Also, since I’m already going to the database in the existing script to obtain the text field value, I don’t want to do it a second time.

The objective is to go through each text field and assure that at least one has a value that is not N/A or null.

Dim currentRecord
Dim dApproval, dCdate
Dim strIssueID, strFileName
Dim nFileCount, nFileNameValue, nFileNameSum
strFileDefault = "n/a"
If Ext.ShellHasProp( "item" ) Then
      Set currentRecord = Shell.item
            Else
      Set currentRecord = Nothing
End If
Call GetFieldValue( currentRecord, "ISSUEID", strIssueID)
Call Ext.LogInfoMsg( "This is the value of the current record or Shell.Item: " & strIssueID)
Call GetFieldValue( currentRecord, "MEDI_MEDICAL_FILE", strFileName)
Call GetFieldValue( currentRecord, "MEDI_MEDICAL_COUNT", nFileCount)
Call CheckFileCount(strFileName, nFileCount)
Call intFileNameCounter(strFileName)
Call GetFieldValue( currentRecord, "MEDI_INPATIENT_FILE", strFileName)
Call GetFieldValue( currentRecord, "MEDI_INPATIENT_COUNT", nFileCount)
Call GetFieldValue( currentRecord, "MEDI_MEDICAL_CDATE", dCdate)
Call GetFieldValue( currentRecord, "MEDICAL_LF_APPROVAL_DATE", dApproval)
Call CheckCDate(dCdate, dApproval)
Call GetFieldValue( currentRecord, "MEDI_INPATIENT_CDATE", dCdate)
Call GetFieldValue( currentRecord, "MEDICAL_LF_APPROVAL_DATE", dApproval)
Call CheckCDate(dCdate, dApproval)
0
Comment
Question by:impala6
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:Chris Raisin
Comment Utility
This is trickier than I first thought.

Stand By....

Chris (Australia)
0
 
LVL 15

Assisted Solution

by:markdmac
markdmac earned 100 total points
Comment Utility
Here is a simple example to do what you ask

test1a=""
test1b="something"
test2a=""
test2b=""
test3a="something"
test3b="something"
test4a="something"
test4b=""

WScript.Echo CheckIsNull (test1a,test1b)
WScript.Echo CheckIsNull (test2a,test2b)
WScript.Echo CheckIsNull (test3a,test3b)
WScript.Echo CheckIsNull (test4a,test4b)

Function CheckIsNull(f1,f2)
      If Len(f1) > 0 Or Len(f2) > 0 Then
            CheckIsNull = "Not Null"
      Else
            CheckIsNull = "Null"
      End If
End Function
0
 
LVL 13

Expert Comment

by:Chris Raisin
Comment Utility
I don't think that will work.

Null is not the same as "n/a" or empty.

Stand By....
0
 
LVL 13

Accepted Solution

by:
Chris Raisin earned 400 total points
Comment Utility
How about this (I assume "Null" means empty)

You could (example only) use it thus:

         Field3.text = iif( NotNullOrNA(Field1.text, Field2.text),"Has Value","NoValue")
         
If "Null" will actually be stated in the field then the code would change slightly.
(Please advise if that is so)

Cheers
Chris
   

Option Explicit
Public Function NotNullOrNA(strField11 As String, strField2 As String) As Boolean
  'Function checks to see whether at least ONE of the two
  'text fields is not empty and has a value <> "n/a"
  '(By default it returns "False")

  strField1 = Trim(LCase(strField1))
  strField2 = Trim(LCase(strField2))
  If Len(strField1) > 0 Then
    If strField1 <> "n/a" Then
      NotNullOrNA = True
      Exit Function    'no need to test any further
    End If
  End If
  If Len(strField2) > 0 Then
      If strField2 <> "n/a" Then
        NotNullOrNA = True  
        'no need to exit function here since there is no further testing  
      End If
    End If
  End If
End Function

Open in new window

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 15

Expert Comment

by:markdmac
Comment Utility
My code should work for you. Please test and report back.  Also feel free to supply a sample source file for further help.
0
 

Author Comment

by:impala6
Comment Utility
That's intriguing, Mark - but in most cases I'm checking 30-40 text fields each with a unique field name so the Function would be huge.  Is there a way to get this to a few reusable lines of code so that I can have one variable representing the "file name" field?

I've attached a script that is doing what I need it to do, but I'm hoping there is a way to scale it down a bit.
08-HRA.vb
0
 
LVL 15

Expert Comment

by:markdmac
Comment Utility
Why would the function be any larger than the same I provided?  Pass it the names of any two variables and it will tell you if at least one has a value as you stated you were trying to do.
0
 
LVL 13

Expert Comment

by:Chris Raisin
Comment Utility
Inpala6,

Have you tried my code? It returns false if the value at least one has a value that is not "n/a" is there or  Empty (as requested).

Chris
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now