Thread View: borland.public.cppbuilder.internet.web
2 messages
2 total messages
Started by Al C
Thu, 01 Dec 2005 17:05
VB to C++ Help
Author: Al C
Date: Thu, 01 Dec 2005 17:05
Date: Thu, 01 Dec 2005 17:05
35 lines
2031 bytes
2031 bytes
I've never had to try this before and hope someone can help. I need to read
the contents of a shopping cart by reading their hidden html forms. I was
given the following example in VB. Could someone please help translate?
Set mDoc = WebBrowser1.Document
Dim title As String
Dim cart_count As Integer
Dim output As String
title = mDoc.frames(1).Document.Title
If (title = "Order Review") Then
cart_count = mDoc.frames(1).Document.frmheader.tot_forms.Value
If (cart_count > 0) Then
For i = 1 To cart_count
Select Case i
Case 1:
output = "Cart Details:" + vbCrLf
output = output +
mDoc.frames(1).Document.frmcarthd_1.carthdr.Value + vbCrLf
output = output +
mDoc.frames(1).Document.frmcartdet_1.cartpart_1.Value + vbCrLf
MsgBox output
Case 2:
output = "Cart Details:" + vbCrLf
output = output +
mDoc.frames(1).Document.frmcarthd_2.carthdr.Value + vbCrLf
output = output +
mDoc.frames(1).Document.frmcartdet_2.cartpart_1.Value + vbCrLf
MsgBox output
End Select
Next
End If
Thanks,
Al
Re: VB to C++ Help
Author: Remy Lebeau (TeamB)
Date: Thu, 01 Dec 2005 20:11
Date: Thu, 01 Dec 2005 20:11
113 lines
4466 bytes
4466 bytes
"Al C" <alanc@jancointernational.com> wrote in message
news:438f2c55$1@newsgroups.borland.com...
> I've never had to try this before and hope someone can help. I need
> to read the contents of a shopping cart by reading their hidden html
> forms. I was given the following example in VB. Could someone
> please help translate?
For example (untested):
#include <utilcls.h>
WideString __fastcall GetFormElementValue(IHTMLElementCollection *Coll,
const WideString &FormName, const WideString &ElementName)
{
TComInterface<IDispatch> disp;
OLECHECK(Coll->item(TVariant(FormName), TVariant(0), &disp));
TComInterface<IHTMLFormElement> form = disp;
disp.Unbind();
OLECHECK(form->item(TVariant(ElementName), TVariant(0), &disp));
TComInterface<IHTMLInputElement> element = disp;
WideString result;
OLECHECK(element->get_value(&result));
return result;
}
TComInterface<IHTMLDocument2> mDoc = (IDispatch*)
CppWebBrowser1->Document;
TComInterface<IHTMLFramesCollection2> frames;
OLECHECK(mDoc->get_frames(&frames));
TVariant index = 1;
TVariant item;
OLECHECK(frames->item(&index, &item));
TComInterface<IHTMLWindow2> framewindow = V_DISPATCH(&item);
TComInterface<IHTMLDocument2> framedoc;
OLECHECK(framewindow->get_document(&framedoc));
WideString title;
OLECHECK(framedoc->get_title(&title));
if( title == L"Order Review" )
{
TComInterface<IHTMLElementCollection> all;
OLECHECK(framedoc->get_all(&all));
// you did not say what element type tot_forms actually is,
// so this is only a guess as to how to get its value...
WideString temp = GetFormElementValue(all, "frmheader",
"tot_forms");
long cart_count = StrToIntDef(temp, 0);
if( cart_count > 0 )
{
WideString output;
for(long i = 1; i <= cart_count; ++i)
{
switch( i )
{
case 1:
{
output = "Cart Details:\r\n";
// you did not say what element types carthdr and
cartpart_1
// actually are, so this is only a guess as to how
to get their values...
output += (GetFormElementValue(all, "frmcarthd_1",
"carthdr") + "\r\n");
output += (GetFormElementValue(all, "frmcartdet_1",
"cartpart_1") + "\r\n");
ShowMessage(output);
break;
}
case 2:
{
output = "Cart Details:\r\n";
// you did not say what element types carthdr and
cartpart_1
// actually are, so this is only a guess as to how
to get their values...
output += (GetFormElementValue(all, "frmcarthd_2",
"carthdr") + "\r\n");
output += (GetFormElementValue(all, "frmcartdet_2",
"cartpart_1") + "\r\n");
ShowMessage(output);
break;
}
}
}
}
}
To help address the unknown areas, it would be helpful if you would show the
actual HTML.
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads