OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Collections?? (http://forum.oberonplace.com/showthread.php?t=5183)

bprice 25-03-2008 14:57

Collections??
 
Forgive my ignorance, as VB is something I only mess around with occasionally...

If I do something like:

Dim Stuff as New Collection
Stuff.Add (Object1)
Stuff.Add (Object2)

For Each Thing in Stuff
Call Myfunction(Thing)
Next Thing

And Then a function that has:

Function MyFunction(ByRef ItemName As Object) As Object
ItemName.Text = "balh blah blah"
End Function

What am I doing wrong... I try something like this... and it gets to the "Call Myfunction(Thing) and says an object is required... I thought "thing" was an object (on each next it changes through the list of objects) because is added it to the stuff collection... object1, object 2 etc.

What am I doing wrong?

Thanks in Advance

B

wOxxOm 25-03-2008 15:51

probably Thing should be declared As Object too

bprice 25-03-2008 17:25

nope...
 
i dim thing as object and still get "object required"

now whats odd is at work, i got that error any time i tried it, at home on my home computer... if i dim thing as object I get "object required", however... if I don't Dim thing as object and simply use the original example I first posted earlier today... i get the error "Compile Error: Can't find project or library"

I'm confused!

wOxxOm 25-03-2008 17:27

then post all the related code

bprice 26-03-2008 05:45

Gms
 
1 Attachment(s)
Here is a GMS file with a form that shows what I am trying to do... there are probably a million different ways to do what I need... but with my very limited knowledge of VB... this is what I came up with....

Since I posted this... I messed around with a few things, and have noticed that "MyObject" doesn't cantain the object name like i want it to, but it's in fact containing the default text in each textbox...

so why is it it's looking at the text in the object and trying to send it to my function rather then the object name itself??? I need it to send the object names I added in the collection to my function....

wOxxOm 26-03-2008 07:19

ah, that's because the controls have a 'default' property which is fed upon ambiguous access (no explicit indication of object type). By explicit I mean: set ObjVar=TextBox1 :-)

anyway here's a trick I use for the task you need, I think it's pretty handy:
Code:

Private Sub EnableControls (ByVal bEnable As Boolean, ParamArray ctls())
 
  Dim var As Variant, bg&, fg&, txt$
  if bEnable then bg=vbWindowBackground: fg=vbWindowText: txt="" _
              else bg=vbGrayText: fg=vb3DDKShadow: txt="N/A"
  For Each var In ctls
      var.Enabled = bEnable
      var.BackColor = bg
      var.ForeColor = fg
      var.Text = txt
  Next
End Sub

This is how I call it:
Code:

EnableControls true, TextBox1, TextBox2, TextBox3
......
EnableControls false, TextBox1, TextBox2, TextBox3

P.S. of course there are a few other ways :-)

bprice 26-03-2008 07:47

hhhmmm...
 
Thanks Os,
I can honestly tell you I don't understand that example and how it works... completely... some of it I get... other parts not so much... but I'll definately try it and learn what's it's doing... because this will be needed a few times in the script I'm making!

Thank you for the help!

B

Lev 27-03-2008 06:28

Code:

Private Sub CommandButton1_Click()
  Dim MyObject As Object
  Dim Boxes As New Collection
  Boxes.Add (Controls("TextBox1").Object)
  Boxes.Add (Controls("TextBox2").Object)
  Boxes.Add (Controls("TextBox3").Object)
  Boxes.Add (Controls("TextBox4").Object)
  Boxes.Add (Controls("TextBox5").Object)
  If ComboBox1.Text = "Disable Boxes" Then
    For Each MyObject In Boxes
      Call BoxDisable(MyObject)
    Next MyObject
  ElseIf ComboBox1.Text = "Enable Boxes" Then
    For Each MyObject In Boxes
      Call BoxEnable(MyObject)
    Next MyObject
  End If
End Sub


Feidias 23-04-2008 07:53

anothe rquestion about collection
 
Hi I would like to know how to change number of members of the collection. Is there any option how to set how many members will be in the collection?

wOxxOm 23-04-2008 14:28

a collection is dynamic by nature, no need to set the maximum amount of items.

However arrays need an upper limit, you may use dynamic arrays:
Code:

dim arrStr() as string, L as Long
redim arrStr(0 to 20) ' 21 items
............
L=200
............
redim preserve arrStr(0 to L)
'201 items, preserving old contents - which works for one-dimensional arrays only



All times are GMT -5. The time now is 22:48.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com