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

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


wOxxOm 25-03-2008 15:51

probably Thing should be declared As Object too

bprice 25-03-2008 17:25

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

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:

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
End Sub

This is how I call it:

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

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!


Lev 27-03-2008 06:28


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:

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

Feidias 24-04-2008 00:15

1 Attachment(s)
Hi, I would like to change number of members in collection or array when i click on the spin button in my macro rotation with clone curves for CorelDRAW 12. I attached this macro to this Reply. I have 4 buttons now in this macro. When this macro starts two of them are disabled and enabled are after first click on the GO button. Before using this macro i recomend to change position of the rotationcenter of the selected curve on the location according you want to curve be rotated. Yes, curve must be selected before using this macro and one requierement or demand is needed when you use GO MIRRORED button - you need rotationcenter of the curve in the same x-axe position like right part of the curve is. After click button origin curve is still selected and trough this curve you can change every cloned curves when you change position of the nodes. But my spin button does not working and i would like to use this spin button for control number of the cloned curves. I would like to ask you if the COLLECTION or ARRAY is better for this example.

wOxxOm 24-04-2008 00:32

do it either way and see the difference through your own experience :-)

All times are GMT -5. The time now is 01:09.

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