Solved

parse string variable for tags and assign to multiple variables

Posted on 2006-06-08
3
169 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

8 Experts available now in Live!

Get 1:1 Help Now