Solved

Tracking the text in dynamically generated text box (also how to modify such boxes)

Posted on 2003-11-18
17
426 Views
Last Modified: 2010-05-01
Hi,

My objective is to display (say n) number of text messages. when user clicks on a message then i should be able to access the related information to that text.
the text messages and related info is stored in a 2 dimentional array and n (and text message array )will keep on changing in runtime.

My approach: I am creating n number of dynamic text objects and printing the messages in sequential order in those boxes. When n changes, i recreate all the text objects (with text coming from the array.)

i also capture mouse click on a text box. however now i need to know what is the index number of this test message in the array so as to access/display other related info.

NOW THE PROBLEM IS : that all the dynamically generated boxes have the same name (the name i give to the object that i include on the form). I cannot assign some ID (i.e. array index no) to each new box' name as it is read only property and so cannot identify the which array position the text belongs to.

I think that one workaround would be to use rich text; include all related info in the text but do not show it (change font color) and when user clicks on a box then read the text in the box, then seperate and display the related info. this is not the best way but if there is no other way then i will have to use it.

ANOTHER RELATED QUESTION: (or should i post is a new question)?
I want the text box height to adjust according to the content. Right now i am setting the height to a specific number. (while i was typing the question i realized that i might calculate the length of the text and then calculate the height to be set dynamically...will try that tomorrow) Is there a method to do it in VB.

Thanks a lot
Animesh
0
Comment
Question by:aanimesh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 4
17 Comments
 
LVL 14

Assisted Solution

by:sudhakar_koundinya
sudhakar_koundinya earned 200 total points
ID: 9776601
there are two ways to create the controls dynamically

i think you are creating them using load method

go through this URL http://www.vb-helper.com/howto_add_controls_scrolled.html

this will help your problem at maximum

instead of creating index for a control it treats controls some thing like text1,text2,text3 and so on

0
 
LVL 14

Assisted Solution

by:sudhakar_koundinya
sudhakar_koundinya earned 200 total points
ID: 9776643
Private Sub Command2_Click()
On Error Resume Next
Dim index As Integer

 Dim ctl As TextBox
Dim prev As TextBox


    m_NumControls = m_NumControls + 1
    Set ctl = Controls.Add("VB.TextBox", "Text" & Format$(m_NumControls), Form1)


    Set prev = Controls("Text" & Format$(m_NumControls - 1))
    ctl.Move prev.Left, _
        prev.Top + prev.Height + 30, _
        prev.Width, prev.Height
    ctl.Text = ctl.Name


    Form1.Move 0, 0, _
        ctl.Left + ctl.Width + 320, _
        ctl.Top + ctl.Height + 320


    ctl.Visible = True


End Sub
0
 
LVL 14

Assisted Solution

by:sudhakar_koundinya
sudhakar_koundinya earned 200 total points
ID: 9776647
text height+textbox height and may be some extra stuff helps you to do your second task

reagrds
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9776664
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9782428
Create a text box called txtDynamic with an index 0 on your form and make it invisible.

Use this code to dynamically create more text boxes on the fly.

  For i = 1 to arrayCount
    Load txtDynamic(i)
    txtDynamic(i).visible = True
    ...
  Next i

You can get the index number of hte text box on any event using the Index parameter passed to you. for example, on the click event...


Private Sub txtDynamic_Click(ByVal Index as Integer)
  ' the Index tells you the index of the text box
End Sub

Hope this helps
0
 

Author Comment

by:aanimesh
ID: 9784280
Hi Sudhakar,

I tried what you suggested. I can assign unique names to each textbox that appears on the form but here is a problem . In this case I cannot write a "text click code" for each of those blocks. (which i am doing now using  Private Sub Text0_Click(Index As Integer)  

my requirement is  to capture which textbox a user has clicked and also execute some code when he does that (this code needs to know the name of the text box in order to know what is displayed in that test box and present some related info ---which can be done using the technique u showed me but in which block do i write the code that will execute when a text box with such unique names is clicked.

am i making sense?
 let me know if it is possible?
0
 

Author Comment

by:aanimesh
ID: 9784284

Hi Ashooo.....

i am doing what you told but then i do not want the index of the control, i want the identifier that i will give when i assign the text to a textbox (as the index will keep on changing but the identifier that i give will not). Sudhakar has understood what i am doing.
0
 
LVL 3

Accepted Solution

by:
ashoooo earned 300 total points
ID: 9784531
You can store the identifier (assuming its a string) in the Tag.
0
 

Author Comment

by:aanimesh
ID: 9784646
hi ashoo...

let me try that....if that cab be done...then that wouuld be greaaat...
thanks a lot man..
will get back to you soon


animesh
0
 

Author Comment

by:aanimesh
ID: 9784683
hi ashoo...
thanks a lot boss..it worked....really appreciate it....
but can i give some points to sudhakar too...as he also had given an alternate way of doing what i wanted to do....you decide....

thanks a lot once again....
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9784765
You can split points between us anyway you like.  I'm glad I was of help.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9785001
this is upto you friend, any thing is accepted by me :-)

0
 

Author Comment

by:aanimesh
ID: 9785181
hi sudhakar,

i could not find an option to split points....
but don't worry i will give you another opportunity very soon :-)


all the best guys....thanks a lot once again,
animesh
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9785213
Thanks aani, but I think there is an option somewhere to split the points. If you want, you can ask the moderator to split the points for you.

Thanks again.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9785482
ok no problem :-)

why don't you ask moderators for help, if possible
0
 

Author Comment

by:aanimesh
ID: 9791973
thanks annieMod.

by the way guys i have another question regarding the same objective.
i am posting a question seperately ..if you guys can help that would be great , especially now that you understand what i am trying to do...

regards,
animesh
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MsgBox 4 75
Send outlook email from VBS Script 2 65
VBA - If Bookmark = "XXBOOKMARKXX" then 15 60
VB6 common control 6 sp6 object library not registerd 3 62
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question