Solved

parse string variable for tags and assign to multiple variables

Posted on 2006-06-08
3
170 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
3 Comments
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
change vba from autofit to 13.5 width? 4 28
Saving history changes to sub form 4 36
clicking a shape in a frame array vb6 3 40
Macro Excel - Multiple If conditions 2 65
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now