PDA

Click to See Complete Forum and Search --> : can someone explain this?


netSurfer
Dec 2nd, 1999, 09:25 PM
I'm trying to read this Non-commented code and I don't understand how this section is working. The guy declares a type:
Type ParaIO
Change As Integer
ParaCount As Integer
FileNo As Integer
ParaDes As String * 4
ParaPos As Long
EndPos As Long
AEndPos As Long
OpenType As Integer
End Type

but then sets it like this:

chng = para.Change
cnt = para.ParaCount
FileNo = para.FileNo
Des$ = para.ParaDes
ps& = para.ParaPos
endps& = para.EndPos
appendendps& = para.AEndPos
otype = para.OpenType

I don't understand how this is working, shouldn't it be paraIO.OpenType etc?

onerrorgoto
Dec 2nd, 1999, 09:39 PM
Well, somewhere in the code he has done this:
Dim para As ParaIO

which give you the oportunity to do this:
chng = para.OpenType


------------------
On Error Goto Bed :0)
anders@zsystemdesign.se

netSurfer
Dec 2nd, 1999, 09:44 PM
yep that's exactly what he's done. What a butt whack. He declares the ParaIO type, then writes a function called ParaIO and dims para as ParaIO in the args for that function. What a whack. Thanks. That explains alot. Another question, can you explain why in the world he'd do this? Is there a reason? If there is, I guess I can't call him a whack.. oh wait, yes I can, you should see the rest of his code....

onerrorgoto
Dec 2nd, 1999, 09:50 PM
He's a whack :o

No I don't know why he declares the var in an arg. I shouldn't, because it's much to confusing as you might have noticed :)

------------------
On Error Goto Bed :0)
anders@zsystemdesign.se

netSurfer
Dec 2nd, 1999, 09:52 PM
:-) That explains him I'm pretty sure. I've never used Types so I'm not sure how they work or why he really needs them. So I wasn't really sure why he'd do this. Would he have to dim para as ParaIO because it's in a function called ParaIO?

netSurfer
Dec 2nd, 1999, 09:53 PM
another question what does this do:

ParaDes As String * 4

declared in the Initial ParaIO type. I don't understand the (* 4)

MartinLiss
Dec 2nd, 1999, 10:07 PM
It defines a fixed length string of 4 characters. If you then set that string equal to something less than 4 chars long, it will pad with spaces. If you set it to something longer, it will truncate.

------------------
Marty

netSurfer
Dec 2nd, 1999, 10:12 PM
Oh, that makes sense. Thanks

MartinLiss
Dec 2nd, 1999, 10:34 PM
You also asked why someone would use Types. Well one reason is to handle (and easily clear) arrays that contain multiple data types. Here's an example:Option Explicit

Private Type MyType
intField1 As Integer
dblField2 As Double
strField3 As String
lngField999 As Long
End Type

Dim MyArray(3) As MyType
Private Sub Form_Load()

MyArray(0).intField1 = 37
MyArray(0).dblField2 = 123.456
MyArray(0).strField3 = "Hi there"
MyArray(0).lngField999 = 123456789

MsgBox MyArray(0).strField3

Erase MyArray()

MsgBox MyArray(0).strField3

End Sub


------------------
Marty

netSurfer
Dec 2nd, 1999, 10:44 PM
thanks, I understand why now. And it cleared up a couple other issues as well. Thanks alot. I've been struggling with this guys code for several weeks now. It really sucks when there's no comments and he does things I don't understand. It helps being able to come here and get help.

onerrorgoto
Dec 5th, 1999, 01:29 PM
A question to this topic, since I'm not that god working with Types(yet :) ).
As netsurfer said:
"He declares the ParaIO type, then writes a function called ParaIO and dims para as ParaIO in the args for that function."

Is it possible to declare a variable of of a type for the first time as an argument??
What kind of input to that function should I then send?

If my question doesn't make sence look here:

type TypeHello
strHello as string
intNumber as integer
end type

myFunction(word as string, Type as TypeHello)as String

private sub form_load
dim Help as string
help=myFunction("Hello World",54) 'is this correct?? second arg should be of TypeHello right!
end sub
Doesn't I have to declare a variable of the type TypeHello to send as an argument??

I laid sleepless (in Seatle, sorry) my bed all weekend trying to figure out this.

------------------
On Error Goto Bed :0)
anders@zsystemdesign.se

Crazy D
Dec 5th, 1999, 02:52 PM
Nope, you'll have to call the function like this:
Dim t as TypeHello
Dim s as string
s = MyFunction("Hello world", t)