Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking two listboxes

Status
Not open for further replies.

camerongtaylor

Structural
Apr 22, 2008
1
Can anyone tell me whats wrong with my code?

First List box:

Rem Initialize List Box
ListBox.ResetContent()

Rem Add Strings here as needed
ListBox.AddString("Cast-in")
ListBox.AddString("Post-installed")

Rem Initialize Selection If desired
ListBox.CurSel = 0

Sub ListBoxEvent_Start()
End Sub

Sub ListBoxEvent_Exec(Inputs,Outputs)
sel = ListBox.CurSel

' Force sel to be a valid value, rather than -1
If sel < 0 Then
sel = 0
End If

' Highlight the selected value
ListBox.CurSel = sel

Outputs(0).Value = ListBox.GetText(sel)
If sel = 0 Then
Outputs(1).Value = 24
End If
If sel = 1 Then
Outputs(1).Value = 17
End If

End Sub

Sub ListBoxEvent_Stop()
Rem TODO: Add your code here
End Sub

Sub ListBox_SelChanged()
ListBox.Recalculate()
End Sub

Sub ListBox_DblClick()
ListBox.Recalculate()
End Sub



Second List Box:

Sub ListBoxEvent_Start()
sel = ListBox.CurSel
ListBox.ResetContent()
anchor = Worksheet.GetValue("AnchorSelection")
If anchor = "Cast-in" Then
ListBox.AddString "Cracked"
ListBox.AddString "Uncracked"
ElseIf mats = "Post-installed" Then
ListBox.AddString "Cracked"
ListBox.AddString "Uncracked"
End If
ListBox.CurSel = sel
End Sub

Sub ListBoxEvent_Exec(Inputs,Outputs)
sel = ListBox.CurSel

' Force sel to be a valid value, rather than -1
If sel < 0 Then
sel = 0
End If

' Highlight the selected value
ListBox.CurSel = sel

anchor = Inputs(0).Value
If sel >= 0 Then
Outputs(0).Value = ListBox.GetText(sel)
If anchor = "Cast-in" Then
If sel = 0 Then
Outputs(1).Value = 1.0
ElseIf sel = 1 Then
Outputs(1).Value = 1.25
End If
ElseIf anchor = "Post-installed" Then
If sel = 0 Then
Outputs(1).Value = 1.0
ElseIf sel = 1 Then
Outputs(1).Value = 1.4
End If
Else
Outputs(1).Value = 0
End If
Else
Outputs(0).Value = "No selection"
Outputs(1).Value = "N/A"
End If
End Sub

Sub ListBoxEvent_Stop()
Rem TODO: Add your code here
End Sub

Sub ListBox_SelChanged()
ListBox.Recalculate()
End Sub

Sub ListBox_DblClick()
ListBox.Recalculate()
End Sub




All im trying to do is get two different selections for one output in box 2, and the outputs from box two vary based on the selection in box 1. Any insight would help. Thanks.

Cameron
 
Replies continue below

Recommended for you

The get value only gets the value at the very end of the sheet and you are probably tieing the code in knots during the re-calculate. You have to decide when the value comes into existance and when it is being asked for, etc.


It is probably easier to pass it via a regular work sheet variable and select 'hide arguments' so that the variable isn't seen.

 
If you figure this out, can you let me know? I think I'm having a similar problem. I need my output variable to be dependent on two input variables from prior listboxes. I can't find an example using two inputs anywhere.
 
The values have to be passed.
So that means each previous list box should pass their values via a mathcad variable (in the examples the often turn off the show attributes/variable/results). (i.e. you have an 'output' value from each)

You have now got the two variables from the previous listboxes, these are passes as inputs to the next component as required.

The right click on the region/component allows you to add/delete extra inputs and outputs. You need this to make sure the internal VB code matches mathcad's viewpoint.

Philip
 
I have my output variables from previous listboxes and I have added the inputs, but my failure is in editing the script to account for the second input.

I'm not a programmer and haven't ever taken a course in it so everything I've done so far has been self-taught. Do you have an example of the script using two inputs you could post or attach?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor