Using ComboBoxList Selected Item as a Variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • konradwalsh
    New Member
    • Dec 2012
    • 4

    Using ComboBoxList Selected Item as a Variable

    Hi have searched and searched but cannot find a specific answer to this..

    I have a form with a combobox with a list of PC names.

    I want to store the pc name selected as a variable and pass it through to a function.

    It fails. I dont understand why. Even if i put up a msgbox to display my variable, it displays empty..

    If I switch to using a regular textbox, pass that through to a variable and then onto the function.. it works...

    Code:
        Public Sub allianceChecker()
    
            Dim strProcess As String = "ALLIANCEMFG.EXE"
    
            Dim strComputer As String = frmStart.cmbMainFrm_PcList.SelectedText.ToUpper
    
            MessageBox.Show(strComputer)
            MessageBox.Show(strProcess)
       
            If CheckRemoteProcess.IsProcessRunning(strComputer, strProcess) = True Then
                MessageBox.Show("Yes")
            Else
                MessageBox.Show("no")
    
            End If
        End Sub
    and the function it calls:

    Code:
    Module CheckRemoteProcess
        Public Function IsProcessRunning(ByVal strServer, ByVal strProcess)
            Dim Process, strObject
            IsProcessRunning = False
            strObject = "winmgmts://" & strServer
    
    
            For Each Process In GetObject(strObject).InstancesOf("win32_process")
                If UCase(Process.name) = UCase(strProcess) Then
                    IsProcessRunning = True
    
                    Exit Function
                End If
            Next
            Return IsProcessRunning
        End Function
    
    End Module

    Please advise...
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I think you misunderstand what selectedText represents. selectedText represents the portion of the text that is highlighted, not the value selected item. For that, you need to use combobox.select edItem.ToString .

    Comment

    • konradwalsh
      New Member
      • Dec 2012
      • 4

      #3
      Hi Rabbit...
      Thanks for offering to help me on this -
      i change the line as you suggested to
      Code:
      strComputer = frmStart.cmbMainFrm_PcList.SelectedItem.ToString.ToUpper
      unfortunately this results in the same error -
      Cannot create ActiveX component. this comes up when it trys to run the command against that machine. The command highlighted in the debugger is
      For Each Process In GetObject(strOb ject).Instances Of("win32_proce ss")

      I am not sure if its significant.. my form has a tab control in which the check button resides but outside the tab control, is my combo box

      Comment

      • konradwalsh
        New Member
        • Dec 2012
        • 4

        #4
        Hi again

        this may also be significant..

        my Combobox is filled by reading a text file

        that text file is a static list of pc names - one per line

        I have an update button that queries the active directory for the latest list of pcs.(Domain computers) and writes over the original text file.

        The purpose is so that the application loads faster and does need to be query-ing the AD so much.

        I have just noticed your method works if I query the AD first and then run my command. It does work when I pick the same item that was generated by the text file

        Comment

        • konradwalsh
          New Member
          • Dec 2012
          • 4

          #5
          i am sorry if I have wasted your time but I have noticed my text file includes a space after each entry. therefore it doesnt work...

          either way.. your original suggestion is what got things moving

          thanks very much

          Comment

          • vigneshwaran91
            New Member
            • Nov 2013
            • 1

            #6
            You should use this
            Code:
             Dim strComputer As String = frmStart.cmbMainFrm_PcList.Text.ToUpper

            Comment

            Working...