Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

parse string variable for tags and assign to multiple variables

Posted on 2006-06-08
3
Medium Priority
?
179 Views
Last Modified: 2010-04-30
I need help creating the code to parse a variable that contains the source of a webpage into different parts. Below is an excerpt from the variable, I need to find the name field and capture the contents which is "test order" from the below into two fields firstname and lastname. I need to loop through this variable and get the contents for the name, address, city, state etc... and fill those into textbox's on my form.

<TR>
<TD align=right><B>Name:</B> </TD>
<TD align=left>test order</TD></TR>
<TR>
<TD align=right><B>Address:</B> </TD>
<TD align=left>this is a test</TD></TR>
<TR>
<TD align=right><B>Unit:</B> </TD>
<TD align=left></TD></TR>
<TR>
<TD align=right><B>City:</B> </TD>
<TD align=left>Palm Bay</TD></TR>
<TR>
<TD align=right><B>State:</B> </TD>
<TD align=left>FL</TD></TR>
<TR>
<TD align=right><B>Zip:</B> </TD>
<TD align=left>32908</TD></TR>
<TR>
<TD align=right><B>Phone:</B> </TD>
<TD align=left>3212427663</TD></TR>
0
Comment
Question by:Dalexan
[X]
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
3 Comments
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 500 total points
ID: 16865673

i think you can figure out the rest?

here is some code that strips the html and gives you the name, the address end so on

read the comments to see where you can find which text



Private Sub Command1_Click()
Const LeftPart As String = "<TD align=left>", RightPart As String = "</TD></TR>"
Dim str As String, strSplit() As String, n As Long
str = Text1.Text 'your html here, i used Text1.text for the html
'i copied the above html in this one

   strSplit = Split(str, vbCrLf)
   str = vbNullChar
   For n = LBound(strSplit) To UBound(strSplit)
      If InStr(strSplit(n), "<TD align=right><B>Name:</B> </TD>") > 0 Then
         str = Replace$(strSplit(n + 1), LeftPart, "")
         str = Replace$(str, RightPart, "")
         'you now have the name in str
      ElseIf InStr(strSplit(n), "<TD align=right><B>Address:</B> </TD>") > 0 Then
         str = Replace$(strSplit(n + 1), LeftPart, "")
         str = Replace$(str, RightPart, "")
         'you now have the address in str
      ElseIf InStr(strSplit(n), "<TD align=right><B>Unit:</B> </TD>") > 0 Then
         str = Replace$(strSplit(n + 1), LeftPart, "")
         str = Replace$(str, RightPart, "")
         'you now have the Unit in str
      ElseIf InStr(strSplit(n), "<TD align=right><B>City:</B> </TD>") > 0 Then
         str = Replace$(strSplit(n + 1), LeftPart, "")
         str = Replace$(str, RightPart, "")
         'you now have the City in str
      ElseIf InStr(strSplit(n), "<TD align=right><B>State:</B> </TD>") > 0 Then
         str = Replace$(strSplit(n + 1), LeftPart, "")
         str = Replace$(str, RightPart, "")
         'you now have the State in str
      ElseIf InStr(strSplit(n), "<TD align=right><B>Zip:</B> </TD>") > 0 Then
         str = Replace$(strSplit(n + 1), LeftPart, "")
         str = Replace$(str, RightPart, "")
         'you now have the Zip in str
      ElseIf InStr(strSplit(n), "<TD align=right><B>Phone:</B> </TD>") > 0 Then
         str = Replace$(strSplit(n + 1), LeftPart, "")
         str = Replace$(str, RightPart, "")
         'you now have the Phone in str
      End If
   Next
End Sub
0
 
LVL 13

Expert Comment

by:iHadi
ID: 16867070
0
 

Author Comment

by:Dalexan
ID: 16869799
I will be testing this today, thanks, will award points later today.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 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