Access a textbox inside a user control from module


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: Access a textbox inside a user control from module

  1. #1
    Join Date
    Nov 2008
    Posts
    13

    Unhappy 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)

  2. #2
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    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.

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    First off, Welcome to DevX

    Second, I already know the answer to this question, but I'll ask anyway....is the person that developed this usercontrol still around?

    I'm also curious as to what kind of Classic VB program is being viewed in a browser.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  4. #4
    Join Date
    Nov 2008
    Posts
    13
    Hey guys.
    Thanks for your comments.

    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....

    Thanks again. Appreciate it.

  5. #5
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    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

  6. #6
    Join Date
    Nov 2008
    Posts
    13

    Vb6

    Hi Ron,

    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.

  7. #7
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    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 06:59 PM.

  8. #8
    Join Date
    Nov 2008
    Posts
    13
    This makes perfect sense.
    If I had a form it'd makes things much easier.

    I do not have a form.
    I have a user control like 'MyControl' compiled to an ocx and used on a (on top of it all ) classic asp page.

    Take a look at MyControl modified project ...
    I have something like that ... and need to access text box from a module ....
    Attached Files Attached Files

  9. #9
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    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 06:59 PM.

Similar Threads

  1. Replies: 2
    Last Post: 08-08-2007, 12:18 AM
  2. Error Rendering Control for User Control
    By Magdalene in forum ASP.NET
    Replies: 0
    Last Post: 05-09-2006, 07:27 AM
  3. Replies: 1
    Last Post: 08-27-2002, 02:28 AM
  4. Replies: 1
    Last Post: 03-30-2002, 12:14 AM
  5. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 11:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center