Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 13th, 2007, 07:57 AM
Authorized User
 
Join Date: Dec 2003
Location: JHB, , South Africa.
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

Reply With Quote
  #2 (permalink)  
Old September 13th, 2007, 08:05 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
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
================================================== =========
Reply With Quote
  #3 (permalink)  
Old September 13th, 2007, 09:24 AM
Authorized User
 
Join Date: Dec 2003
Location: JHB, , South Africa.
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!!!!

Reply With Quote
  #4 (permalink)  
Old September 13th, 2007, 09:31 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
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
================================================== =========
Reply With Quote
  #5 (permalink)  
Old September 17th, 2007, 05:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
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
Reply With Quote
  #6 (permalink)  
Old September 19th, 2007, 02:24 AM
Authorized User
 
Join Date: Dec 2003
Location: JHB, , South Africa.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks marcostraf. Your way is a bit more efficient!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:34 PM.


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