Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Creating VB objects programmatically

Posted on 2004-11-25
7
Medium Priority
?
529 Views
Last Modified: 2013-12-25
hi,

i am trying to create a program that opens a text file and designs a form according to this text file.

the problem i am having is that i cant create a vb object (checkbox, textbox etc) programmatically..

I have tryed the following:

Dim asdf As TextBox

with asdf.
      .alignment = "XXX"
     ' and so on
end with
but that doesnt work.. i am not quite sure how to do this..

Any help will be appreciated
Thanks
0
Comment
Question by:apoorvamehta
  • 4
  • 3
7 Comments
 
LVL 54

Accepted Solution

by:
Ryan Chong earned 600 total points
ID: 12675314
try like:

Dim asdf As TextBox

Private Sub Form_Load()
    Set asdf = Me.Controls.Add("VB.TextBox", "asdf")
   
    With asdf
        .Alignment = 1
        .Visible = True
        .Left = 0
        .Top = 20
        .Text = "hello world"
    End With
   
    MsgBox asdf.Name
End Sub

0
 

Author Comment

by:apoorvamehta
ID: 12675401
Thanks!!

did u know why the text is on the right sided of the textbox..

when i make a check box.. i get the chekbox on the left of the text..

0
 

Author Comment

by:apoorvamehta
ID: 12675412
i meant.. i get the checkbox on the right of the text unlike the normal checkbox
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:apoorvamehta
ID: 12675420
i am sorry.. really stupid question..
(the alignment should be 1..)

thanks again
have a good day
Apoorva
0
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 12675429
>>when i make a check box.. i get the chekbox on the left of the text..
That's what a typical checkbox is it. If you want to make the text appears to the left of checkbox, you can:

1. empty the Caption property of that checkbox
2. and then add a label on the left of that checkbox, and type the text whatever you wanted.

Anyway, thks for the pts, and glad could make help here 8-) cheers
0
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 12675449
It's ok, apoorvamehta. 8-) Have a nice day too.
0
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 12675543
Damn.. my mistake...  if you want to have a checkbox with text align on left, you can try like:

Dim WithEvents asdf As CheckBox

Private Sub Form_Load()
    Set asdf = Me.Controls.Add("VB.CheckBox", "text2")
   
    With asdf
        .Alignment = 1
        .Visible = True
        .Left = 0
        .Top = 20
        .Caption = "hello world"
    End With
   
    MsgBox asdf.Name
End Sub

Private Sub asdf_Click()
    MsgBox "you click me!"
End Sub

Sorry if i misunderstand your above question ;-)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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 …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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
Course of the Month21 days, 1 hour left to enroll

810 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