Results 1 to 21 of 21

Thread: Can't use Option Explicit

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Can't use Option Explicit

    So I'm using this example VB code I got from the Instrument Vendor ( Keithley ) and although it works, it won't compile with Option Explicit = True

    From past bad experience, I always like to have Option Explicit set at the top in any programs I write. Saves future heartache.

    Anyway, here is the offending line:

    driver.System.ControlMode = TekPWx4000ControlModeLocal

    It only appears in one place in the program, and like I said the program works fine, but I want to use Option Explicit. How do I declare this ?

    I did try using a break point, but when I hover over the [TekPWx4000ControlModeLocal] variable it always says "empty".

    Please help me declare this guy, thanks...

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,461

    Re: Can't use Option Explicit

    What is the data type of driver.System.ControlMode?

    Most likely it is Integer, Long, or maybe Byte? Perhaps even Single or Double? If so, just assign 0 and be done.

    If String assign vbNullString and be done.

    If Variant, assign Empty and be done.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Re: Can't use Option Explicit

    Attachment 184822

    This is how it shows up in properties, some kind of object ?

    And this is the reference, its a .dll I believe. The red arrow is to indicate how similar it is to all the text boxes in the app.

    I can't figure out how to properly declare it to make Option Explicit work, my apologies.
    Last edited by prginocx; May 17th, 2022 at 07:01 PM.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Re: Can't use Option Explicit

    Quote Originally Posted by dilettante View Post
    What is the data type of driver.System.ControlMode?

    Most likely it is Integer, Long, or maybe Byte? Perhaps even Single or Double? If so, just assign 0 and be done.

    If String assign vbNullString and be done.

    If Variant, assign Empty and be done.
    I should also mention this declaration at the top of the form: Dim driver As Ke2100

  5. #5
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    714

    Re: Can't use Option Explicit

    If it works fine just comment out that line it will probably continue to work since itís undefined right now. As is itís probably doing nothing or throwing an error if itís an object type. Itís more likely and enum value an object would have a set keyword

  6. #6
    Addicted Member
    Join Date
    Oct 2011
    Posts
    179

    Re: Can't use Option Explicit

    Quote Originally Posted by prginocx View Post
    Option Explicit = True
    That's the problem, it is incorrect.

    It is just:

    Code:
    Option Explicit
    In the declaration section.
    Just that, in one line.
    Not equal to anything.

  7. #7
    Addicted Member gilman's Avatar
    Join Date
    Jan 2017
    Location
    Bilbao
    Posts
    130

    Re: Can't use Option Explicit

    If Driver is correctly declared, goto to the definition of TekPWx4000ControlModeLocal

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Re: Can't use Option Explicit

    I don't know where that Option Explicit = True came from, I've never declared it that way...and Originally posted by prginocx is not true, that is fake.

    I've always used Option Explicit...just two words on one line. at the very top.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Re: Can't use Option Explicit

    The only declaration of driver is like above:

    Dim driver As Ke2100


    and Ke2100 is a .dll library in the ReferencesAttachment 184869

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Re: Can't use Option Explicit

    Won't work if I comment out that line.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Re: Can't use Option Explicit

    Quote Originally Posted by gilman View Post
    If Driver is correctly declared, goto to the definition of TekPWx4000ControlModeLocal

    Dim driver As Ke2100 ' is the declaration, I can't find the definition of TekPWx4000ControlModeLocal

    I also tried debug.print of TekPWx4000ControlModeLocal...came up blank.

  12. #12
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    714

    Re: Can't use Option Explicit

    you would have to upload the source and sdk package somewhere for someone to look at

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Re: Can't use Option Explicit

    Quote Originally Posted by dilettante View Post
    What is the data type of driver.System.ControlMode?

    Most likely it is Integer, Long, or maybe Byte? Perhaps even Single or Double? If so, just assign 0 and be done.

    If String assign vbNullString and be done.

    If Variant, assign Empty and be done.
    driver is declared as the data type Ke2100, and that takes me back to the project references:

    Attachment 184870

  14. #14
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    714

    Re: Can't use Option Explicit

    none of your attachments are working for me btw

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Re: Can't use Option Explicit

    Is there some other way to post a picture ? This is a .jpg shot of the References form.

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Re: Can't use Option Explicit

    This is the source code for form1:
    Code:
    Dim driver As Ke2100
     '  Option Explicit                 ' had to remove because of driver.System.ControlMode = TekPWx4000ControlModeRemote
    
    
    Private Sub btnClrValue_Click()
    Form1.tbx_Measurement.Text = ""
    End Sub
    
    Private Sub btnLogSamples_Click()
       gblintSampleNo = 0
       gblvarThisInstant = CDate(Now())
       gblintNoSecs = CInt(Form1.tbxSampleInterval.Text)
       gblvarFutureTime1 = DateAdd("s", gblintNoSecs, gblvarThisInstant)
       gblvarStartTime = gblvarThisInstant
       Form1.tmr_Sample.Enabled = True
       log (" Start Sampling Now")
    End Sub
    
    Private Sub btnStop_Click()
       Form1.tmr_Sample.Enabled = False
       Form1.tmr_GetFileStr.Enabled = False
       
    End Sub
    
    
    
    Private Sub Command1_Click()
    Form1.Timer12.Enabled = True    ' fire all the exit timers
    End Sub
    
    Private Sub Command10_Click()
    List1.Clear
                                       
                Dim measuredValues() As Double
                On Error GoTo error_handler4
                measuredValues = driver.Measurement.FetchMultiPoint(CInt(Text11.Text))
                
                Dim index As Long
                For index = LBound(measuredValues) To UBound(measuredValues)
    
                    List1.AddItem (CStr(measuredValues(index)))
                Next
    Exit Sub
    error_handler4:
                    MsgBox "Not a Valid Integer Value at TimeOut"
    End Sub
    
    Private Sub Command11_Click()
    List1.Clear
                            
                Dim measuredValues() As Double
                On Error GoTo error_handler5
                measuredValues = driver.Measurement.ReadMultiPoint(CInt(Text11.Text))
    
                Dim index As Long
                For index = LBound(measuredValues) To UBound(measuredValues)
                
                    List1.AddItem (CStr(measuredValues(index)))
                Next
    Exit Sub
    error_handler5:
                    MsgBox "Not a Valid Integer Value at TimeOut"
    End Sub
    
    Private Sub btn_Clear_Click()
    'Clear Status Byte
                driver.Status.ClearStatusByte
                
                Dim csb As Integer
                csb = driver.InstrumentIO.Query("*OPC?")
                           
                'MsgBox csb
                
                If csb = 0 Then
                    MsgBox "Device Clear Status Byte is failed"
                End If
                
                If csb = 1 Then
                    'MsgBox "Device Clear Status Byte is Successful"
                    Form1.lblStatus.Caption = "  Device Clear OK !"
                End If
                
    End Sub
    
    Private Sub Command13_Click()
    
    Dim s As String               'added for the op exp
                'Resetting
                driver.Utility.Reset
                'Clear status byte
                driver.Status.ClearStatusByte
                'Set reference resistance to 50ohm
                driver.Math.DBMReference = 50
                'Configure the DMM to measure ACVolts
                driver.Configure Ke2100FunctionACVolts, 5, 0.00001
                'Configure the range
                driver.Range = 1
                'Set AC Filter to 200Hz
                driver.Measurement.Configuration.DetectorBandwidth = 200
                'Make it accept 5 triggers
                driver.Trigger.MultiPoint.SampleCount = 5
                'Set trigger source to immediate
                driver.Trigger.Source = Ke2100TriggerSourceImmediate
                'Set math function to DBM
                driver.Math.Function = Ke2100MathFunctionDBM
                'Enable math
                driver.Math.State = True
                'DMM Data array
                 Dim dmmdata() As Double
                dmmdata = driver.Measurement.ReadMultiPoint(5000)
                
                Dim index As Long
                For index = LBound(dmmdata) To UBound(dmmdata)
                    s = s & "," & CStr(dmmdata(index))
                Next
                MsgBox (s)
            
    End Sub
    
    Private Sub Command3_Click()
    Text4.Text = driver.Identity.InstrumentManufacturer & "," & driver.Identity.InstrumentModel
    End Sub
    Private Sub btn_Init_Click()
    Set driver = New Ke2100
             
             On Error GoTo error_handler1
             
             driver.Initialize Text1.Text, False, False, ""
             
             
             If driver.Initialized = True Then
                
              driver.System.ControlMode = TekPWx4000ControlModeRemote                                        ' does not allow option explicit
                Frame2.Enabled = True
                Frame3.Enabled = True
                Frame8.Enabled = True
                cbx_Online.Enabled = True
                cbx_Online.Value = 1
                Form1.cbx_Online.FontBold = True
                Form1.cbx_Online.Caption = "KEITHLEY 2100 ONLINE"
                Form1.cbx_Online.BackColor = GREEN
                End If
             If driver.Initialized = False Then
                Frame2.Enabled = False
                Frame3.Enabled = False
                Frame8.Enabled = False
                cbx_Online.Enabled = False
                cbx_Online.Value = 0
                Form1.cbx_Online.FontBold = False
                Form1.cbx_Online.Caption = "Keithley 2100 Offline"
             End If
             
    Exit Sub
            
    error_handler1:
                    MsgBox "Not a Valid Instrument Resource Name"
    
    End Sub
    Private Sub Command2_Click()
            Dim errorNum As Long
            Dim errorMsg As String
            errorNum = -1
    
            driver.Utility.ErrorQuery errorNum, errorMsg
            Text2.Text = errorNum
            Text3.Text = errorMsg
            
    End Sub
    Private Sub btn_Reset_Click()
        driver.Utility.Reset
        
                Dim rst As Integer
                rst = driver.InstrumentIO.Query("*OPC?")
                
                'MsgBox rst
                
                If rst = 0 Then
                    MsgBox "Reset Device is failed"
                End If
                If rst = 1 Then
                 '   MsgBox "Reset Device is Successful"
                    Form1.Text4.Text = ""
                    Form1.lblStatus.Caption = "  Device Reset OK !"
                End If
                
        End Sub
    Private Sub btn_Disconnect_Click()
     Debug.Print (TekPWx4000ControlModeLocal)
     driver.System.ControlMode = TekPWx4000ControlModeLocal       ' does not allow Option Explicit
     Debug.Print (TekPWx4000ControlModeLocal)
        driver.Close
        
     '   driver.System.ControlMode
    'msgbox (TekPWx4000ControlModeLocal)
    If driver.Initialized = False Then
                
                Frame2.Enabled = False
                Frame3.Enabled = False
                Frame8.Enabled = False
                Form1.cbx_Online.Enabled = False
                Form1.cbx_Online.Value = 0
                Form1.cbx_Online.FontBold = False
                Form1.cbx_Online.Caption = "Keithley 2100 Offline"
                Form1.cbx_Online.BackColor = Const_GREY
                Form1.lblStatus.Caption = "  Device Disconnected OK!"
            End If
    End Sub
    
    Private Sub Command4_Click()
        driver.Measurement.Initiate
    End Sub
    
    Private Sub Command5_Click()
        Text5.Text = CStr(driver.Measurement.Fetch(5000))
    End Sub
    
    Private Sub Command6_Click()
        Text6.Text = CStr(driver.Measurement.Read(5000))
    End Sub
    
    Private Sub btn_Measure_Click()
            
        Dim MyOption As Ke2100FunctionEnum
        MyOption = Combo1.ListIndex
            
        On Error GoTo error_handler2
        Dim input1 As Double
        Dim input2 As Double
        
        input1 = CDec(Text7.Text)
        input2 = CDec(Text8.Text)
        
        Form1.tbx_Measurement.Text = CStr(driver.Measure(MyOption, input1, input2))
    
    Exit Sub
    error_handler2:
                    MsgBox "Not a Valid Double Value"
        
    End Sub
    
    Private Sub Command8_Click()
        Text10.Text = driver.Trigger.MultiPoint.SampleCount
    End Sub
    
    Private Sub Command9_Click()
        On Error GoTo error_handler3
        driver.Trigger.MultiPoint.SampleCount = CInt(Text10.Text)
    Exit Sub
    error_handler3:
                    MsgBox "Not a Valid Integer Value"
        
    End Sub
    
    
    Private Sub Form_Load()
    'Dim hMenu   As Long        ' all this in the form load
    
    'hMenu = GetSystemMenu(Me.hwnd, 0)         ' turn off the X do user can't close the main form / program...
    'DeleteMenu hMenu, SC_CLOSE, MF_BYCOMMAND  ' turn off the X top right corner
    
    gblblColor = False                 ' give it a start value
    
    Form1.Combo1.ListIndex = 1         ' set it to DC volts
    
    
    End Sub
    
    
    
    Private Sub Timer1_Timer()
    Form1.Timer1.Enabled = False
    Form1.btn_Disconnect.Value = True
     Unload logging
     Unload Me
    End Sub
    
    Private Sub Timer12_Timer()
    Form1.Timer12.Enabled = False
    Form1.btn_Clear.Value = True    ' press clear btn
    Form1.Timer16.Enabled = True
    End Sub
    
    Private Sub Timer16_Timer()
    Form1.Timer16.Enabled = False
    Form1.btn_Reset.Value = True
    Form1.Timer1.Enabled = True
    End Sub
    
    Private Sub tmr_GetFileStr_Timer()
    Form1.tmr_GetFileStr.Enabled = False
    
    Dim strFileData As String
    Dim varThisInstant As Variant
    Dim strSampleNo As String
    Dim dblBattV As Double
    Dim dblBattMin As Double
    Dim varElapsedTime As Variant
    Dim strElapsedTime As String
    Dim strFileHeader As String
    Dim strBattV As String
    Dim intError As Integer
    Dim strFilePath As String
    
    strFilePath = App.Path
    strFilePath = strFilePath & "\logs\BattDat.txt"
    
    dblBattMin = CDbl(Form1.tbxBattMin.Text)
    strSampleNo = CStr(gblintSampleNo)
    varThisInstant = CDate(Now())
    dblBattV = CDbl(Form1.tbx_Measurement.Text)
       If (dblBattV < dblBattMin) Then    ' stop sampling, we are done.
          Form1.btnStop.Value = True
          log (" Bat V = " & Form1.tbx_Measurement.Text & " but Batt Min = " & Form1.tbxBattMin.Text & " Time to STOP ")
          MsgBox " Vbatt of " & dblBattV & " is less than Vmin of " & Form1.tbxBattMin.Text
       End If
       If gblintSampleNo < 2 Then ' we need to write the header string
          MsgBox " This file " & strFilePath & " MUST Exist, and shoudl be blank !"
          strFileHeader = ", Sample No ,  Current Time ,  Elapsed Time ,    VBatt , "
          intError = OpenAppendFile(strFilePath, strFileHeader)
          log (" OpenAppendFile(), file header returned " & intError)
       End If
    varElapsedTime = varThisInstant - gblvarStartTime
    strElapsedTime = Format(varElapsedTime, "h:m:s")
    strBattV = Format(dblBattV, "00.00000")
    strFileData = ", " & strSampleNo & " , " & varThisInstant & " , " & strElapsedTime & " , " & strBattV
    log (" About to OpenAppendFile() with " & strFileData)
    
       intError = OpenAppendFile(strFilePath, strFileData)
    log (" OpenAppendFile() returned " & intError)
    End Sub
    
    Private Sub tmr_Sample_Timer()
    ' Form1.TmrTest.Enabled = False
    Dim lngin As Long
    Dim varThisInstant As Variant
    Dim ElapsedTime As Variant
    
    '   cut from below " + " , " + " Elapsed Time =: " + " , " + Format(ElapsedTime, "h:m:s") + " , "
    
    gblvarThisInstant = CDate(Now())
    If gblvarThisInstant > gblvarFutureTime1 Then
       gblintSampleNo = gblintSampleNo + 1
       gblintNoSecs = CInt(Form1.tbxSampleInterval.Text)
       gblvarFutureTime1 = DateAdd("s", gblintNoSecs, gblvarThisInstant)    ' select a future time trigger point
       logging.scribe (" SAMPLE !! This instant = " & gblvarThisInstant & " Future Time1 = " & gblvarFutureTime1)
       Form1.btnClrValue.Value = True
       Form1.btn_Measure.Value = True     ' press button, take measurement
       Form1.tmr_GetFileStr.Enabled = True ' fire timer to get info into string for file
       log (" ThisInstant > FutureTime, ++ future time, fire tmrGetFileStr()")
    Else
       If gblblColor = True Then
          Form1.tbx_Measurement.BackColor = &HC0FFFF
          gblblColor = False
       Else
          Form1.tbx_Measurement.BackColor = &HFFFFC0
          gblblColor = True
       End If
    End If
    
     Form1.tmr_Sample.Enabled = True
    ' log (" This instant = " & gblvarThisInstant & " Future Time1 = " & gblvarFutureTime1 & " Fire tmr_Sample again")
    
    End Sub
    
    
    
    
    Private Sub log(ByVal strline As String)
    
    logging.scribe (strline)
    End Sub
    Last edited by Shaggy Hiker; May 18th, 2022 at 04:46 PM. Reason: Added CODE tags.

  17. #17
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,461

    Re: Can't use Option Explicit

    Quote Originally Posted by prginocx View Post
    driver is declared as the data type Ke2100, and that takes me back to the project references:
    Who asked about driver? What is the data type of driver.System.ControlMode?

    Or just assign Empty there then, since that's the value you have without Option Explicit. or comment the line out entirely, which may well work if the assignment to Empty isn't doing anything important.

    This isn't hard. It's actually pretty obvious.

  18. #18
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    714

    Re: Can't use Option Explicit

    The answer is not in the source. Itís most likely in the type libraries of the dlls we donít have access to. Sometimes constant values will also be define in the sample code they provide. Search /grep all the sample code and see if comes up as well. Object browser has a search feature as well. If itís truly undefined the vendor probably has their own forum or at least an email address somewhere. They will have access to the files and know the environment. Iím out good luck.

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Re: Can't use Option Explicit

    Quote Originally Posted by dz32 View Post
    The answer is not in the source. Itís most likely in the type libraries of the dlls we donít have access to. Sometimes constant values will also be define in the sample code they provide. Search /grep all the sample code and see if comes up as well. Object browser has a search feature as well. If itís truly undefined the vendor probably has their own forum or at least an email address somewhere. They will have access to the files and know the environment. Iím out good luck.

    I did email back to tech support for the company ...they said the guy who created all this quit a long time ago...

  20. #20
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    37,412

    Re: Can't use Option Explicit

    It sure looks like an enum. You may have done this already and I missed it, but I'd try assigning 0.
    My usual boring signature: Nothing

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    150

    Re: Can't use Option Explicit

    Quote Originally Posted by Shaggy Hiker View Post
    It sure looks like an enum. You may have done this already and I missed it, but I'd try assigning 0.

    I apologise for asking, but what would that look like ?

    Enum "enumerationname" [ As datatype ]
    memberlist
    End Enum

    data type ?

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