Link to home
Start Free TrialLog in
Avatar of vbMarkO
vbMarkO

asked on

How would I ignore a Variable if it returns Null

RIchTextBox

I am reading rtb1.Lines

   Street addresses are in the rtb1.lines

For Each nLine in rtb1.Lines
   If nLine.Contains("_") Then
       sString = nLine.Substring(0, nLine.IndexOf(":- " & txtStreet.Text ' <--- heresd the problem
   End If
Next


txtStreet.Text some times the addresses ... well I the variables that would contain the address dont always have the right address ... when that hap[pens variable returns NULL and it stops
at sString because of it ...

I hope I am explaining this ok ... here is what I am wanting to know ...

If a variable that is supposed to return a lat & lon has either  nothing or something otther than lat & lon how could I ignore anything but lat & lon

Avatar of strickdd
strickdd
Flag of United States of America image

IF String.IsNullOrEmpty(txtStreet.Text) Then
   'whatever
Else
  'something else
End If
Avatar of Esspy
Esspy

what version of windows are your running ?

What do you mean by 777 ? This is linux rights..

Right click on the file and go under security, what are the users there ?

If you're logged as a user which is not there, add it.
That went in the wrong post... delete please
I don't really understand the question.

What is the error message that you get?
I don't think the txtSTreet.Text can bel NULL, but the IndexOf method could return -1, and that is probably the problem.

Please post the complete code snippet, because the one in your original message has missing paratheses etc ...  It's difficult to understand like this.
Avatar of vbMarkO

ASKER

Sorry about the missing "))" was at work and typed it out in a hurry

I realized now what its doing and I also figured out how to better ask what I was needing

Here is the code I am using and I figured out what I needed ... it was an exception handler ... its not crashing but its not complete ....

It keeps me from crashing but its not letting me find the text that does exist ... meaning as soon as it finds an error it Exits Sub ... I know I wrote it to do that ....

But what I need is it to find the error take the address that doesnt exist and put it in lstAdds
but if the address exist find it without error
DOES THIS MAKE SENSE?
Maybe the code will explain it better

Using the code example below if User inputs in txtStreet TextBox  lets say 7300 Riverside Dr

then the code should place it in lstAdds because it doesnt exist or not found

but if they input 7700 Riverside Dr .... it does exist but at the moment as soon as it finds 7500 Riverside Dr it used to throw an exception which the handler is taking care of but its not continuing to search al the lines
I hope this is making sense guys ...
Sometimes the addresses just aren't in the DB or they have Garbage RANDOM crazy stuff and unpredictable so it causes an exception

I simply want unfounds in lstAdds
Founds I will add to an XML file   HOPE THIS HELPS







Dim sAdds As New List(Of String)
        sAdds.Add("Disturbance..."">7500 Riverside Dr")
        sAdds.Add("Disturbance..."">7700 Riverside Dr")
        sAdds.Add("Armed Robbery..."">6100 S Lewis Ave")
        sAdds.Add("Shots Fired..."">blahblah@#$7300 Riverside Dr") '/// Sometimes random garbage is added to the address ///
        sAdds.Add("Person Down..."">7100 S Yale Ave")
        sAdds.Add("EOD..."">8100 S Yale Ave")  '/// This should be 8145 S Yale Ave ///


        rtb1.Lines = sAdds.ToArray()
        Dim str As String = String.Empty
        For Each line In rtb1.Lines
            If line.Contains("Disturbance") Then
                Try
                    str = line.Substring(0, line.IndexOf(""">" & txtStreet.Text))
                    rtb1.Clear()
                    rtb1.Text = str
                Catch ex As Exception
                    lstAdds.Items.Add(txtStreet.Text)
                    Me.Text = txtStreet.Text & " Was not found"
                    Exit Sub
                End Try

            End If


        Next
         Me.Text = txtStreet.Text & " Found" '/// Will be replaced and saved to XML later //////

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of joriszwaenepoel
joriszwaenepoel
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vbMarkO

ASKER

Thank you!!!

   That was educational and exactly what I was needing and great advice on top of it all.

   I am choosing your as solution  might I ask a final question about your code you gave

Nothing went in between Try and Catch

  What is its purpose then?  (Try I mean)?

That was a mistake.
I used "copy and paste" and forgot to delete the Try, Catch and End Try statements.  They should not be there.
Since the possible (previous) error conditions is now tested in the If-statement, the previous catch-code is now in the else-block.
Avatar of vbMarkO

ASKER

Did the trick

NOTE If you use this remove the Try out

read the post you will see its not needed