Results 1 to 12 of 12

Thread: can someone explain this?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    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?

  2. #2
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post

    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



  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    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....

  4. #4
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post

    He's a whack

    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



  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    :-) 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?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    another question what does this do:

    ParaDes As String * 4

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

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Post

    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

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    Oh, that makes sense. Thanks

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Post

    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

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    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.

  11. #11
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post

    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



  12. #12
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386

    Post

    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
  •  



Click Here to Expand Forum to Full Width