IM a noob.... visual basic help please

Soldato
Joined
4 Nov 2004
Posts
14,452
Location
Beds
Right below is some visual basic proram that i need for our group project. It's supposed to calculate three dimensional spin characteristics of a golf ball fired out of our cannon and upon hitting an angled plate.

When i try and debug the thing in the excel editor it highlights the red bit and says 'invalid outside procedure'.

I don't no much at all about BASIC and am wondering if anyone would be kind enough to explain whats going on, but most importantly get the bad boy working.

Also, does that data stuff need to be at the end, or is that where i need to input my own data ???

cheers :D :D :D



Rem**Y,Z is the principle point
Rem**Y0(1),Z0(1) is the centre of the first image
Rem**Y(1,1),Z(1,1) is the first node of the first image
Rem**Y(2,1),Z(2,1) is the second node of the first image
Rem**The coordinates for the successive images aresimilar but with the second array
Rem**variable as 2,3 and 4.

Rem**Dimension the arrays
Dim Y0(4), Z0(4), Y(2, 4), Z(2, 4)

Rem**Read in the data
For J% = 1 To 4
READ Y0(J%), Z0(J%)
For I% = 1 To 2
READ Y(I%, J%), Z(I%, J%)
Next I%
Next J%
READ Y, Z, F

Rem**Adjsut the data to allow for the relief displacement
For I% = 1 To 2
For J% = 1 To 4
If 4.536901 - (Y(I%, J%) - Y0(J%) ^ 2 - (Z(I%, J%) - Z0(J%)) ^ 2 < 0) Then X(I%, J%) = 0: GoTo 5
X(I%, J%) = Sqr(4.536901 - (Y(I%, J%) - Y0(J%)) ^ 2 - (Z(I%, J%) - Z0(J%)) ^ 2)
5 R(I%, J%) = Sqr((Y(I%, J%) - Y) ^ 2 + (Z(I%, J%) - Z) ^ 2)
D(I%, J%) = X(I%, J%) * R(I%, J%) * 0.0154
YO(J%) = (J%) - Y: Y(I%, J%) = Y(I%, J%) - Y
Z0(J%) = Z0(J%) - Z: Z(I%, J%) = Z(I%, J%) - Z
K(I%, J%) = Y(I%, J%) * K(I%, J%)
Y(I%, J%) = Y(I%, J%) * K(I%, J%)
Z(I%, J%) = Z(I%, J%) * K(I%, J%)
Y(I%, J%) = Y(I%, J%) - Y0(J%): Z(I%, J%) = Z(I%, J%) - Z0(J%)
If 4.536901 - Y(I%, J%) ^ 2 - Z(I%, J%) ^ 2 Then X(I%, J%) = 0: GoTo 6
X(I%, J%) = Sqr(4.536901 - Y(I%, J%) ^ 2 - Z(I%, J%) ^ 2)
6 Next I%
Next J%

Rem**Modify cartesian coordinates to direct cosines
For J% = 1 To 4
For I% = 1 To 2
X(I%, J%) = X(I%, J%) / 2.13
Y(I%, J%) = Y(I%, J%) / 2.13
Z(I%, J%) = Z(I%, J%) / 2.13
Next I%
Next J%

Rem**Calculate spin vector before impact
If Z(2, 1) - Z(2, 2) = 0 Then A = 1E+20: GoTo 10
A = (Z(1, 1) - Z(1, 2)) / (Z(2, 1) - Z(2, 2))
10 If A * (Y(2, 1) - Y(2, 2)) - Y(1, 1) + Y(1, 2) = 0 Then GoTo 20
B = (X(1, 1) - X(1, 2) - A * (X(2, 1) - X(2, 2))) / (A * (Y(2, 1) - Y(2, 2)) - Y(1, 1) + Y(1, 2))
C = 1 + B * B + ((X(1, 1) - X(1, 2) + B * (Y(1, 1) - Y(1, 2))) / (Z(1, 2) - Z(1, 1))) ^ 2: GoTo 30
20 B = 1E+20: C = 1E+20
30 Xb = Sqr(1 / C)
Yb = B * Xb
Zb = Sqr(1 - (1 + B * B) * Xb * Xb)

Rem**Calculate rotation before impact
ANGb = Xb * X(1, 1) + Yb * Y(1, 1) + Zb * Z(1, 1)
ANGb = -Atn(ANGb / Sqr(-ANGb * ANGb + 1)) + 1.570796
R = 4.26 * Sin(ANGb)
D = Sqr((X(1, 1) - X(1, 2)) ^ 2 + (Y(1, 1) - Y(1, 2)) ^ 2 + (Z(1, 1) - Z(1, 2)) ^ 2)
ROTb = D / R
ROTb = 2 * Atn(ROTb / Sqr(-ROTb * ROTb + 1))

