Solved

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

Posted on 2003-11-18
17
418 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
  • 6
  • 6
  • 4
17 Comments
 
LVL 14

Assisted Solution

by:sudhakar_koundinya
sudhakar_koundinya earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
text height+textbox height and may be some extra stuff helps you to do your second task

reagrds
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
0
 
LVL 3

Expert Comment

by:ashoooo
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
You can store the identifier (assuming its a string) in the Tag.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:aanimesh
Comment Utility
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
Comment Utility
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
Comment Utility
You can split points between us anyway you like.  I'm glad I was of help.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
this is upto you friend, any thing is accepted by me :-)

0
 

Author Comment

by:aanimesh
Comment Utility
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
Comment Utility
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
Comment Utility
ok no problem :-)

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

Author Comment

by:aanimesh
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now