none
Optiion Explicit on requires all variable to have an 'as' clause. RRS feed

  • Question

  •  How could I rewrite this code  below? What kind of variable will PrintControl fall into. When I run the code I get "option Explicit on requires all variable to have an 'As' clause"

    Thanks

            Dim printControl = New Printing.StandardPrintController
           

    Sunday, June 10, 2018 6:31 PM

Answers

  •  You are creating a New instance of a StandardPrintController right?  So that is the type that your variable should be declared as.  You can declare it either or way...

            Dim printControl As New Printing.StandardPrintController
    
            'or...
    
            Dim printControl As Printing.StandardPrintController = New Printing.StandardPrintController


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Sunday, June 10, 2018 6:59 PM
    • Proposed as answer by Cor Ligthert Sunday, June 10, 2018 8:21 PM
    • Marked as answer by alobi Tuesday, June 12, 2018 5:49 PM
    Sunday, June 10, 2018 6:58 PM

All replies

  •  You are creating a New instance of a StandardPrintController right?  So that is the type that your variable should be declared as.  You can declare it either or way...

            Dim printControl As New Printing.StandardPrintController
    
            'or...
    
            Dim printControl As Printing.StandardPrintController = New Printing.StandardPrintController


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Sunday, June 10, 2018 6:59 PM
    • Proposed as answer by Cor Ligthert Sunday, June 10, 2018 8:21 PM
    • Marked as answer by alobi Tuesday, June 12, 2018 5:49 PM
    Sunday, June 10, 2018 6:58 PM
  • Yea it depents, because you start with an lowercase, I assume the sentence is inside a method. 

    Then you can also set Option Infer On 

    In the build code will then the same code created as ironRazerz shows (be aware the second one he shows is VB7.0 style the first one is since VB7.1). 


    Success
    Cor


    Sunday, June 10, 2018 7:55 PM