GPWiki.org
GPWiki.org
It is currently Sat May 25, 2013 4:07 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue Oct 18, 2011 1:01 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2217
Location: England
Suppose I want to use a FileListBox, but I don't have a form to place the control onto.

I want to create the object dynamically.

So I need a function like CreateAnObject that I can use like this:

Code:
CreateAnObject "FileListBox", "MyFLB"
MyFLB.Path  = "C:\"
For i = 0 to MyFLB.ListCount - 1
  DoSomethingToFile "C:\" & MyFLB.List(i)
Next


How?

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
PostPosted: Tue Oct 18, 2011 2:07 pm 
King Code Monkey
User avatar

Joined: Wed Sep 01, 2004 3:05 pm
Posts: 11182
Location: Abingdon, MD
This?

Dim ctlTest As Control

Set ctlTest = Form1.Controls.Add("VB.FileListBox", "flbTest", Form1)

ctlTest.Visible = True

ctlTest.Top = 42

_________________
Bored? Head on over to my blog and see what I'm up to.

Microsoft XNA MVP


Top
 Profile  
 
PostPosted: Tue Oct 18, 2011 4:14 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2217
Location: England
That works if one has a Form1 to place the control onto, but my question is asking about creating a FileListBox object in a project without a form.

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
PostPosted: Tue Oct 18, 2011 4:41 pm 
King Code Monkey
User avatar

Joined: Wed Sep 01, 2004 3:05 pm
Posts: 11182
Location: Abingdon, MD
Is the problem you're trying to solve just getting the file names in a folder? If so, why not just use the Dir function?

_________________
Bored? Head on over to my blog and see what I'm up to.

Microsoft XNA MVP


Top
 Profile  
 
PostPosted: Tue Oct 18, 2011 4:57 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
Have you tried this?

Code:
FileListBox MyFLB = new FileListBox
MyFLB.Path  = "C:\"
For i = 0 to MyFLB.ListCount - 1
  DoSomethingToFile "C:\" & MyFLB.List(i)
Next


Haven't tested it but just creating the file list box object doesn't require a form to work.

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
PostPosted: Tue Oct 18, 2011 5:48 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2217
Location: England
Code:
FileListBox MyFLB = new FileListBox
MyFLB.Path  = "C:\"
For i = 0 to MyFLB.ListCount - 1
  DoSomethingToFile "C:\" & MyFLB.List(i)
Next


That doesn't work unfortunately. If FileListBox were a class, it might have worked... Controls must be something else.

In Machiara's code example, the Set keyword is for assigning a reference to a control. It's a keyword I've never used before, and I've never took the time to understand it's usage.

This is one thing in VB I dislike. It feels like dynamic control creation was an afterthought, clumsily bolted on to the language.

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
PostPosted: Tue Oct 18, 2011 6:37 pm 
King Code Monkey
User avatar

Joined: Wed Sep 01, 2004 3:05 pm
Posts: 11182
Location: Abingdon, MD
Jasmine wrote:
It feels like dynamic control creation was an afterthought, clumsily bolted on to the language.

Probably because it's not something that happened often in that time. I can count the number of times I needed to do it on my thumbs probably. :)

_________________
Bored? Head on over to my blog and see what I'm up to.

Microsoft XNA MVP


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group