Wrox Programmer Forums
|
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 July 13th, 2004, 10:09 AM
Registered User
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating Textboxes


I would like to create a text box, without having one appear on my form. Is this possible? Or if I do that does the textbox already have to be on my form. How?

I know I can declare an varaible as a text box, Dim txtTest as Textbox, but if I try to assign a value to the text box I get an error. i.e.:

Dim txtTest as Textbox

txtTest.Text = "Test"

Thank you,
Jennifer
 
Old July 13th, 2004, 10:16 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

Hi

You could add the textbox somewhere on your form and then use *Text1.Visible = False* in your form load sub. This way it wont appear when the program is running but you could still assign text to it.

Regards
Marnus
 
Old July 13th, 2004, 10:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe you can use the Visible property of the textbox?

Either in the properties window or as code: txtTest.visible=False
 
Old July 13th, 2004, 10:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm a little curious, though. Why do you want a textbox if it shouldn't be seen? Can't you use a variable instead to hold your values?
 
Old July 13th, 2004, 01:12 PM
Registered User
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default


I am trying to dynamically create text boxes. The amount of text boxes will be based on how many records are in a database table. I am not going to know how many text boxes to create until I query the database.

My main goal is to dynamically create an array of text boxes.

Any ideas?

Thank you,
J



 
Old July 13th, 2004, 02:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, ive tried this approach, but not sure it's the right way to do it:

I copied/pasted a textbox on a form to make it a controlarray (dont know how else to do this), then deleted the new textbox. The remaining textboxname is now Text1(0).

I added a commandbutton with this code:

Dim x As Long
Dim y As Long
y = 100

For x = 1 To 3
    Load Text1(x)
    Text1(x).Top = y * x * 10
    Text1(x).Left = 10
    Text1(x).Width = 1500
    Text1(x).Height = 100
    Text1(x).Visible = True
Next x

You can address the new textboxes with their x value, e.g. Text1(2).Text. But I imagine it could be difficult to keep track of textboxnames and the values they should hold, but it can be done.

Hope this may give you an idea to solve your task!
 
Old July 14th, 2004, 11:16 PM
Authorized User
 
Join Date: Jul 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

... or simply you could put a textbox in your form and set its index property to 0.

I'm just curious why you have to populate your form with n number of textboxes. what if you got thousands of rows? don't you want to use a grid?

 
Old July 14th, 2004, 11:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Jennifer,

Take a look at this article.
I used its theory to create a quite complex venn diagram by dynamically adding controls.
It now works well after a lot of trial and error

http://www.thescarms.com/vbasic/DynamCtls.asp





======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
Two TextBoxes [email protected] ASP.NET 1.0 and 1.1 Basics 5 April 1st, 2006 06:32 AM
creating dynamic textboxes djricochet ASP.NET 2.0 Professional 0 March 14th, 2006 12:04 PM
calculate 2 textboxes chriskhan2000 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 December 1st, 2005 09:11 PM
Repeating textboxes Robert_Hill BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 September 2nd, 2004 10:42 AM
Currency value in textboxes mahulda ASP.NET 1.0 and 1.1 Basics 1 April 6th, 2004 02:10 PM





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