×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Linking two listboxes

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
Replies continue below

Recommended for you

RE: Linking two listboxes

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.

 

RE: Linking two listboxes

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.

RE: Linking two listboxes

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
 

RE: Linking two listboxes

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?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close