Solved

parse string variable for tags and assign to multiple variables

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

696 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