Results 1 to 9 of 9

Thread: Music Notes through For loops?`

  1. #1

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Music Notes through For loops?`

    I have a program with two list boxes, one for the current key and one for the new key, titled CurrentKey and TranseposeKey.

    I want to know if there is a way to show the new chords through for loops instead of massive if-then statements.

  2. #2

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    Better question, now that I think I've figured out how to do what I needed...

    Can I assign values to the members of a list box? i.e. Two list boxes, 12 variables each, but they are letters, and if I could assign values to those so that if user selected "C", VB would use value "4"... Can I do that?

  3. #3
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    In addition to the "List" property (which is the text you add via AddItem), the listbox also has an "ItemData" property, which is a long integer that you can use to assoicate a numeric value with each item. You can load the listboxes as follows (the NewIndex property refers to most recently added item) :
    List1.AddItem "A"
    List1.ItemData(List1.NewIndex) = 1
    List1.AddItem "A#/Bb"
    List1.ItemData(List1.NewIndex) = 2
    List1.AddItem "B"
    List1.ItemData(List1.NewIndex) = 3
    List1.AddItem "C"
    List1.ItemData(List1.NewIndex) = 4
    List1.AddItem "C#/Db"
    List1.ItemData(List1.NewIndex) = 5
    etc.
    "It's cold gin time again ..."

    Check out my website here.

  4. #4

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    In which case I still have a bunch of If statements being used. I'm thinking that if I can find a value difference between the values of the two list boxes, I can give the label the right value...

    Maybe a quick something like this...

    VB Code:
    1. Private Sub cmdTranspose_Click()
    2. 'CurrentKey and TranseposeKey are ListBoxes
    3. 'There are two control arrays of labels, one for the static notes and the other for the transposed notes, named lblBase and lblNote, respectively
    4.  
    5.    Dim diff As Integer
    6.    Dim temp As Integer
    7.  
    8.    If CurrentKey.ItemData - TranseposeKey.ItemData < 0 Then
    9.       diff = CurrentKey.ItemData - (TranseposeKey.ItemData - 12)
    10.    Else
    11.       diff = CurrentKey.ItemData - TranseposeKey.ItemData
    12.    End If
    13.  
    14.    For temp = (diff + 1) To 12
    15.       lblNote(temp) = lblBase(diff + temp)
    16.    Next temp
    17.  
    18.    For temp = 1 To diff
    19.       lblNote(temp) = lblBase(12 - diff)
    20.    Next temp
    21.  
    22. End Sub

    It gives me errors on the .ItemData part, so what property defines the item value?

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    I could give suggestions if you told me what you are trying to do.
    You could use SELECT CASE instead of IF statements.

  6. #6

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    That would accomplish pretty much the same thing as the If statements, just in a more orderly fashion...

    I'll try and explain this to the best of my ability. The user is going to select the current key of the song to be transposed. Then they are going to select the key in which the song should be in. When they hit the transpose button, the program is going to tell them that the A chord should now be this, B should be this, and on and on and on. I know what I'm trying to do, I just don't know the ListBox properties well enough to pull it off.

    What property returns a value of the selected item? Say, I select "B", which is the third item in the ListBox. What property would return a value of 3 for me to use?

  7. #7

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    Combo Boxes... Sorry...

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    the index is always one less than the item that you have selected.
    that's because they are zero based.
    Why not just use a formula.

    Code:
    newchord = (oldchord + transposesteps ) Mod 12
    if you want to transpose everything up one key, then you would add 2 half-steps. oldchord would be 1, and newchord woud be 3.
    MOD 12 limits them to 1-12 only. Four keys would be 6 half-steps, etc.

  9. #9
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    The ListIndex property tells you which item is selected (for a normal, not multi-select listbox).
    The "List" property array returns the text of the selected item, the "ItemData" property array returns the associated numeric value of the selected item.

    So List1.List(List1.ListIndex) gives you the text,
    List1.ItemData(List1.ListIndex) gives you the associated value.
    "It's cold gin time again ..."

    Check out my website here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width