473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how can i make textbox(n).text, how can i control n to write something in there

2
Guys! Please help me! For example, i have a programme. There are 4 textboxes and 1 button. So i write in the first textbox a number 2, 3 or 4 and then in one of the textbox programme writes something (doesn't matter what):

Expand|Select|Wrap|Line Numbers
  1. Dim x As Integer
  2.  
  3. Sub Button1.Click(....)
  4. x = Val(TextBox1.Text)
  5. TextBox(x).Text = "blahblahblah"
  6. End Sub
I hope i wrote it clear and you understand what i want - i want to control with this "x" in which textbox will i write something, but obviously my code isn't working. Please help!
Oct 25 '14 #1
3 1344
iam_clint
1,208 Expert 1GB
Assuming you named the controls and know what they are you can simply use the name of the textbox control to modify the value.

If I assume you don't have the names of the textboxes because they are dynamic you can iterate the controls.
Expand|Select|Wrap|Line Numbers
  1.  For Each ctrl as control In form1.Controls
  2.    If (ctrl.GetType() Is GetType(TextBox)) Then
  3.       ctrl.text="blahblahblah"
  4.    end if
  5.  Next
  6.  
But thirdly if the controls are dynamic you can store references to them in an array when you create them and then modify them that way.
Oct 26 '14 #2
SizOff
2
Sorry, i didn't get your message fully (because i don't know english perfectly, yeah), but as I understood you're trying to say that i need to use "If". I tried to do it, and, well, it works, but i use to many code on that:

Expand|Select|Wrap|Line Numbers
  1. x = Val(TextBox1.Text)
  2. if x = 2 Then TextBox2.Text = "blahblahblah"
  3. if x = 3 Then TextBox3.Text = "blahblahblah"
  4. if x = 4 Then TextBox4.Text = "blahblahblah"
So I don't like this version and want just to make like "TextBox(x).Text" without "If" or "For", but I don't know how to do it.

Or maybe I just understood you wrong.
Oct 27 '14 #3
iam_clint
1,208 Expert 1GB
the for loop I posted is probably going to be you're easiest solution. either that or create an array containing references to the textboxes you want.

I mean if you really wanted TextBox(i).text
Expand|Select|Wrap|Line Numbers
  1.     Dim TextBox As New List(Of TextBox)
  2.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  3.         For Each ctrl As Control In Me.Controls
  4.             If (ctrl.GetType() Is GetType(TextBox)) Then
  5.                 TextBox.Add(ctrl)
  6.             End If
  7.         Next
  8.         TextBox(1).Text = "test"
  9.     End Sub
  10.  
Oct 28 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Eric B | last post by:
I am looking for a text control (or API) that can emulate the behavior of CodeWrite where you can move the cursor in any direction on a blank text area and begin typing (so you are not confined to...
8
by: none | last post by:
Hi, I wrote a program for work that processed and formatted some collected text data in a Tkinter based GUI display. I've found that as my data files get longer (a few thousand lines), there...
0
by: NancyASAP | last post by:
In case anyone hasn't seen this problem, just sharing the info.... I created a dotnet 1.1 page with a literal control. I used a streamreader to open a text file to fill the control. I filled the...
2
by: Gwin | last post by:
I am programming a client service dbase in access 2000 for a non-profit health clinic. I want to create a navigation menu that can show varying numbers of command buttons with varying captions,...
2
by: Mark Allison | last post by:
Hi, On my Windows Form I have a text control and a button. The text control is single-line and I want the user to be able to type something in it, but when they hit Enter, I want this to click...
4
by: David Davis | last post by:
Woll2Woll has a product for Delphi called Infopower which has a rtf control with a built-in word processor. Does anyone know of a third party control that has the same capabilities. I don't have...
2
by: tlyczko | last post by:
Hello, I'm experimenting with Stephen Lebans' Rich Text Control for doing RTF data entry into a memo field. I imported the table, form, toobar, and modules from the A2k version into an A2k3...
1
by: (PeteCresswell) | last post by:
Got a text control that where .Locked = True. I have the text blue and underlined to simulate a clickable link on a web page. If the user clicks on that field, I open up a window that shows the...
1
by: ozzy66 | last post by:
Hiho NG, I've created a tool (tray application) like "keytext" or "shortcut" that is a little tool where you can store text components which you can call from any running app. Such a stored text...
1
by: Randy Shore | last post by:
I have run into a problem with the new rich text control in Access 2007. It seems that you can only choose from 6 preset font sizes when entering or editing text. The sizes are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.