Solved

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

Posted on 2003-11-18
17
424 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

832 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