Rem**Calculate spin vector after impact
If Z(2, 3) - Z(2, 4) = 0 Then A = 1E+20: GoTo 10
A = (Z(1, 3) - Z(1, 4)) / (Z(2, 3) - Z(2, 4))
10 If A * (Y(2, 3) - Y(2, 4)) - Y(1, 3) + Y(1, 4) = 0 Then GoTo 20
B = (X(1, 3) - X(1, 4) - A * (X(2, 3) - X(2, 4))) / (A * (Y(2, 3) - Y(2, 4)) - Y(1, 3) + Y(1, 4))
C = 1 + B * B + ((X(1, 3) - X(1, 4) + B * (Y(1, 3) - Y(1, 4))) / (Z(1, 4) - Z(1, 3))) ^ 2: GoTo 30
20 B = 1E+20: C = 1E+20
30 Xa = Sqr(1 / C)
Ya = B * Xa
Za = Sqr(1 - (1 + B * B) * Xa * Xa)

Rem**Calculate rotation after impact
ANGa = Xa * X(1, 3) + Ya * Y(1, 3) + Za * Z(1, 3)
ANGa = -Atn(ANGa / Sqr(-ANGa * ANGa + 1)) + 1.570796
R = 4.26 * Sin(ANGa)
D = Sqr((X(1, 3) - X(1, 4)) ^ 2 + (Y(1, 3) - Y(1, 4)) ^ 2 + (Z(1, 3) - Z(1, 4)) ^ 2)
ROTb = D / R
ROTb = 2 * Atn(ROTb / Sqr(-ROTb * ROTb + 1))

Rem**Output data
Print "*****Before Impact*****"
Print "Spin Vector is ";: Print USING; "+#.##,"; Xb; Yb; Zb
Print "ROTx = ";: Print USING; "+###.##"; ROTb * Xb * F;: Print " rad/s ROTy = ";: Print USING; "+###.##"; ROTb * Yb * F;: Print " rad/s ROTz = ";: Print USING; "+###.##"; ROTb * Zb * F;: Print " rad/s."
Print "Total rotation is ";: Print USING; "+###.##"; ROTb * F;: Print " rad/s"

Print "*****After impact*****"
Print "Spin Vector is ";: Print USING; "+#/##,"; Xa; Ya; Za
Print "ROTx = ";: Print USING; "+###.##"; ROTa * Xa * F;: Print " rad/s, ROTz = ";: Print USING; "+###.##"; ROTa * Za * F;: Print " rad/s."
Print "Total rotation is ";: Print USING; "+###.##"; ROTa * F;: Print " rad/s"

End
DATA 41.4, 18.1
DATA 41.5, 19#
DATA 42.2, 17.9
DATA 33.7, 9.1
DATA 34.4, 9.9
DATA 34.2, 8.6
DATA 41.3, 18#
DATA 41.5, 19.2
DATA 42.2, 17.9
DATA 33.8, 9.2
DATA 34.4, 9.9
DATA 34.2, 8.6
DATA 31#, 14.5, 250
 
Mr^B said:
That looks suspiciously like ZX or perhaps C64 Basic, what it definately isn't it Visual Basic.

Where on earth did you get it from? Still, good luck unpicking what it does and getting it to work, I certainly wouldn't like to do it and don't see any value in unpicking 20 year old code.

:)

lol it's from some old paper our tutor gave us.... haha i did't know it was that old...... Damn i knew it was old skool but not that bad..


Christ we are screwed then :rolleyes: . plus our tutor said it was simple.... Silly old fool...


I'm a C64 n00b as I wasn't posh enough to be able to afford one at the time, you obviously come from an overprivileged background and I bet you had an Amiga when they first came out too!

nah screw amiga, atari for the win. Think i still have the 2600 or what ever it was called. stunning console and still works. Sony and their rubbish ps2 eat your heart out. !!!!!

i need a cookie
 
Last edited:
sos for not replying, been away for a few days.

Thanks a lot byte, much appreciated. Meeting with our tutor tomorrow so il show him what we have so far :D :D :D

Programming something like this for noobs really is hard. I know loads about PC hardware and a little about software, but programming is soo hard. I remember doing some C++ in my first year, and 90% of the 200 coursework exercises were copied off about 5 people who could do it. We are engineers not programers. LOL.

Ad
 
Last edited:
O ya and i think it was BASIC for apple.

Tutor lookedover it today and said it was some VERRRRY old program that obviously couldn't have been written excel as that was around all those years ago. So he said that the printing parts near the end cannot obviously be compiled by excel, and other parts of the program are not need/ and or wrong.

He didn't tell me any of this when he gave me the program and probably assumed i was some wizzkid :rolleyes: lol
 
hmm thought id replied, obviously not.

Using excel XP and just go to the macro part of the tools and select *** visual basic option in there.

My tutor explained a little of it too me, but ive sent it to him so hopefully he'll be able to bring it up to date in excel.
 
Back
Top Bottom