Solved

parse string variable for tags and assign to multiple variables

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to incorporate an error traping routing to existing code in VB6 11 53
vbModal 12 73
pop out of webbrowser1 control vba6 5 50
Win 10 Automation Error with .doCmd in Access 2 85
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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

739 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