TheSwamp

Code Red => VB(A) => Topic started by: krampaul82 on August 17, 2007, 03:06:02 PM

Title: combobox
Post by: krampaul82 on August 17, 2007, 03:06:02 PM
I am new to vba and know enough to be stupid. so please be kind to me.

I am trying to create a vba script that will insert a block into a current ACAD2008 drawing.  A certain model has different part numbers/ extensions, so i thought i would use a combo box / case statement to allow the user to choose which item he needs. it partially works but the problem is that it always grabs the first item in the list only even though another item is selected. here is the code, (dvb attached) any help would be appreciated.

Title: Re: combobox
Post by: David Hall on August 17, 2007, 03:17:50 PM
Looking now
Title: Re: combobox
Post by: Keith™ on August 17, 2007, 03:22:57 PM
Ok, a couple of problems ....

You are trying to read the text of the button, not the combobox i.e.

Code: [Select]
Select Case cmd_sensor_t7770a.Text
     Case t7770a1006    'Calls sub from Module_sensor
          Sensor_t7770a1006_get
     Case t7770a1022    'Calls sub from Module_sensor
         Sensor_t7770a1022_get
     Case "t7770a2004"   'Calls sub from Module_sensor
           Sensor_t7770a2004_get
     Case t7770a2012    'Calls sub from Module_sensor
           Sensor_t7770a2012_get
     Case t7770a3002   'Calls sub from Module_sensor
           Sensor_t7770a3002_get
   End Select
 

You should be reading the contents of the associated combo box as so:

Code: [Select]
Select Case ComboBox_t7770a.Text
     Case t7770a1006    'Calls sub from Module_sensor
          Sensor_t7770a1006_get
     Case t7770a1022    'Calls sub from Module_sensor
         Sensor_t7770a1022_get
     Case "t7770a2004"   'Calls sub from Module_sensor
           Sensor_t7770a2004_get
     Case t7770a2012    'Calls sub from Module_sensor
           Sensor_t7770a2012_get
     Case t7770a3002   'Calls sub from Module_sensor
           Sensor_t7770a3002_get
   End Select

Further, you should also be comparing the values as text strings, as you have it written the code compares the cases to variables. i.e. you text comparisons must be in quotes as follows:

Code: [Select]
Select Case ComboBox_t7770a.Text
     Case "t7770a1006"    'Calls sub from Module_sensor
          Sensor_t7770a1006_get
     Case "t7770a1022"    'Calls sub from Module_sensor
         Sensor_t7770a1022_get
     Case "t7770a2004"   'Calls sub from Module_sensor
           Sensor_t7770a2004_get
     Case "t7770a2012"    'Calls sub from Module_sensor
           Sensor_t7770a2012_get
     Case "t7770a3002"   'Calls sub from Module_sensor
           Sensor_t7770a3002_get
   End Select

You have quite a few things to correct, but once you do it should work as desired.
Title: Re: combobox
Post by: David Hall on August 17, 2007, 03:26:05 PM
Couple of things I see right away.  You are repeating (retyping) the same code over and over just changing the block name, so maybe we can condense that into 1 function with the blockname as an argument.