Access a textbox inside a user control from module
This is what I have.
ActiveX project with a user control containing 2 buttons and a text box.
There are also 2 modules ..... dealing with a nasty third party dll that captures DTMF tones (phone key presses).
Somehow I got it to work (I'm not even a beginner when it comes to ActiveX)
I can see the control in a browser and capture tones ...
A Sub from a module contains a number that I want to append to the textbox inside a control....
How the heck do I access that textbox inside a control from code inside a module?
(Please bear in mind that I know next to nothing about ActiveX, why and how they work)
Check the code for the user control. It may already have a property that lets you have access to the textbox.
There would be one or two property subs that would give you access to the textbox.
To get the value there would be a Property Get, to Set the value there would be a Property Let.
Search the code for the name of the textbox and see if it is found within a Property Get or Property Let routine. If not you could add them.
Lemme explain a bit better ...
Back in the day there was a windows app that hooked into a sound card using a 3rd party dll and record whatever came in.
So, I grabbed the windows app code and created ActiveX control from that code.
The 3rd party dll is not the control itself ... it just sits in system32 dir and is being called by one of the modules.
I removed form and replaced it with a UserControl that had same look and click handlers (contains only 2 buttons and a text box :-) ). I have no idea how it all works, so I had about 5 seconds to decide whether to use a form or control. Since it needs to be web based I picked activeX control .... kinda made sense.
I played around with making it an ActiveX dll and so on ... but then I got those messages along the line 'no entry point'. Knowing it'll take me time (I do not have) to figure that one out I opted for a user control.
So, I have complete control over control design.
Let's say control name is devX and I create a property Sub setResult.
How do I call that Sub from a module?
Scope in ActiveX control projects seems kinda weird ....
(Don't kill me) For now I have a timer on the UserControl that fires every 0.5 seconds and grabs a value of a variable from a module ....
Could barely sleep.... hate timers .... especially inside web apps ... on top of that inside a ActiveX control I barely have time understand... that on top of it all calls a 3rd party dll written in assembly and C....
Ok I created a very simple user control, added two buttons and a textbox.
I named the textbox control simply 'textbox'
Next I created two property routines for Get and Let and simply called them value:
Code:
'retreive the textbox text
Public Property Get value() As String
value = textbox.text
End Property
'set the textbox text
Public Property Let value(text As String)
textbox.text = text
End Property
Next I added my new control to my form and called it myCtl
In my forms Load Event I set myCtl's value property to the text I wanted to start with in my user control's textbox; when the form is loaded.
Code:
Private Sub Form_Load()
myCtl.value = "Some Text To Display"
End Sub
Next I added a button to my form so I could get any text from myCtl's textbox and display it in a message box:
Code:
Private Sub cmdShowText_Click()
'show the text from my user controls textbox
MsgBox "Text: " & myCtl.value
End Sub
Thanks for your help.
By looking at your code it seems like this is a web user control
The control I'm building is an ActiveX control built in VB6 and compiled into an ocx.
I wish I could do this using 'regular' user control, but the 3rd party dll does not seem to contain code that can be referenced so I'm stuck with using VB6 and ActiveX.
No the code above was used in an ActiveX control.
I have attached both the ActiveX Control Project (MyCtrl.vbp)
And the Test Project(Project1.vbp)
This is very basic and simple, just enough to show how I used the code above.
In the control the buttons just set the textbox to a short text message.
In the test project the Form1 load event sets text into the controls textbox
The show button retreives the current text in the control and shows it in a message box
Run the Test Project
The test project first sets the text of the usercontrol in the Form Load Event
Press the Show Button and see the message box that retreives this value
Push one of the buttons of the control and it's text changes then press Show
Again the messagebox retreives the current value of the usercontrols textbox
Now Type in something into the user control and press show
Again the messagebox retreives the current value of the usercontrols textbox
Last edited by Ron Weller; 02-11-2009 at 07:59 PM.
Well I don't do a lot of ActiveX for web pages, let alone ASP,
but I did manage to add it to an html page and got it to work
It's basically the same as what the original Form1 did.
I didn't fully register this to work on a website. I just did enough
to get it to work locally in my browser (IE6).
I used Visual Studio to edit my html file, so that I could tell it where the
control (the ocx file) was located at.
I wrote the html first, stole the classid from the form1.frm file in the
original project. Then right-clicked and selected edit with visual studio.
Once in visual studio I right-clicked and selected customize from the
Activex section of the toolbox window and then browsed to the file and
clicked ok which added it to the project.
Next I simply clicked to the source tab where the control showed up on its
own so I clicked back to design and the control showed up there also.
I saved all, exited out, and opend it in my browser.
You will probably have to do something similar to get IE to recognize the
control. But I am sure there are better html editors that will let you do this
just as easily as visual studio. I just used what was handy.
Here is the new example:
Last edited by Ron Weller; 02-11-2009 at 07:59 PM.