Need help with a VBScript to evaluate text field values

Posted on 2012-03-15
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
      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)
Question by:impala6
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 13

Expert Comment

by:Chris Raisin
ID: 37727787
This is trickier than I first thought.

Stand By....

Chris (Australia)
LVL 15

Assisted Solution

markdmac earned 100 total points
ID: 37729532
Here is a simple example to do what you ask


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"
            CheckIsNull = "Null"
      End If
End Function
LVL 13

Expert Comment

by:Chris Raisin
ID: 37734781
I don't think that will work.

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

Stand By....
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

LVL 13

Accepted Solution

Chris Raisin earned 400 total points
ID: 37734802
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)


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

LVL 15

Expert Comment

ID: 37734882
My code should work for you. Please test and report back.  Also feel free to supply a sample source file for further help.

Author Comment

ID: 37742924
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.
LVL 15

Expert Comment

ID: 37744954
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.
LVL 13

Expert Comment

by:Chris Raisin
ID: 37745575

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).


Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 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