Results 1 to 3 of 3

Thread: get all textbox values at once

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    12

    Arrow get all textbox values at once

    Is there any way of looping through every textbox in a form to get thier values.

    This is how i have done it in ASP....
    For Each objItem In Request.Form

    It will save me having to write out a string for every textbox....
    saveStr = saveStr & "email=" & email.text
    saveStr = saveStr & "firstname=" & firstname.text
    saveStr = saveStr & "lastname=" & lastname.text
    saveStr = saveStr & "comments=" & comments.text
    and so on for over 50 textboxes
    Last edited by gingernuutter; Aug 17th, 2001 at 08:08 AM.

  2. #2
    New Member
    Join Date
    Aug 2001
    Location
    New York, NY
    Posts
    6
    not sure if this is what you meant, but - you can always try control arrays.

    so if you had 5 text boxes, as txtBox(0), txtBox(1).... txtBox(4), you could do this:

    Dim saveStr as String
    Dim i as Integer

    For i = 0 to txtBox.Count - 1
    saveStr = saveStr & "comments=" and txtBox(i).Text
    Next

  3. #3
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    This should work.
    VB Code:
    1. Option Explicit
    2. Dim strText() As String
    3. Private Sub Command1_Click()
    4.    Dim ctl As Control
    5.    ReDim strText(0)
    6.    For Each ctl In Controls
    7.       If TypeOf ctl Is TextBox Then
    8.          ReDim Preserve strText(UBound(strText) + 1)
    9.          strText(UBound(strText)) = ctl.Text
    10.       End If
    11.    Next ctl
    12. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width