I have a combo box called cbonumberstrands an option button called option live 1 a textbox called txtanchorblockle1 a textbox called txtcastingle1 The theory is as follows User selects numberstrands ie 2s, (cbonumberstrands) if optionlive1=true then values to be written into txtboxes accordingly problem is if user selects 2s then selects 3s the textboxes dont update 'set up first end '----------------------------- Private Sub OptionLive1_Click() If (cboStrandType.Text) = "12.7mm" Then End If If OptionLive1 = True Then 'clear combobox Cbofirstend.Clear Cbofirstend.AddItem "Edge" Cbofirstend.AddItem "Pan" Cbofirstend.ListIndex = 0 End If If (cboNumberStrands) = "2s" Then Txtductsize.Text = "70" Txtanchorblockle1.Text = "ab205" Txtcastingle1.Text = "ac205" End If If (cboNumberStrands.Text) = "3s" Then Txtductsize.Text = "80" Txtanchorblockle1.Text = "ab305" Txtcastingle1.Text = "ac305" End If If (cboNumberStrands) = "4s" Then Txtductsize.Text = "90" Txtanchorblockle1.Text = "ab405" Txtcastingle1.Text = "ac405" End If If (cboNumberStrands) = "5s" Then Txtductsize.Text = "100" Txtanchorblockle1.Text = "ab505" Txtcastingle1.Text = "ac505" End If If cboStrandType.Text = "15.2mm" Then End If If (cboNumberStrands) = "6s" Then Txtductsize.Text = "76" Txtanchorblockle1.Text = "ab206" Txtcastingle1.Text = "ac206" End If If (cboNumberStrands) = "7s" Then Txtductsize.Text = "86" Txtanchorblockle1.Text = "ab306" Txtcastingle1.Text = "ac306" End If If (cboNumberStrands) = "8s" Then Txtductsize.Text = "96" Txtanchorblockle1.Text = "ab406" Txtcastingle1.Text = "ac406" End If If (cboNumberStrands) = "9s" Then Txtductsize.Text = "106" Txtanchorblockle1.Text = "ab506" Txtcastingle1.Text = "ac506" End If End Sub
Look at the syntax If (cboNumberStrands) = "2s" Then If (cboNumberStrands.Text) = "3s" Then one has ".Text" and the other does not
still it makes no difference if they are all the same. I have tried all.text, all .text in parentheses etc. I dont know where else to go from here
john, Do you have any code in the cboNumberStrands_Change event? This will run whenever the user changes the combo box from "2s" to "3s". The option button event that you posted will only run when the user clicks on it. The code you posted seems like it should be in cboNumberStrands_Change. James
this is the only code to the cboNumberStrands_change area Private Sub CboStrandType_Change() If cboStrandType.Text = "12.7mm" Then cboNumberStrands.Clear cboNumberStrands.AddItem "2s" cboNumberStrands.AddItem "3s" cboNumberStrands.AddItem "4s" cboNumberStrands.AddItem "5s" cboNumberStrands.ListIndex = 0 Else cboNumberStrands.Clear cboNumberStrands.AddItem "6s" cboNumberStrands.AddItem "7s" cboNumberStrands.AddItem "8s" cboNumberStrands.AddItem "9s" cboNumberStrands.ListIndex = 0 End If End Sub
cboNumberStrands.ListIndex = 0 What is your purpose with this? Might want to read up on it. Not necessary here and it's firing your event when you probably don't want it fired...It will also fire your event whenever you start your program. gl Paul
You are correct .Text is the default property of a text box. Tom Closs INCAT www.incat.com all.text, all .text in parentheses etc. I dont know where else to go from here
If you have your combo box set too only a drop down list the change event doesn't fire. If this is true try placing the change event code into the click event. This will fire after the user picks a new value. Don't forget to read the new value. Tom Closs INCAT www.incat.com
John, James hit it on the head above, you don't have any code in the change event for cboNumberStrands_Change? I added the option button code to the combobox and it works fine. Good place to use the debugger. Put a breakpoint on your Changes to see when they are firing and what is changing. Also you might want to use the following for your change event so once the right value is found you exit the If statement. Otherwise multiple if statements are executing for nothing. If else If else: end If gl Paul
i must be losing something in the translation here. mine would not work. the way i expect. it seems that i have to pick option dead after i change number of stands and then pick option live before the casting and anchor block will work correctly. Please see earlier post when i attached project file of full code John
I would suggest something like the following create subs that check the pertinent values any time a significant change might occur then call that sub in the change event for any of the values that might change I'd also convert the multiple ifs to select case..just for easier reading to me...fwiw 'here i'd call the same sub on any changes that would be appropriate Private Sub cboNumberStrands_Change() CalculateBlocks End Sub Private Sub OptionLive1_Click() CalculateBlocks End Sub Private Sub OptionLive2_Click() CalculateBlocks End Sub Private Sub OptionDead1_click() CalculateBlocks End Sub Private Sub OptionDead2_click() CalculateBlocks End Sub 'etc - any other controls that should update the textboxes 'main sub to check values Private Sub CalculateBlocks() CalculateStrandType CalculateEnds CalculateStrands End Sub 'individual subs to check different aspects of settings Sub CalculateStrandType() Select Case cboStrandType Case Is = "12.7mm" cboNumberStrands.Clear cboNumberStrands.AddItem "2s" cboNumberStrands.AddItem "3s" cboNumberStrands.AddItem "4s" cboNumberStrands.AddItem "5s" cboNumberStrands.ListIndex = 0 Case Is = "15.2mm" cboNumberStrands.Clear cboNumberStrands.AddItem "6s" cboNumberStrands.AddItem "7s" cboNumberStrands.AddItem "8s" cboNumberStrands.AddItem "9s" cboNumberStrands.ListIndex = 0 Case Else 'do something else End Select End Sub Private Sub CalculateEnds() If OptionLive1 = True Then 'clear combobox Cbofirstend.Clear Cbofirstend.AddItem "Edge" Cbofirstend.AddItem "Pan" Cbofirstend.ListIndex = 0 End If If OptionLive2 = True Then 'clear combobox' Cbosecondend.Clear Cbosecondend.AddItem "Edge" Cbosecondend.AddItem "Pan" Cbosecondend.ListIndex = 0 End If If OptionDead1 = True Then 'clear combobox' Cbofirstend.Clear Cbofirstend.AddItem "Bulb" Cbofirstend.AddItem "Swage" Cbofirstend.ListIndex = 0 Txtanchorblockle1.Text = " " Txtcastingle1.Text = " " End If If OptionDead2 = True Then 'clear combobox' Cbosecondend.Clear Cbosecondend.AddItem "Bulb" Cbosecondend.AddItem "Swage" Cbosecondend.ListIndex = 0 Txtanchorblockle2.Text = " " Txtcastingle2.Text = " " End If End Sub Private Sub CalculateStrands() Select Case cboNumberStrands Case Is = "2s" Txtductsize.Text = "70" Txtanchorblockle1.Text = "ab205" Txtcastingle1.Text = "ac205" Case Is = "3s" Txtductsize.Text = "80" Txtanchorblockle1.Text = "ab305" Txtcastingle1.Text = "ac305" Case Is = "4s" Txtductsize.Text = "90" Txtanchorblockle1.Text = "ab405" Txtcastingle1.Text = "ac405" Case Is = "5s" Txtductsize.Text = "100" Txtanchorblockle1.Text = "ab505" Txtcastingle1.Text = "ac505" Case Is = "6s" Txtductsize.Text = "76" Txtanchorblockle1.Text = "ab206" Txtcastingle1.Text = "ac206" Case Is = "7s" Txtductsize.Text = "86" Txtanchorblockle1.Text = "ab306" Txtcastingle1.Text = "ac306" Case Is = "8s" Txtductsize.Text = "96" Txtanchorblockle1.Text = "ab406" Txtcastingle1.Text = "ac406" Case Is = "9s" Txtductsize.Text = "106" Txtanchorblockle1.Text = "ab506" Txtcastingle1.Text = "ac506" End Select End Sub don't know if that is any help or not just an idea Mark the way i expect. it seems that i have to pick option dead after i change number of stands and then pick option live before the casting and anchor block will work correctly. Please see earlier post when i attached project file of full code
iF I USE THIS CODE THEN I SEEM TO BE GETTING MULTIPLE COPIES OF 2S,3S ETC IN THE NUMBER OF STRANDS COMBO. MAYBE I AM DOING SOMETHING WRONG. i AM NO WHER NEAR AN EXPERT IN THIS STUFF. YOUR HELP APPRECIATED
sorry john, I was just trying to show you an approach as an example - not really finished code. My idea was to divide the functions that read the different variables(combo or option button settings) into separate subs In other words any time a combo box changes you want to recalculate some value(textbox entry). Also any time an option button changes you also want to recalculate some value(textbox entry). Also any time the strand type changes you want to recalculate some value. So my thought was to separate the function that read the settings from the events that call that function. Then just call the same sub from all the change events so that any thing that changes (combo or option etc) would force a recalc. I just did it kind of quick so i missed the multiple adding part... I think when the form is being initialized the calc sub is being called multiple times and for some reason the .clear line isn't running - i'll look at it closer if i get time later. sorry i'm kinda busy these days. right - just checked and the calculate block fucniton is called about 50 times before the form shows probably evertime a v alue is entered in every one of the combos on setup so major problem in my idea - need to add a boolean or something so it isn't called at setup - just by user intervention There may be other problems with what i posted as well, i didnt have time to totally understand everything you're doing there - just the basic idea - so you need to review what needs to happen when strand type changes, end type etc and adjust the subs accordingly. My way may not be any good, it was just a thought after looking at your code. sorry i didn't have more time to look at it closer (ps i'm just a beginner too) Mark IN THE NUMBER OF STRANDS COMBO. MAYBE I AM DOING SOMETHING WRONG. i AM NO WHER NEAR AN EXPERT IN THIS STUFF. YOUR HELP APPRECIATED
ok, again - this is just a sample for ideas - see if you can find anything useful here Option Explicit Private bDoneInit As Boolean Private Sub CalcStrandType() Select Case cboStrandType Case Is = "12.7mm" InitNumStrands12 Case Is = "15.2mm" InitNumStrands15 Case Else 'do something else End Select End Sub '--------------------------- Private Sub InitNumStrands12() cboNumberStrands.Clear cboNumberStrands.AddItem "2s" cboNumberStrands.AddItem "3s" cboNumberStrands.AddItem "4s" cboNumberStrands.AddItem "5s" cboNumberStrands.ListIndex = 0 'numstrands starts 2s CalcStrandNum End Sub '--------------------------- Private Sub InitNumStrands15() cboNumberStrands.Clear cboNumberStrands.AddItem "6s" cboNumberStrands.AddItem "7s" cboNumberStrands.AddItem "8s" cboNumberStrands.AddItem "9s" cboNumberStrands.ListIndex = 0 CalcStrandNum End Sub '--------------------------- Private Sub CalcEnds() If OptionLive1 = True Then 'clear combobox Cbofirstend.Clear Cbofirstend.AddItem "Edge" Cbofirstend.AddItem "Pan" Cbofirstend.ListIndex = 0 End If If OptionLive2 = True Then 'clear combobox' Cbosecondend.Clear Cbosecondend.AddItem "Edge" Cbosecondend.AddItem "Pan" Cbosecondend.ListIndex = 0 End If If OptionDead1 = True Then 'clear combobox' Cbofirstend.Clear Cbofirstend.AddItem "Bulb" Cbofirstend.AddItem "Swage" Cbofirstend.ListIndex = 0 Txtanchorblockle1.Text = " " Txtcastingle1.Text = " " End If If OptionDead2 = True Then 'clear combobox' Cbosecondend.Clear Cbosecondend.AddItem "Bulb" Cbosecondend.AddItem "Swage" Cbosecondend.ListIndex = 0 Txtanchorblockle2.Text = " " Txtcastingle2.Text = " " End If End Sub '--------------------------- Private Sub CalcStrandNum() Select Case cboNumberStrands Case Is = "2s" Txtductsize.Text = "70" Txtanchorblockle1.Text = "ab205" Txtcastingle1.Text = "ac205" Case Is = "3s" Txtductsize.Text = "80" Txtanchorblockle1.Text = "ab305" Txtcastingle1.Text = "ac305" Case Is = "4s" Txtductsize.Text = "90" Txtanchorblockle1.Text = "ab405" Txtcastingle1.Text = "ac405" Case Is = "5s" Txtductsize.Text = "100" Txtanchorblockle1.Text = "ab505" Txtcastingle1.Text = "ac505" Case Is = "6s" Txtductsize.Text = "76" Txtanchorblockle1.Text = "ab206" Txtcastingle1.Text = "ac206" Case Is = "7s" Txtductsize.Text = "86" Txtanchorblockle1.Text = "ab306" Txtcastingle1.Text = "ac306" Case Is = "8s" Txtductsize.Text = "96" Txtanchorblockle1.Text = "ab406" Txtcastingle1.Text = "ac406" Case Is = "9s" Txtductsize.Text = "106" Txtanchorblockle1.Text = "ab506" Txtcastingle1.Text = "ac506" End Select End Sub '--------------------------- Private Function FormDataIsValid() As Boolean FormDataIsValid = True If txtTendonID.Text = "" Then MsgBox "Enter a value for the tendon ID." txtTendonID.SetFocus FormDataIsValid = False Exit Function End If If TxtPourNumber.Text = "" Then MsgBox "Enter a value for the pour number." TxtPourNumber.SetFocus FormDataIsValid = False Exit Function End If If cboStrandType.Text = "" Then MsgBox "Enter a value for the strand type." cboStrandType.SetFocus FormDataIsValid = False Exit Function End If If cboNumberStrands.Text = "" Then MsgBox "Enter a value for the number of strands." cboNumberStrands.SetFocus FormDataIsValid = False Exit Function End If If Txtductsize.Text = "" Then MsgBox "Enter a value for the duct size." Txtductsize.SetFocus FormDataIsValid = False Exit Function End If ' If cboCastingDE.Text = "" Then 'this one ' MsgBox "Enter a value for the casting DE." ' cboCastingDE.SetFocus 'this one ' FormDataIsValid = False ' Exit Function ' End If ' If cboAnchorBlockDE.Text = "" Then ' MsgBox "Enter a value for the anchor block DE." ' cboAnchorBlockDE.SetFocus ' FormDataIsValid = False ' Exit Function ' End If End Function '--------------------------- Private Sub btnAddTendon_Click() Dim objBlockDefinition As AcadBlock Dim objBlockReference As AcadBlockReference Dim varAttributes As Variant Dim blnBlockExists As Boolean Dim varInsertionPoint As Variant Dim intIndex As Integer If FormDataIsValid Then Me.Hide ' Create the tendon block definition if it doesn't already exist. blnBlockExists = False For Each objBlockDefinition In ThisDrawing.Blocks If objBlockDefinition.Name = TENDON_BLOCK_NAME Then blnBlockExists = True Exit For End If Next objBlockDefinition If Not blnBlockExists Then CreateTendonBlock End If ' Insert an instance of the tendon block in modelspace. varInsertionPoint = ThisDrawing.Utility.GetPoint(, "Pick insertion point: ") Set objBlockReference = ThisDrawing.ModelSpace.InsertBlock(varInsertionPoint, _ TENDON_BLOCK_NAME, 1#, 1#, 1#, 0) ' Update the block ref's attributes. varAttributes = objBlockReference.GetAttributes For intIndex = LBound(varAttributes) To UBound(varAttributes) Select Case varAttributes(intIndex).TagString Case "ID" varAttributes(intIndex).TextString = txtTendonID.Text Case "POUR_NUMBER" varAttributes(intIndex).TextString = TxtPourNumber.Text Case "STRAND_type" varAttributes(intIndex).TextString = cboStrandType.Text Case "STRANDS" varAttributes(intIndex).TextString = cboNumberStrands.Text Case "LENGTH" varAttributes(intIndex).TextString = txtTendonLength.Text Case "CASTING" varAttributes(intIndex).TextString = Txtcastingle1.Text Case "COUPLER" varAttributes(intIndex).TextString = txtCouplingLE.Text Case "ANCHOR" varAttributes(intIndex).TextString = Txtanchorblockle1.Text ' Case "DEAD" ' varAttributes(intIndex).TextString = cboCastingDE.Text 'this one Case "POCKET_EDGE1" varAttributes(intIndex).TextString = "PAN" ' Case "POCKET_EDGE2" ' varAttributes(intIndex).TextString = "EDGE" ' You're missing several attributes aren't you? ' How are the pocket edge values calculated? End Select Next intIndex Unload Me End Else Exit Sub End If End Sub '--------------------------- Private Sub btnCancle_Click() 'don't need to hide first cause you're just disposing of it 'Me.Hide 'this is all you need Unload Me 'never use End - do a google search on this function 'End End Sub Private Sub Cbofirstend_Change() End Sub '--------------------------- Private Sub cboNumberStrands_Change() 'CalculateBlocks If bDoneInit Then CalcStrandNum End Sub 'set up first end of tendon' '----------------------------- Private Sub OptionLive1_change() If bDoneInit Then CalcEnds ' CalculateBlocks End Sub 'set up second end of tendon' '----------------------------- Private Sub OptionLive2_change() If bDoneInit Then CalcEnds ' CalculateBlocks End Sub '--------------------------- Private Sub OptionDead1_change() If bDoneInit Then CalcEnds ' CalculateBlocks End Sub '--------------------------- Private Sub OptionDead2_change() If bDoneInit Then CalcEnds ' CalculateBlocks End Sub 'set up coupler of tendon' '----------------------------- Private Sub OptionCoup_click() If optioncoup = True Then 'if true then txt box should 'show for various cases above txtCouplingLE.Text = "cb405" End If If optioncoup = False Then txtCouplingLE = "" End If End Sub 'add number of strands' '----------------------------- Private Sub CboStrandType_CHANGE() If bDoneInit Then CalcStrandType End Sub 'open userform' '----------------------------- Private Sub UserForm_Initialize() InitValues End Sub '--------------------------------- Private Sub InitValues() ' bDoneInit = False InitStrandType 'initends InitTendonLength bDoneInit = True End Sub '--------------------------------- Private Sub InitStrandType() cboStrandType.AddItem "12.7mm" cboStrandType.AddItem "15.2mm" cboStrandType.ListIndex = 0 'strand type starts 12.7 InitNumStrands12 End Sub '--------------------------------- Private Sub InitTendonLength() txtTendonLength.Text = strTendonLength txtTendonLength.Locked = True ' Calculated. Don't let user change. End Sub '--------------------------------- hth Mark IN THE NUMBER OF STRANDS COMBO. MAYBE I AM DOING SOMETHING WRONG. i AM NO WHER NEAR AN EXPERT IN THIS STUFF. YOUR HELP APPRECIATED