|
-
Dec 2nd, 1999, 10:25 PM
#1
Thread Starter
Hyperactive Member
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?
-
Dec 2nd, 1999, 10:39 PM
#2
Hyperactive Member
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)
[email protected]
-
Dec 2nd, 1999, 10:44 PM
#3
Thread Starter
Hyperactive Member
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....
-
Dec 2nd, 1999, 10:50 PM
#4
Hyperactive Member
-
Dec 2nd, 1999, 10:52 PM
#5
Thread Starter
Hyperactive Member
:-) 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?
-
Dec 2nd, 1999, 10:53 PM
#6
Thread Starter
Hyperactive Member
another question what does this do:
ParaDes As String * 4
declared in the Initial ParaIO type. I don't understand the (* 4)
-
Dec 2nd, 1999, 11:07 PM
#7
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
-
Dec 2nd, 1999, 11:12 PM
#8
Thread Starter
Hyperactive Member
Oh, that makes sense. Thanks
-
Dec 2nd, 1999, 11:34 PM
#9
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:
Code:
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
-
Dec 2nd, 1999, 11:44 PM
#10
Thread Starter
Hyperactive Member
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.
-
Dec 5th, 1999, 02:29 PM
#11
-
Dec 5th, 1999, 03:52 PM
#12
Hyperactive Member
Nope, you'll have to call the function like this:
Dim t as TypeHello
Dim s as string
s = MyFunction("Hello world", t)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|