New Objects

wd40bomber7
12-30-2007, 07:26 PM
Ok a (long) while ago I posted this exact same thing, with this exact same question. However I didn't follow up, and didn't explain what I wanted very well. Now I hope to amend my ways.

When I say 'object' I mean like a text box, a line, a frame, etc. The sort of things you can place on the form. Specifically I'm interested in making more lines in realtime. When you design the form you can choose what goes where, but I need to make more lines/textboxes/shapes in realtime.

If you need more information just ask me. This time I will follow through.

Edit, I've been experiencing an error. I don't want to start a new thread, so I'll post it here to.
The error:
In this code it points to Nar = L2P(Star) with the error "Only user-defined types defined in public modules can be coerced to or from a variant or passed to late-bound functions" I can't understand why I'm getting this.

Code Inside form:

Private Sub Command2_Click()
Dim Star As Location
Dim Star2 As Location
Dim Nar As Point
Dim Nar2 As Point
Star.X = Val(XX1.Text)
Star.Y = Val(XY1.Text)
Star.Z = Val(XZ1.Text)
Star2.X = Val(XX2.Text)
Star2.Y = Val(XY2.Text)
Star2.Z = Val(XZ2.Text)
Nar = L2P(Star)
Nar2 = L2P(Star2)
Line1.X1 = Nar.X
Line1.Y1 = Nar.Y
Line1.X2 = Nar2.X
Line1.Y2 = Nar2.Y
End Sub

Code inside module:

Public Type Point
X As Long
Y As Long
End Type
Public Type Location
X As Long
Y As Long
Z As Long
End Type
Public Function L2P(Gar As Location) As Point
Dim First As Location
Dim Second As Location
Dim Third As Point
'Time for orthographic projection!
'Step 1
First.X = Gar.X
First.Y = (Gar.Y * Cos(CamSpin.X)) + (Gar.Z * Sin(CamSpin.X))
First.Z = (Gar.Z * Cos(CamSpin.X)) - (Gar.Y * Sin(CamSpin.X))
'Step 2
Second.X = (First.X * Cos(CamSpin.Y)) - (First.Z * Sin(CamSpin.Y))
Second.Y = First.Y
Second.Z = (First.Z * Cos(CamSpin.Y)) + (First.X * Sin(CamSpin.Y))
'Step 3
Third.X = (Second.X * Cos(CamSpin.Z)) + (Second.Y * Sin(CamSpin.Z))
Third.Y = (Second.Y * Cos(CamSpin.Z)) - (Second.X * Sin(CamSpin.Z))

L2P = Third 'Send back this value
End Function


Edit: Updated the code to my most recent version

Robert Collins
12-30-2007, 08:46 PM
First thing is I don't see any return type for your function L2P. Could that be a problem?

wd40bomber7
12-30-2007, 08:49 PM
L2P = Third 'Send back this value That is how you return values in VB right? I'm setting the function to my return value.

Robert Collins
12-30-2007, 08:56 PM
I think it should be...

Public Function L2P(Gar As Location) As return_type

wd40bomber7
12-30-2007, 09:01 PM
Wow, that fixed that error. Now I have a new one! It won't let me use the variable CamSpin. It is declared at the top of the form like so:
Dim CamSpin As Location
I declared it at the top of the form because I'll probably have to modify it in realtime.

*Fixed/Erased XYZ problem*

(No ones answered my first question still)

the master
12-30-2007, 11:27 PM
(No ones answered my first question still)

Is that the bit about creating new objects? Set the index property of a line to 0. If that line is called line1 then you can load more like so


load line1(1)
load line1(2)


Remember that by default they are invisible

DougT
12-30-2007, 11:27 PM
You can create Control Arrays at design time and then add elements to them at run time.

For example, assume you've got Text1 on your Form and its Index property = 0, then

Load Text1(1)
Text1(1).Left = Text1(0).Left + Text1(0).Width
Text1(1).Visible = True

will create a new element and locate it immediately to the right of the existing element.

wd40bomber7
12-31-2007, 11:40 AM
It can only be done during run-time. Can't it be done in realtime? I made something small to test it, so when I pressed a button it made a new line. It says that it loaded the object, but I can't see it. Oh, I needed to set it to be visible. Strange, I would have thought it an exact copy of my first object in my array.

Final Problem
Public Function L2P(Gar As Location) As Point
Dim First As Location
Dim Second As Location
Dim Third As Point
CamSpin.X = 1
CamSpin.Y = 0
CamSpin.Z = 0
'Time for orthographic projection!
'Step 1
First.X = Gar.X
First.Y = (Gar.Y * Cos(CamSpin.X)) + (Gar.Z * Sin(CamSpin.X))
First.Z = (Gar.Z * Cos(CamSpin.X)) - (Gar.Y * Sin(CamSpin.X))
'Step 2
Second.X = (First.X * Cos(CamSpin.Y)) - (First.Z * Sin(CamSpin.Y))
Second.Y = First.Y
Second.Z = (First.Z * Cos(CamSpin.Y)) + (First.X * Sin(CamSpin.Y))
'Step 3
Third.X = (Second.X * Cos(CamSpin.Z)) + (Second.Y * Sin(CamSpin.Z))
Third.Y = (Second.Y * Cos(CamSpin.Z)) - (Second.X * Sin(CamSpin.Z))

