• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 993
  • Last Modified:

Need help with a VBScript to evaluate text field values

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
impala6
Asked:
impala6
  • 4
  • 3
2 Solutions
 
Chris Raisin(Retired Analyst/Programmer)Commented:
This is trickier than I first thought.

Stand By....

Chris (Australia)
0
 
markdmacCommented:
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
 
Chris Raisin(Retired Analyst/Programmer)Commented:
I don't think that will work.

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

Stand By....
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Chris Raisin(Retired Analyst/Programmer)Commented:
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
 
markdmacCommented:
My code should work for you. Please test and report back.  Also feel free to supply a sample source file for further help.
0
 
impala6Author Commented:
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
 
markdmacCommented:
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
 
Chris Raisin(Retired Analyst/Programmer)Commented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now