Solved

Need to access object names in a web page that has charsactors that foxpro does not like

Posted on 2010-11-17
13
542 Views
Last Modified: 2012-05-10
Here is the situation, given that a web page has the following:
<input name="input-one"></input>
<input name="input|two"></input>

Open in new window


And I am accessing the page via createobject in foxpro:
o=CREATEOBJECT('internetexplorer.application')
o.Visible=.t.
o.navigate2('c:\inputs.html')

Open in new window


Is there a simple way I can access these web page input box names by using some sort of conversion, unicode or eval statement?

Foxpro does not like the "-" (minus) or "|" (pipe) charactor

I have a somewhat complex workaround in some situations, but these are really not desirable methods.

Thank you all again!

BC
0
Comment
Question by:busycoder
  • 4
  • 4
  • 4
  • +1
13 Comments
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34158718
Yes you can.

Check STRCONV(), COMPROP and SYS(3101)
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34158736
How about getting all the elements names and addressing them in an array?
0
 

Author Comment

by:busycoder
ID: 34158870
Thats what I was doing, I am looking for another way, can you give me any examples to get me started using the functions you mentioned to directly acces an object with a name like:

input|two (using the pipe char)

You are giving me hope here :)

BC

0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34160120
0
 

Author Comment

by:busycoder
ID: 34161040
I guess I have not gotten the issue across, I have a good understanding of how to populate forms with data from Foxpro in a web page or a web object in a form.

The problem I am having using my examples above is:

You can't do this in foxpro:

o=CREATEOBJECT('internetexplorer.application')
o.Visible=.t.
o.navigate2('c:\inputs.html')
o.document.body.all.input1.value=somevalue <<-- This will work
o.document.body.all.input-one.value=somevalue <<--This will fail
o.document.body.all.input|two.value=somevalue <<--As will this


Without using an array to reference the object, does anyone know of a way to do this on one line of code for example, using some kind of conversion function to access a named object that has a dash or a pipe character in it?

Thanks,

BC
0
 
LVL 2

Expert Comment

by:Gary2Seven
ID: 34161967
Can you post or attach the contents of inputs.html?


G2S
0
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

 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34162060
Why don't you use STRTRAN to rename the strings in the input.html to names that you can access.

cHTML = FILETOSTR("c:\input.html")
cHTML = STRTRAN(cHTML,"input-one","input1")
= STRTOFILE(cHTML,c:\input1.html")

you navigate to input1.html
0
 

Author Comment

by:busycoder
ID: 34165892
The examples are from a local page but the application will be pages stored on the web, I cannot have the names changed in the pages, which is why I am trying to find solutions to access these types of names. Below is how I am handling this now, I would like to know if there is a way to do something simpler, on one line of code, like you can when the object name does not contain a dash or pipe charactor in it.

x=""
o=1
the_length=Thisform.web1.Document.getElementsByTagName("input").Length

Do Whil At("input-one",Lower(x),1)=0 And o<the_length
	g='thisform.web1.document.getElementsByTagName("input").['+Alltrim(Str(o))+'].name'
	If Type('&g')="C"
		x=&g
	Endif
	o=o+1
Enddo
tt = Evaluate('thisform.web1.document.getElementsByTagName("input").['+Alltrim(Str(o-1))+']')
tt.value=some_value

Open in new window


Thanks again for helping me think about this!!!

BC
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 34168515
Think about adressing the elements just via their position in the array getElementsByTagName() returns. Foxpro cannot adress the names with forbidden chars, even javascript cannot perhaps, but you can adress the element via an object reference.

Bye, Olaf.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 34183620
I don't get what you want. You ARE setting the value in one line aren't you?

Of course you can also change your code a little to shorten it, and you see nowhere a name is used to adress a html tag, access is done via object reference tt and the inputtags object.

Bye, Olaf.

tt=.null.
x=""
o=1
inputtags = oIE.Document.getElementsByTagName("input")
the_length = inputtags.Length
? the_length

Do While o<=the_length
	tt = inputtags.item(o-1)
	If Type('tt.name')="C"
	    x=tt.name
	    ? x
	    ? tt.value
	Endif
	o=o+1
Enddo

Open in new window

0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 34183627
Just change one line to fit your situation:

inputtags = oIE.Document.getElementsByTagName("input")
should be like in your code:
inputtags = thisform.web1.document.getElementsByTagName("input")

Bye, Olaf.
0
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 500 total points
ID: 34183919
Or are actually just searching for getElementsByName?

tt =  thisform.web1.document.getElementsByName("input|two")

if a tag with that name exists tt should be the reference you need, if not tt.item(0) should be it.

Bye, Olaf.
0
 

Author Closing Comment

by:busycoder
ID: 34184400
That did it, thanks again all, thanks for keeping after it Olaf, now I can do it on one line of code a LOT cleaner.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

22 Experts available now in Live!

Get 1:1 Help Now