PDA

View Full Version : 0>5 and 5<0 both true?!



truszko1
06-07-2011, 12:09 PM
Hey, guys!
I am having a quite frustrating issue with my macro.
So I have created a userform that loads data from a scripting.dictionary. It fills the ListBox with entires. Now, there is a command button called "Edit" which allows editing the entries. Each entry has a title and a body associated with it.

The feature I am struggling with is "Position number"
Users are allowed to manipulate an order of the entries of the list (I tried doing it with MouseDown, MouseUp, but it was a fail). The code I have written works when going down the list, and it doesn't work when going up the list.

Here is a simplified version of it:
If defaultEntryPosition < ComboBox1 Then
'defaultEntryPosition --- highlighted entry
'ComboBox1 --- wanted position
For X = 0 To ComboBox1 - 1
If X < defaultEntryPosition Then
UserForm1.ListBox1.ListIndex = 0
title = UserForm1.ListBox1.Text
body = dBz(title)
dBz.Remove (title)
dBz.Add title, body
UserForm1.ListBox1.AddItem b(X)
UserForm1.ListBox1.RemoveItem 0
ElseIf X > defaultEntryPosition Then
UserForm1.ListBox1.ListIndex = 1
title = UserForm1.ListBox1.Text
body = dBz(title)
dBz.Remove (title)
dBz.Add title, body
UserForm1.ListBox1.AddItem b(X)
UserForm1.ListBox1.RemoveItem 1
End If
Next

UserForm1.ListBox1.ListIndex = 0
title = UserForm1.ListBox1.Text
body = dBz(title)
dBz.Remove (title)
dBz.Add title, body
UserForm1.ListBox1.AddItem b(defaultEntryPosition)
UserForm1.ListBox1.RemoveItem UserForm1.ListBox1.ListIndex

For X = ComboBox1 To UserForm2.ListBox1.ListCount - 1
UserForm1.ListBox1.ListIndex = 0
title = UserForm1.ListBox1.Text
body = dBz(title)
dBz.Remove (title)
dBz.Add title, body
UserForm1.ListBox1.AddItem b(X)
UserForm1.ListBox1.RemoveItem UserForm1.ListBox1.ListIndex
Next
ElseIf defaultEntryPosition > ComboBox1 Then
MsgBox ("")
End If
SaveToFile

defaultEntryPosition < ComboBox1 is true when going down the list
defaultEntryPosition > ComboBox1 is true when going up the list

at least it is a way it should be, but it's not. When I implement this piece of code, right before the entire If-net is run, I get two "true" windows:
msgbox(defaultEntryPosition < ComboBox1)
msgbox(defaultEntryPosition > ComboBox1)

truszko1
06-07-2011, 12:16 PM
Here is a PrtSc

tinypic.com/view.php?pic=svkzz7&s=7