Linking two listboxes
Linking two listboxes
(OP)
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
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
RE: Linking two listboxes
It is probably easier to pass it via a regular work sheet variable and select 'hide arguments' so that the variable isn't seen.
RE: Linking two listboxes
RE: Linking two listboxes
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
RE: Linking two listboxes
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?