Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2007, 11:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default VBScript to list Textboxes on page

Sorry to post this here, but there still doesn't seem to be a VBSCRIPT forum, or if there is, I couldn't find it. This seems like a simple quesation, yet I cannot find any information anywhere on how to do this.

I have a dynamically created form containing one or more text boxes and textarea fields. I would like to obtain the value from each in a loop without directly referencing the field by name. What is the equivalent of this in VBSCRIPT:

for each form field
    if this is a text box or a text area field
        reference the value of the field
    end if
next
 
Old October 4th, 2007, 03:18 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I believe you need to get each element in the form’s .Controls collection.
For each one, check it’s control type to exclude labels, buttons, et al.
Given the type, use the appropriate property (.Text? .Value?) to reference the contents.
 
Old October 4th, 2007, 03:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

I aready surmised as much and I know I need VALUE. I was rather hoping for some functioning code indicating exactly what the method for TYPE is in VBScript as I can find no examples on-line anywhere.
 
Old October 4th, 2007, 05:11 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Well, I would have to do the same thing you could do. Create a simple form without much on it, loop through the controls collection, and use the TypeName() function to list the type of everything. It should then become apparent what’s what.
 
Old October 5th, 2007, 07:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

TypeName appears to tell me whether a variable or value is a string, integer, null, and so forth. I am looking for a way to tell whether an HTML form field is a text box, text area, radio button, check box, etc.
 
Old October 5th, 2007, 08:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

For enquiring minds and anybody else trying to figure out how to do this, here is what I was looking for:

dim i

For i = 0 to myform.Elements.length-1
   if instr(myform.Elements(i).type,"text") then
    do whatever
   end if
Next

The reference to the .LENGTH property wasn't especially intuitive to an old VBer like myself. I expected a .COUNT property, and indeed several sites suggested as much, but IE returns "Object doesn't support this property or method: 'myform.Elements.count'". .LENGTH was just a lucky guess.

I am, incidentally, soliciting for a hit fund for whomever on the VBScript committee thought that .LENGTH made more sense than .COUNT when dealing with the number of elements in an array! :(

And the .TYPE property is the key to identifying the kind of field currently under examination. It returns "text" for text boxes and "textarea" for text areas.

I knew it would be easy to do once I figured out the right properties to use!





Similar Threads
Thread Thread Starter Forum Replies Last Post
textboxes or list boxes with multiple fore color svharishtech Pro VB 6 5 April 20th, 2007 05:04 PM
populating textboxes using list/Menu rylemer Javascript 0 November 23rd, 2005 10:05 PM
Optimization of ASP page with VBScript anandham VBScript 0 April 18th, 2005 05:03 AM
Using quotes in VBSCript and an asp page dragonfields Classic ASP Basics 2 July 31st, 2003 10:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.