Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

easy!! loading a control

Posted on 1999-06-30
16
Medium Priority
?
238 Views
Last Modified: 2013-12-25
Is there any way of loading a control at run time....or putting some piece of code in an application saying...
"load this control if it exists"
Thanks
0
Comment
Question by:vbkann
[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
  • 4
  • 3
  • 3
  • +5
16 Comments
 
LVL 2

Expert Comment

by:mannen
ID: 1494923
To load a control at runtime, you have to have an array of controls, like: Text1(0), Text1(1), Text1(2) and so on...

I don't understand the "load this control if if exists", what do you mean exists? The control or the program, if it is the program, you have to use subclassing, if not, which type of control is it?

- Vidar Braut Haarr
  AmigoSoft Productions
  folk@popmail.com
0
 
LVL 2

Expert Comment

by:mannen
ID: 1494924
I'm sorry, that was meant as a comment, not an answer.
Though, if you will accept is as an answer, that would be nice.

- Vidar Braut Haarr
  AmigoSoft Productions
  folk@popmail.com
0
 
LVL 1

Author Comment

by:vbkann
ID: 1494925
What i want to do is load a control to a form that isnt part of a control array...a control that i havent added on at design time.

Because i am using an outlook express .ocx...not every computer has outlook express installed..so if they dont have outlook installed, my program wont run because if performs an error on startup saying that it cant load that control because it is not there.
So i want to somehow say in code, load this control...if it exists.
If you understand what im saying...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:db_tiger
ID: 1494926
I Think you cannnot load a control on a form, if you don't use an array of controls as mannen explained.

What you could probably  do, is to write an Activex.Exe with a form, that is not visible - this active.exe should own the .ocx-control and it should have a fine ErrorHandling for the case, that the server cannot load because the ocx does not exist on the computer where your programm runs.

So, if the .ocx does not exist, you receive an error in your main application, because the activeX-server was not able to instantiate himself correctly or the call to instantiate the server failed - this error you can catch in your main programm.

If the .ocx exists you can use it within the activeX.exe, but not within your main form.
I think my comment is somehow unclear, but your question is NOT easy.

domib

0
 
LVL 1

Author Comment

by:vbkann
ID: 1494927
hmmmm i think you know what i want...but i dont have a clue how to do it
0
 
LVL 15

Expert Comment

by:ameba
ID: 1494928
' paste this code to EMPTY form, VB6 only!
Option Explicit
' If you are adding an ActiveX control at run-time that is
' not referenced in your project, you need to declare it
' as VBControlExtender.
Dim WithEvents ctlDynamic As VBControlExtender
Dim WithEvents ctlText As VB.TextBox
Dim WithEvents ctlCommand As VB.CommandButton

Private Sub ctlCommand_Click()
  ctlText.Text = "You Clicked the Command button"
End Sub

Private Sub ctlDynamic_ObjectEvent(Info As EventInfo)
' test for the click event of the TreeView
  If Info.Name = "Click" Then
    ctlText.Text = "You clicked " _
     & ctlDynamic.object.selecteditem.Text
  End If
End Sub

Private Sub Form_Load()
  Dim i As Integer
  ' Add the license for the treeview to the license collection.
  ' If the license is already in the collection you will get
  ' the run-time error number 732.
  Licenses.Add "MSComctlLib.TreeCtrl"
  ' Dynamically add a TreeView control to the form.
  ' If you want the control to be added to a different
  ' container such as a Frame or PictureBox, you use the third
  ' parameter of the Controls.Add to specify the container.
  Set ctlDynamic = Controls.Add("MSComctlLib.TreeCtrl", _
    "myctl", Form1)
  ' set the location and size of the control.
  ctlDynamic.Move 1, 1, 2500, 3500
  ' Add some nodes to the control.
  For i = 1 To 10
    ctlDynamic.object.nodes.Add Key:="Test" & Str(i), Text:="Test" _
      & Str(i)
    ctlDynamic.object.nodes.Add Relative:="Test" & Str(i), _
      Relationship:=4, Text:="TestChild" & Str(i)
  Next i
  ' Make the control visible.
  ctlDynamic.Visible = True
  ' add a textbox
  Set ctlText = Controls.Add("VB.TextBox", "ctlText1", Form1)
  ' Set the location and size of the textbox
  ctlText.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
    1, 2500, 100
  ' Change the backcolor.
  ctlText.BackColor = vbYellow
  ' Make it visible
  ctlText.Visible = True
  ' Add a CommandButton.
  Set ctlCommand = Controls.Add("VB.CommandButton", _
    "ctlCommand1", Form1)
  ' Set the location and size of the CommandButton.
  ctlCommand.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
    ctlText.Height + 50, 1500, 500
  ' Set the caption
  ctlCommand.Caption = "Click Me"
  ' Make it visible
  ctlCommand.Visible = True
End Sub

0
 
LVL 1

Expert Comment

by:db_tiger
ID: 1494929
Respect ameba, if that works, I will take the code although.
0
 
LVL 2

Expert Comment

by:mannen
ID: 1494930
I agree with db_tiger! You cant load a control without an array...

- Vidar Braut Haarr
  AmigoSoft Productions
  folk@popmail.com
0
 
LVL 3

Expert Comment

by:kfrick
ID: 1494931
Why not just load the control with the .Enabled and .Visible properties set to "False". Then, if ya need 'em, set those properties to "True", and there they are! Seems to take a lot less code......

-kf
0
 
LVL 2

Expert Comment

by:mannen
ID: 1494932
kfrick, I think you should read the question before answering...

- Vidar Braut Haarr
  AmigoSoft Productions
  folk@popmail.com
0
 
LVL 1

Author Comment

by:vbkann
ID: 1494933
ameba...do you know anyway of me doing this in visual basic 5 sp3? as i dont have vb6.

0
 
LVL 15

Expert Comment

by:ameba
ID: 1494934
Create Exception Handler
It raises an error so that it can
be trapped with an ON ERROR statement
in the procedure that caused the exception.

You will be able to continue with your program. This should also work for missing OCX-es.

This has been described in VBPJ May 99, but I don't have that article at a moment.
http://www.vbpj.com/ (requires premier membership at http://www.windx.com/)
0
 
LVL 1

Expert Comment

by:boodabelly
ID: 1494935
Ameba,
I never got the exception handler from the may VBPJ to work.  I dled the source and it still does not work.  Did you have to change the code to get it to work
0
 
LVL 15

Expert Comment

by:ameba
ID: 1494936
I didn't try - I just saw this.
0
 

Accepted Solution

by:
jackjoker earned 40 total points
ID: 1494937
Try this.
Let's say you're using TextBoxes.

Make 2 textboxes, visible or not, as you like.
Edit their names to "Text(0)" and "Text(1)"

On the click event of a button, type the following.
  Dim i As Integer
  i = i + 1

  Load Text(i)
  Text(i).Top = 25
  Text(i).Left = 25

  And so on...

 
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6821735
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects that and the expert will now receive these points, all verified.

Please click on your Member Profile, select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.
 
Thanks,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

704 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