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.
Printable View
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.
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?
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.
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:
Private Sub cmdTranspose_Click() 'CurrentKey and TranseposeKey are ListBoxes 'There are two control arrays of labels, one for the static notes and the other for the transposed notes, named lblBase and lblNote, respectively Dim diff As Integer Dim temp As Integer If CurrentKey.ItemData - TranseposeKey.ItemData < 0 Then diff = CurrentKey.ItemData - (TranseposeKey.ItemData - 12) Else diff = CurrentKey.ItemData - TranseposeKey.ItemData End If For temp = (diff + 1) To 12 lblNote(temp) = lblBase(diff + temp) Next temp For temp = 1 To diff lblNote(temp) = lblBase(12 - diff) Next temp End Sub
It gives me errors on the .ItemData part, so what property defines the item value?
I could give suggestions if you told me what you are trying to do.
You could use SELECT CASE instead of IF statements.
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?
Combo Boxes... Sorry...:cry:
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.
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.Code:newchord = (oldchord + transposesteps ) Mod 12
MOD 12 limits them to 1-12 only. Four keys would be 6 half-steps, etc.
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.