By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,550 Members | 908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,550 IT Pros & Developers. It's quick & easy.

Using ComboBoxList Selected Item as a Variable

P: 4
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...

Expand|Select|Wrap|Line Numbers
  1.     Public Sub allianceChecker()
  2.  
  3.         Dim strProcess As String = "ALLIANCEMFG.EXE"
  4.  
  5.         Dim strComputer As String = frmStart.cmbMainFrm_PcList.SelectedText.ToUpper
  6.  
  7.         MessageBox.Show(strComputer)
  8.         MessageBox.Show(strProcess)
  9.  
  10.         If CheckRemoteProcess.IsProcessRunning(strComputer, strProcess) = True Then
  11.             MessageBox.Show("Yes")
  12.         Else
  13.             MessageBox.Show("no")
  14.  
  15.         End If
  16.     End Sub
  17.  
  18.  
and the function it calls:

Expand|Select|Wrap|Line Numbers
  1. Module CheckRemoteProcess
  2.     Public Function IsProcessRunning(ByVal strServer, ByVal strProcess)
  3.         Dim Process, strObject
  4.         IsProcessRunning = False
  5.         strObject = "winmgmts://" & strServer
  6.  
  7.  
  8.         For Each Process In GetObject(strObject).InstancesOf("win32_process")
  9.             If UCase(Process.name) = UCase(strProcess) Then
  10.                 IsProcessRunning = True
  11.  
  12.                 Exit Function
  13.             End If
  14.         Next
  15.         Return IsProcessRunning
  16.     End Function
  17.  
  18. End Module
  19.  
  20.  

Please advise...
Dec 5 '12 #1

✓ answered by Rabbit

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.selectedItem.ToString.

Share this Question
Share on Google+
5 Replies


Rabbit
Expert Mod 10K+
P: 12,382
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.selectedItem.ToString.
Dec 5 '12 #2

P: 4
Hi Rabbit...
Thanks for offering to help me on this -
i change the line as you suggested to
Expand|Select|Wrap|Line Numbers
  1. 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(strObject).InstancesOf("win32_process")

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
Dec 6 '12 #3

P: 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
Dec 6 '12 #4

P: 4
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
Dec 6 '12 #5

P: 1
You should use this
Expand|Select|Wrap|Line Numbers
  1.  Dim strComputer As String = frmStart.cmbMainFrm_PcList.Text.ToUpper
Nov 20 '13 #6

Post your reply

Sign in to post your reply or Sign up for a free account.