Select Case

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All:

I have some code that reads the names of XmlNodes and processes information
accordingly. I just recived a new xml file that will now have a dynamic list
of nodes with names like CC1, CC2, ... CC9. I don't know from file to file
how many CC?'s there will be.

I currently have a Select statement that processes the XmlNode information
based on the XmlNode's name. I am writing to ask if it is possible to code
in a Select statement something similar to the "Like 'CC*'" in SQL. I don't
think that this is possible, but I thought that I would ask.

I am trying to avoid a nasty series of If statements.

If anyone has a suggestion, I would appreciate your sharing them.

TIA,
 
Joe said:
Hello All:

I have some code that reads the names of XmlNodes and processes information
accordingly. I just recived a new xml file that will now have a dynamic list
of nodes with names like CC1, CC2, ... CC9. I don't know from file to file
how many CC?'s there will be.

I currently have a Select statement that processes the XmlNode information
based on the XmlNode's name. I am writing to ask if it is possible to code
in a Select statement something similar to the "Like 'CC*'" in SQL. I don't
think that this is possible, but I thought that I would ask.

I am trying to avoid a nasty series of If statements.

If anyone has a suggestion, I would appreciate your sharing them.

TIA,

Couldn't you do something like:

Select Case XYZ
case ...
case ...
case else
if NodeName.SubString(0,2) = "CC" then

end if
end select

It would be helpful to know what you are doing in the case statement to
know if there is a better way to help you.

Chris
 
Unless you want to put an If statement in your Case Else branch,
you might consider something like

Private Sub TestSelect(ByVal a As String)
Select Case a
Case "cc00" To "cc99"
Debug.WriteLine("ok:" & a)

Case Else
Debug.WriteLine("not ok: " & a)

End Select
End Sub

If this is called with

TestSelect("cb")
TestSelect("cc00")
TestSelect("cd")
TestSelect("cc0a")

the result will be

not ok: cb
ok:cc00
not ok: cd
ok:cc0a

That may or may not be acceptable to you.

You can also write something like

Case Is >= "cc"

but I don't think you can write

Case Is >= "cc" And <= "cc99"

but that is okay - that is what "Case ... To ..." is for.

I think the ...To... condition is usable if you do not
have any other nodes named "cc...".

You will still want to validate the node name after the
....To... condition has been satisfied.

/JB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top