Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing for data

Status
Not open for further replies.

spyderco

Programmer
Jan 23, 2005
107
US
This was asked yesterday and it works without "error" but it's not really doing what expected.

I need to append data to a variable IF and ONLY if that variable contains data. If the testing variable is empty, it should move on to the next test.

The following adds lines that test false (variables that contain nothing are still having their data concat. to the _results ).

Any idea how to clean this up?

Code:
        Dim _meta_start As String = "<meta name='"
        Dim _meta_end As String = "'>"

        ' begin writing our results page
        If (Not _author Is Nothing) Then
            _results = _results & _meta_start & "results'" & " content='" & _author & _meta_end & vbCrLf
        End If
        If (Not _keywords Is Nothing) Then
            _results = _results & _meta_start & "keywords'" & " content='" & _keywords & _meta_end & vbCrLf
        End If
        If (Not _description Is Nothing) Then
            _results = _results & _meta_start & "description'" & " content='" & _description & _meta_end & vbCrLf
        End If
        If (Not _copyright Is Nothing) Then
            _results = _results & _meta_start & "copyright'" & " content='" & _copyright & _meta_end & vbCrLf
        End If
        If (Not _abstract Is Nothing) Then
            _results = _results & _meta_start & "abstract" & " content='" & _abstract & _meta_end & vbCrLf
        End If
        If (Not _distributor Is Nothing) Then
            _results = _results & _meta_start & "distributor'" & " content='" & _distributor & _meta_end & vbCrLf
        End If
        If (Not _robots Is Nothing) Then
            _results = _results & _meta_start & "robots'" & " content='" & _robots & _meta_end & vbCrLf
        End If
        If (Not _rating Is Nothing) Then
            _results = _results & _meta_start & "rating'" & " content='" & _rating & _meta_end & vbCrLf
        End If
        If (Not _distribution Is Nothing) Then
            _results = _results & _meta_start & "distribution'" & " content='" & _distribution & _meta_end & vbCrLf
        End If
        If (Not _language Is Nothing) Then
            _results = _results & _meta_start & "language'" & " content='" & _language & _meta_end & vbCrLf
        End If
        Results.Text = _results
 
what are the types of your variables? Also, if the values are retrieved from a database, you can also try:

Code:
if not isDBNull(_author) then
'process
end if


 
All variables are just Strings and it's not from a DB, this is just from fields.Text-ish input.

Thanks.
 
Code:
if _author <> String.Empty then
'process
end if

or

Code:
if _author.trim <> "" then
'process
end if


it's all i can think of, hope it helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top