Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Great Hans a question on your old code... (2000 sr 1)

    Sub IPSEMA()

    Set Elenco = Worksheets("IPSEMA")
    n = FirstFree("IPSEMA", "A", 2) 'Record iniziale per il riempimento del tabulato
    'Elenco.Range("A3:IV65536").ClearContents

    Call CheckCondition

    Kill "E:MACRODIFRONZOGOTFI200"
    Do
    Application.Wait Now + TimeSerial(0, 0, 5)
    Loop Until Dir("E:MACRODIFRONZOGOTFI200") = ""



    X = Shell("E:MACRODIFRONZOIPSEMA.BAT", vbHide)
    Do While Dir("E:MACRODIFRONZOGOTFI200") = ""
    Application.Wait Now + TimeSerial(0, 0, 5)
    Loop

    iFile = FreeFile()
    NomeFile = "E:MACRODIFRONZOGOTFI200"

    'Ciclo apertura file di testo
    Open NomeFile For Input As #iFile
    ..........

    This is a piece of my code and a CALL CheckCondition
    CODE OF CheckCondition
    Public Function CheckCondition()
    Dim strFile As String

    On Error GoTo NoDisk
    'If error => no disk
    strFile = Dir("A:")

    'If result of dir = "" => file not present
    strFile = Dir("A:GOTFI200.ZIP")
    Select Case strFile
    Case ""
    GoTo FileNotpresent
    End Select

    'Conditions are ok => return TRUE
    CheckCondition = True
    Exit Function

    NoDisk:
    Select Case Err.Number
    Case 52
    'Bad file name or number
    MsgBox "NESSUN FLOPPY-DISK INSERITO! INSERIRE FLOPPY DISK!"
    End Select
    'Conditions are false => return FALSE
    CheckCondition = False
    Exit Function
    FileNotpresent:
    MsgBox "NESSUN FILE GOTFI200.ZIP, INSERISCI IL FLOPPY-DISK CORRETTO!"
    'Conditions are false => return FALSE
    CheckCondition = False
    Exit Function

    End Function

    Why If one of this condition into Public Function not is respected the next line of code go to

    Kill "E:MACRODIFRONZOGOTFI200"

    and not stop the rest of code?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Great Hans a question on your old code... (2000 sr 1)

    The macro IPSEMA will call CheckCondition, and whatever the result, continue execution after it, If you want IPSEMA to stop running if there is a problem in CheckCondition, you must make use of the return value of this function:

    n = FirstFree("IPSEMA", "A", 2) 'Record iniziale per il riempimento del tabulato
    'Elenco.Range("A3:IV65536").ClearContents

    If CheckCondition = False Then Exit Sub

    Kill "E:MACRODIFRONZOGOTFI200"

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Great Hans a question on your old code... (2000 sr 1)

    Kiss!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •