Author Topic: combobox  (Read 1915 times)

0 Members and 1 Guest are viewing this topic.

krampaul82

  • Guest
combobox
« 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.


David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: combobox
« Reply #1 on: August 17, 2007, 03:17:50 PM »
Looking now
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: combobox
« Reply #2 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.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: combobox
« Reply #3 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.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)