Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 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 September 13th, 2007, 07:57 AM
Authorized User
 
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cannot reference text box added at run time

Hi,

I am using a function to add a number of text boxes (all named differently) to a form at run time (Code listed below).

This works fine, except that when I try and extract any of the values in the boxes boxes added later using a command button event click function I get a compile error "Method or data member not found".

Does anyone have any ideas about what I am doing wrong, or what I should be doing to make this work.

Thanks in advance for any help...

Code to add text box

Function createTextbox(tmpWhere As Form, tmpLeft As Integer, tmpTop As Integer, txtName As String)

    Dim txt As TextBox

    Set txt = Controls.Add("VB.textbox", txtName, tmpWhere)
    With txt

        .Move tmpLeft, tmpTop, 500, 200
        .Visible = True
        .BackColor = &H80000005
    End With
    Set txt = Nothing
End Function

Code to reference text box
Private Sub cmdAddLineItem_Click()
    MsgBox (frmOtherQuoteUtilities.txtQty1.Text)
End Sub

 
Old September 13th, 2007, 08:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. is the code to reference the textbox in the same form??

you can look for the control in the controls collection of the form.. maybe that's not the name of the control??

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 13th, 2007, 09:24 AM
Authorized User
 
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Yes,

Didn't think of that. I looped through the control collection and found the text boxes (using c.name (c is dimmed as control)). From there in the loop if the name matched then I can assign the text value to a variable and collect it that way.

I.E

Private Sub cmdAddLineItem_Click()
    Dim c As Control

    For Each c In Controls
        If TypeOf c Is TextBox Then
            If c.Name = "txtQty1" Then
                msgBox (c.Text)
                x = x + 1
            End If
        End If
    Next
End Sub

Thanks loads for your help Gonzalo!!!!

 
Old September 13th, 2007, 09:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

glad I help you...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 17th, 2007, 05:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

or you can access directly without the loop, using:

dim t as textBox
set t = controls("txtQty1")
msgbox t.text


"There are two ways to write error-free programs. Only the third one works."
Unknown
 
Old September 19th, 2007, 02:24 AM
Authorized User
 
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks marcostraf. Your way is a bit more efficient!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Dialog Box Hidden at Run Time? Ron Howerton Visual Studio 2005 4 September 21st, 2007 02:31 PM
Design-Time or Run-Time now ? ALGNET .NET Framework 2.0 1 July 31st, 2006 04:43 AM
Adding Text boxes on run time jmss66 VB How-To 1 March 31st, 2006 03:32 PM
How to clear all text box in a form at once time richie86 ASP.NET 1.0 and 1.1 Basics 1 October 31st, 2005 04:57 AM
record the time a text box is updated techsp Access 2 August 2nd, 2005 09:51 AM





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