Click to See Complete Forum and Search --> : huge bug in VB5!


January 5th, 2000, 02:49 PM
i made a combobox named combo1 = everything is fine. I insert 7 items in it, so combo1.listcount = 9, Now, on the combo1.click protocol, I enter the following code:

If Combo1.ListIndex = 0 Then
message$ = InputBox("Enter the line of text you wish the person to see in your program.", "Message")
truemessage$ = "Echo " + message$
frmDocument.List1.AddItem (truemessage$)
Add2$ = "[Text: " + message$ + "]"
List1.AddItem (Add2$)
five$ = "[Command: " + truemessage$ + " | Program = True"
List1.AddItem (five$)
Exit Sub
End If
If Combo1.ListIndex = 1 Then
comment$ = InputBox("Enter the comment. Remember, the user cannot see comments, but they exist only for the program!", "Comment")
truecomment$ = "Rem " + comment$
frmDocument.List1.AddItem (truecomment$)
Add$ = "[Comment: " + comment$ + "]"
List1.AddItem (Add$)
four$ = "[Command: " + truecomment$ + " | Program = True]"
List1.AddItem (four$)
Exit Sub
End If
If Combo1.ListIndex = 2 Then
file$ = InputBox("Enter the full file path in the textbox below. Remember: C:\something.txt is right, whereas if you enter something.txt then the file must exist in the same directory as this program!", "File.")
label2.Text = "New Command Entered!"
List1.AddItem ("[Erase: " + file$ + "]")
v1.Caption = "del " + file$
Command1.Enabled = True
Exit Sub
End If
If Combo1.ListIndex = 3 Then
Dire$ = InputBox("Enter the name of the directory you wish to competely erase below. Remember: C:\something is right, as is C:\something\, but something is wrong! If you wish to erase the whole tree, then enter *.* below. Go to help --> commands for more information.", "Directory.")
prompting = MsgBox("Do you wish to give the user the option to see if he/she wants the file to be erased? In other words, do you want to prompt the user to see if the directory will be erased or not?", vbYesNoCancel, "Prompt")
If prompting = vbYes Then ve$ = ""
If prompting = vbNo Then ve$ = " /y"
If prompting = vbCancel Then Exit Sub
label2.Text = "New Command Entered!"
List1.AddItem ("[Rmdir: " + Dire$ + ve$ + "]")
v1.Caption = "Deltree " + Dire$ + ve$
Command1.Enabled = True
Exit Sub
End If
If Combo1.ListIndex = 4 Then
label2.Text = "Pause Break Entered In Program!"
List1.AddItem ("[----------------------------------------------]")
frmDocument.List1.AddItem ("Pause")
Exit Sub
End If
If Combo1.ListIndex = 6 Then
thelist$ = InputBox("Enter the directory you wish to be listed. You can enter a * string to view filenames. Example: if you want to see all .DOC files in C:\my, then enter C:\my\*.DOC!", "Directory Listing")
askyou = MsgBox("If there are many files, the user might not be able to see all of them! By adding a constant, however, all can be seen. Do you wish to add that constant?", vbYesNo, "Constant")
End If
If askyou = vbYes Then
thetruelist$ = thelist$ + " | MORE"
thereallist$ = "dir " + thetruelist$
v1.Caption = thereallist$
List1.AddItem ("[Dir List: " + thelist$ + "]")
Command1.Enabled = True
Exit Sub
Else
Exit Sub
End If
If frmfunctions.Combo1.ListIndex = 7 Then
d123$ = InputBox("Enter the new current directory you would like to be in the program. Include the full drive! If you want to change to C:\mydir, then mydir is wrong, C:\mydir is right! See help for what this does.", "Directory Change")
F123$ = "cd " + d123$
v1.Caption = F123$
Command1.Enabled = True
Exit Sub
End If
If frmfunctions.Combo1.ListIndex = 8 Then
T123$ = InputBox("Enter only the DRIVE LETTER you want to change to! If you want to change to drive C, do not enter C: or C:\, but only enter C!", "Drive Change")
T234$ = T123$ + ":\"
v1.Caption = T234$
Command1.Enabled = True
Exit Sub
End If

I am aware combo1.listindex = 5 is not there; it is not made yet! It works when the user selects any item up until combo1.listindex = 6. After this, however, at 7 and 8, nothing happens. The code is exactly the same in every other combo1.listindex = number, but it still doesn't work! Be reminded again: there is a .listindex (7); the listcount is 9. Is it a VB5 bug?

Chris Eastwood
January 6th, 2000, 03:37 AM
I don't see how if you've added 7 items to the combo that the listcount
property is returning 9 - have you tried to do a debug.print on the
contents of the combobox to see what these extra two items are ?

I'd also recommend you fix a bug by rewriting your code from :


If Combo1.ListIndex = 6 then
thelist$ = InputBox("Enter the directory you wish to be listed. You can enter a * string to view filenames. Example: if you want to see all .DOC files in C:\my, then enter C:\my\*.DOC!", "Directory Listing")
askyou = MsgBox("If there are many files, the user might not be able to see all of them! By adding a constant, however, all can be seen. Do you wish to add that constant?", vbYesNo, "Constant")
End If
If askyou = vbYes then
thetruelist$ = thelist$ + " | MORE"
thereallist$ = "dir " + thetruelist$
v1.Caption = thereallist$
List1.AddItem ("[Dir List: " + thelist$ + "]")
Command1.Enabled = true
Exit Sub
else
Exit Sub
End If




to :


If Combo1.ListIndex = 6 then
thelist$ = InputBox("Enter the directory you wish to be listed.
You can enter a * string to view filenames. Example: if you want to see all .DOC files in C:\my, then enter C:\my\*.DOC!", "Directory Listing")
askyou = MsgBox("If there are many files, the user might not be able to see all of them! By adding a constant, however, all can be seen. Do you wish to add that constant?", vbYesNo, "Constant")
'
' This check moved inside the check for combo1.listindex = 6
'
If askyou = vbYes then
thetruelist$ = thelist$ + " | MORE"
thereallist$ = "dir " + thetruelist$
v1.Caption = thereallist$
List1.AddItem ("[Dir List: " + thelist$ + "]")
Command1.Enabled = true
Exit Sub
else
Exit Sub
End If
End If




As a check for Combo1.ListIndex = 7 would have never have been reached
because the check for 'askyou = vbYes' always exits the subroutine.


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb