Results 1 to 11 of 11

Thread: Could someone tell me what's Wrong With This Code?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    406

    Could someone tell me what's Wrong With This Code?

    Code:
    Friend Sub Read_Script_Template()
        Dim Handle As Integer
        
        If Len(Dir$(mvarSCRIPT_TEMPLATE_NAME)) = 0 Then
            Err.Raise 53  ' File not found
        End If
        
        ' open in binary mode
        Handle = FreeFile
        Open mvarSCRIPT_TEMPLATE_NAME$ For Binary As #Handle
        ' read the string and close the file
        SCRIPT_TEMPLATE = Space$(LOF(Handle))
        Get #Handle, , SCRIPT_TEMPLATE
        Close #Handle
        
        MsgBox SCRIPT_TEMPLATE
    
    End Sub

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Well, without knowing what you are expecting, or what you got that you didn't expect, its hard to say.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    406

    well....

    nothing comes up in the message box...

    but I don't get any errors or anything....so it finds the file....but it doesn't seem to read it at all...

  4. #4
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    You need to loop through it... I believe......
    VB Code:
    1. Do While Not EOF
    2.    'Your Code here
    3. Loop

  5. #5
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    shouldnt it be

    VB Code:
    1. Get #Handle, 1 , SCRIPT_TEMPLATE
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    No, his File I/O code is just fine.
    I would imagine that perhaps an error is happening, and it is being passed up to the called procedure which has On Error Resume Next in place, or the error is just being ignored.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  7. #7
    Addicted Member Bregalad's Avatar
    Join Date
    Jul 2000
    Location
    Oslo,Norway
    Posts
    183

    variant/string

    Try

    Dim SCRIPT_TEMPLATE As String

    in your Sub

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: variant/string

    Originally posted by Bregalad
    Try

    Dim SCRIPT_TEMPLATE As String

    in your Sub
    It, along with the other variables, could be declared as module level variables - or Option Explicit may not be turned on.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  9. #9
    Addicted Member Bregalad's Avatar
    Join Date
    Jul 2000
    Location
    Oslo,Norway
    Posts
    183
    Yes, but
    Dim SCRIPT_TEMPLATE
    or
    Dim SCRIPT_TEMPLATE As Variant ' or something else
    would cause an error

  10. #10
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Ahhh very true. I didn't know the Get keyword wouldn't work with variants. Good call
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    406

    Yeah....

    It is a module level declaration, declared Private as a string...and I am PRETTY sure the option explicit is there (I am at work now, so i can't check)....but i'll look when i get home!

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