L2P = Third 'Send back this value
End Function It won't let me put this in the form because it says I'm not allowed to pass types around. But I need it in the form or I can't modify CamSpin in realtime. I had to move CamSpin there because it won't allow me to access it from the form!

Grr... Is there anyway to reclassify my form as a public module, because its making me mad....

Robert Collins
12-31-2007, 11:56 AM
Exactly what is the difference between run-time and real-time?

wd40bomber7
12-31-2007, 01:05 PM
I consider run-time when your bringing the program up/when its loading. I consider real-time = anytime.

Robert Collins
12-31-2007, 01:18 PM
Oh. I guess then run-time = real-time in my book. However, I think way back somewhere the term real-time was used to indicate something going on at any given real time, like the software programs that control the air planes or software that controlled/monitored guided missles, and thing like that.


EDIT

BTW, are you aware that you misspelled Maybe

wd40bomber7
12-31-2007, 01:41 PM
Actually yes, I'm aware I misspelled maybe. I just haven't gotten around to fixing it.

Yes thats what I had in mind when I said realtime. A game doesn't just update the screen when you run it. It updates the screen in real-time. (Most likely every few milliseconds)

Let me just repeat my current question for people who don't want to read the whole thread to find out. It won't let me put this (See above post) in the form because it says I'm not allowed to pass types around. But I need it in the form or I can't modify CamSpin in realtime. I had to move CamSpin there because it won't allow me to access it from the form!

Grr... Is there anyway to reclassify my form as a public module, because its making me mad....

the master
12-31-2007, 07:20 PM
Runtime is when your application is running
Designtime is when you are designing your app.

Realtime is a type of processing and not an "app state". Every few milliseconds isnt really realtime. The idea of realtime is that an input will cause a direct output imediately

wd40bomber7
12-31-2007, 09:24 PM
Thank you for the clarification, I'll use it that way from now on. However you didn't answer my question...

Robert Collins
12-31-2007, 10:18 PM
Well, I'm not sure what your program is supposed to do but I copied your code and got a line drawn at an angle in the upper left corner of the form based on the values I put in the six text boxes.

Here is the Form Code...

Private Sub Command1_Click()
Dim Star As Location
Dim Star2 As Location
Dim Nar As Point
Dim Nar2 As Point

Star.X = Val(XX1.Text)
Star.Y = Val(XY1.Text)
Star.Z = Val(XZ1.Text)

Star2.X = Val(XX2.Text)
Star2.Y = Val(XY2.Text)
Star2.Z = Val(XZ2.Text)

Nar = L2P(Star)

Nar2 = L2P(Star2)

Line1.X1 = Nar.X
Line1.Y1 = Nar.Y
Line1.X2 = Nar2.X
Line1.Y2 = Nar2.Y
End Sub

Private Sub Form_Load()
XX1.Text = "10"
XY1.Text = "20"
XZ1.Text = "30"

XX2.Text = "40"
XY2.Text = "50"
XZ2.Text = "60"
End Sub


And here is the module Code...

Public CamSpin As Location

Public Type Point
X As Long
Y As Long
End Type

Public Type Location
X As Long
Y As Long
Z As Long
End Type

Public Function L2P(Gar As Location) As Point
Dim First As Location
Dim Second As Location
Dim Third As Point

'
'Time for orthographic projection!
'Step 1
'
First.X = Gar.X
First.Y = (Gar.Y * Cos(CamSpin.X)) + (Gar.Z * Sin(CamSpin.X))
First.Z = (Gar.Z * Cos(CamSpin.X)) - (Gar.Y * Sin(CamSpin.X))

'
'Step 2
'
Second.X = (First.X * Cos(CamSpin.Y)) - (First.Z * Sin(CamSpin.Y))
Second.Y = First.Y
Second.Z = (First.Z * Cos(CamSpin.Y)) + (First.X * Sin(CamSpin.Y))

'
'Step 3
'
Third.X = (Second.X * Cos(CamSpin.Z)) + (Second.Y * Sin(CamSpin.Z))
Third.Y = (Second.Y * Cos(CamSpin.Z)) - (Second.X * Sin(CamSpin.Z))

L2P = Third 'Send back this value
End Function

Robert Collins
12-31-2007, 10:26 PM
Heres is the same results when I put CamSpin on the Form


Private CamSpin As Location

Private Sub Command1_Click()
Dim Star As Location
Dim Star2 As Location
Dim Nar As Point
Dim Nar2 As Point

Star.X = Val(XX1.Text)
Star.Y = Val(XY1.Text)
Star.Z = Val(XZ1.Text)

