TheSwamp
Code Red => VB(A) => Topic started by: David Hall on April 26, 2007, 03:03:02 PM
-
something that seems so easy is eluding me. I have a form named frmSetup which has 3 frames, 1 of which is named frmBusCenterLine which has 2 comboboxes, named cboBCLHighBus & cboBCLLowBus. I am trying to populate the 2 combo boxes on the fly, but to no avail. Autocad/VBA Help shows this
Private Sub UserForm_Initialize()
ScrollBar1.Max = 400
ScrollBar1.Min = 10
ScrollBar1.Value = 100
Label1.Caption = "10 -----Percent of " _
& "Original Size---- 400"
Label2.Caption = ScrollBar1.Value
Frame1.TextBox1.Text = "Enter your text here."
Frame1.TextBox1.MultiLine = True
Frame1.TextBox1.WordWrap = True
Frame1.Zoom = ScrollBar1.Value
End Sub
So, given that example, why cant I get values to go to the cbo boxes?
These are the things I have tried so far
frmSetup.frmBusCenterLine.cboBCLHighBus.AddItem "7'-6"""
frmSetup.cboBCLHighBus.AddItem "7'-8"""
frmSetup.frmBusCenterLine.Controls.Item("cboBCLHighBus").AddItem "dsh"
cboBCLLowBus.AddItem "8'-0"""
cboBCLLowBus.AddItem "8'-6"""
-
Have you clicked on the combo box to check if the info is really getting in there or not? If you don't add ....ListIndex = 0, the combo box will appear to be empty. See below... this works for me.
Public Sub Main()
Load frmSetup
frmSetup.cboBCLHighBus.AddItem "7'-8"""
frmSetup.cboBCLLowBus.AddItem "8'-0"""
frmSetup.cboBCLLowBus.AddItem "8'-6"""
frmSetup.cboBCLHighBus.ListIndex = 0
frmSetup.cboBCLLowBus.ListIndex = 0
frmSetup.Show
End Sub
-
Matt, are you using frames? I have never had any problem filling up a cbo box. I tried adding the listindex part, but its still a no go.
here is the form
-
Here's the little proggy I threw together.
-
OK, one thing I see that we are doing differently is your loading from a module, where as I am trying t use the FormInitialize area. Yours worked by the way. Let me see if I can adapt mine really quickly.
-
OK, that worked perfectly. My question is why.... what makes it different to pass those from a module to the form, than to load them via the form init?
-
Here it is using the Initialize event. Still works. Not sure what you're doing differently? Can you post it or PM me with the code?
-
No need, just hit me with a baseball bat :pissed: :pissed: :pissed:
I went to copy the code to PM you, and saw that I had selected the wrong event by accident, and this whole time, was populating a different event for the form, one which never runs, so it never filled up the boxes. DUH!!!
I guess I should have checked there. Force of habit, just missed with the mouse.
-
thanks for making me slow down and re-look at the code
-
thanks for making me slow down and re-look at the code
No problem... Been there before myself (many times). :wink:
-
Ok, next question. I am not sure how to word this so bear with me. Given the form pic above, can I make an enumeration of the controls inside one of the frames, and capture the selected control by number (thinking about an enumeration being zero-based, get the selected control 0-?)
-
Or maybe an array...
-
This may help, I remember battling through the same thing and forgot the answer.
As far as I remember groupname is better than frames.
Option Explicit
Private C As Control
Private F As Frame
Private Sub CommandButton1_Click()
Me.HIDE
Dim i As Integer
For Each C In Controls
If TypeOf C Is Frame Then
Set F = C
For i = 0 To F.Controls.Count - 1
If F.Controls.Item(i).Name = F.ActiveControl.Name Then
Debug.Print i, F.ActiveControl.Name
End If
If F.Controls.Item(i).Value = True Then
Debug.Print "Value", F.ActiveControl.Name
End If
Next
End If
Next
End Sub
-
No need, just hit me with a baseball bat :pissed: :pissed: :pissed:
I went to copy the code to PM you, and saw that I had selected the wrong event by accident, and this whole time, was populating a different event for the form, one which never runs, so it never filled up the boxes. DUH!!!
I guess I should have checked there. Force of habit, just missed with the mouse.
Your username says it all
:ugly:
How is it going cmdr?
-
what are you wanting to do with the controls? There may be a different solution that is easier/better, if we have an idea of what you need to do.
-
An array of controls in VBA is not possible like it is in straight VB. You can kinda "fudge" it, but I've always found that it's easier to work with controls that have unique names and not CombBox(0), ComboBox(1), etc... Call it "personal preference", but I think it's easier that way.
-
What I was trying to do was determine which option was selected. I was thinking of the array (I learned to do that in C#) where I could cycle through the array and find the selected control. I ended up using select case to parse the controls. Is there a better way? Bryco, I saw your post, but have been in meetings all day, so I haven't had a chance to look into that yet.
Dim booTrue As Boolean
booTrue = True
Select Case booTrue
Case frmSetup.optBS3.Value
ThisDrawing.SetVariable "USERI4", 3
Case frmSetup.optBS4.Value
ThisDrawing.SetVariable "USERI4", 4
Case frmSetup.optBS5.Value
ThisDrawing.SetVariable "USERI4", 5
Case frmSetup.optBS6.Value
ThisDrawing.SetVariable "USERI4", 6
End Select
Select Case booTrue
Case frmSetup.optVC138kv.Value
ThisDrawing.SetVariable "USERS2", "138"
Case frmSetup.optVC69kv.Value
ThisDrawing.SetVariable "USERS2", "69"
Case frmSetup.optVC46kv.Value
ThisDrawing.SetVariable "USERS2", "46"
Case frmSetup.optVC230kv.Value
ThisDrawing.SetVariable "USERS2", "230"
Case frmSetup.optVC345kv.Value
ThisDrawing.SetVariable "USERS2", "345"
End Select
-
Randall or the llama had some code to fool vba into thinking there were control arrays. I tried it and did not like it so much. With the few number of controls you have, you are better off doing it how you currently are.
Are you calling those user variables from a lisp routine or vba routine?
-
VBA
-
is the vba routine inside this project, or a different one?
-
this one