Star2.X = Val(XX2.Text)
Star2.Y = Val(XY2.Text)
Star2.Z = Val(XZ2.Text)

Nar = L2P(Star, CamSpin)

Nar2 = L2P(Star2, CamSpin)

Line1.X1 = Nar.X
Line1.Y1 = Nar.Y
Line1.X2 = Nar2.X
Line1.Y2 = Nar2.Y
End Sub

Private Sub Form_Load()
XX1.Text = "10"
XY1.Text = "20"
XZ1.Text = "30"

XX2.Text = "40"
XY2.Text = "50"
XZ2.Text = "60"
End Sub



Public Type Point
X As Long
Y As Long
End Type

Public Type Location
X As Long
Y As Long
Z As Long
End Type

Public Function L2P(Gar As Location, CamSpin As Location) As Point
Dim First As Location
Dim Second As Location
Dim Third As Point

'
'Time for orthographic projection!
'Step 1
'
First.X = Gar.X
First.Y = (Gar.Y * Cos(CamSpin.X)) + (Gar.Z * Sin(CamSpin.X))
First.Z = (Gar.Z * Cos(CamSpin.X)) - (Gar.Y * Sin(CamSpin.X))

'
'Step 2
'
Second.X = (First.X * Cos(CamSpin.Y)) - (First.Z * Sin(CamSpin.Y))
Second.Y = First.Y
Second.Z = (First.Z * Cos(CamSpin.Y)) + (First.X * Sin(CamSpin.Y))

'
'Step 3
'
Third.X = (Second.X * Cos(CamSpin.Z)) + (Second.Y * Sin(CamSpin.Z))
Third.Y = (Second.Y * Cos(CamSpin.Z)) - (Second.X * Sin(CamSpin.Z))

L2P = Third 'Send back this value
End Function

wd40bomber7
12-31-2007, 11:14 PM
It let you do that? It let you put camspin on the form? It won't let me do that. (Which is exactly my problem)

Error message:Object Required

I know why its giving me this error, because the form is a private module so. However when I try and move the whole function to the form I get this (seems like circular logic) error: "Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types"
Ok so it has to be in the module I guess. How stupid! When I press the help button, it tells me "Cannot find the requested help topic" ...... I am not impressed...

I see you passed camspin to it like a variable, I thought of that as well. Why won't it let you declare Camspin as a public and be done with it?!

Anyway: Overall my worst problem is that I can't put a function which takes/gives a user-defined type into the form. I need to do this so the function can interact with the objects on the forms. Anyones help is heavily appreciated.

the master
01-01-2008, 05:07 AM
Erm. That error sounds like its here


Public Type Point
X As Long
Y As Long
End Type

Public Type Location
X As Long
Y As Long
Z As Long
End Type


Robert said he put that lot of code in a module. If you are trying to put it in a form then you need private types instead (and check the other variables too)

Robert Collins
01-01-2008, 08:48 AM
Here is the whole thing on the Form only


Dim CamSpin As Location

Private Type Point
X As Long
Y As Long
End Type

Private Type Location
X As Long
Y As Long
Z As Long
End Type

Private Function L2P(Gar As Location, CamSpin As Location) As Point
Dim First As Location
Dim Second As Location
Dim Third As Point

'
'Time for orthographic projection!
'Step 1
'
First.X = Gar.X
First.Y = (Gar.Y * Cos(CamSpin.X)) + (Gar.Z * Sin(CamSpin.X))
First.Z = (Gar.Z * Cos(CamSpin.X)) - (Gar.Y * Sin(CamSpin.X))

'
'Step 2
'
Second.X = (First.X * Cos(CamSpin.Y)) - (First.Z * Sin(CamSpin.Y))
Second.Y = First.Y
Second.Z = (First.Z * Cos(CamSpin.Y)) + (First.X * Sin(CamSpin.Y))

'
'Step 3
'
Third.X = (Second.X * Cos(CamSpin.Z)) + (Second.Y * Sin(CamSpin.Z))
Third.Y = (Second.Y * Cos(CamSpin.Z)) - (Second.X * Sin(CamSpin.Z))

L2P = Third 'Send back this value
End Function

Private Sub Command1_Click()
Dim Star As Location
Dim Star2 As Location
Dim Nar As Point
Dim Nar2 As Point

Star.X = Val(XX1.Text)
Star.Y = Val(XY1.Text)
Star.Z = Val(XZ1.Text)

Star2.X = Val(XX2.Text)
Star2.Y = Val(XY2.Text)
Star2.Z = Val(XZ2.Text)

Nar = L2P(Star, CamSpin)

Nar2 = L2P(Star2, CamSpin)

Line1.X1 = Nar.X
Line1.Y1 = Nar.Y
Line1.X2 = Nar2.X
Line1.Y2 = Nar2.Y
End Sub
Private Sub Form_Load()
XX1.Text = "10"
XY1.Text = "20"
XZ1.Text = "30"

XX2.Text = "40"
XY2.Text = "50"
XZ2.Text = "60"

End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum