Linda said:
Hi Cj,
up.
If we set a break point at the line of code 'for x = 1 to 3' and press F5
to run this program, the program enters break mode when this line of code
is executed. At this time, this line of code is highlighted. If we press
F11 to step into, the line of code 'messagebox.show(x)' is highlighted and
a message box pops up.
Do you mean you have seen something different from the above?
Yes. Though I have to be honest I' not actually using
messagebox.show(x). I wanted to made a simple example but it turns out
the example works as it should.
This is the actual code that does not work.
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
' Start Excel and get Application object.
oXL = CreateObject("Excel.Application")
oXL.Visible = True
oWB = oXL.Workbooks.Add
For x As Int32 = oWB.Sheets.Count To 2 Step -1
oWB.Worksheets(x).delete()
Next
This is what I'm doing. Set the breakpoint on the line "oXL.Visible =
True". The program goes into debug mode when it gets to that line but
BEFORE it executes that line. press F11--Excel becomes visible on the
task bar and "oWB = oXL.Workbooks.Add" becomes yellow. press F11--The
workbook is created in Excel and "For x As Int32 = oWB.Sheets.Count To 2
Step -1" becomes yellow. Good so far. Press F11--The Excel icon on the
task bar starts flashing and "oWB.Worksheets(x).delete()" becomes
yellow. If click Excel on the taskbar you will note it's saying "the
sheet will be permanently deleted ok cancel". That's the problem. VB
should not have told Excel to delete the sheet yet. That line is yellow
waiting for me to press F11 to run--it has not been run yet.
Normally when I press F11 on a yellow line it is executed and the next
line of code is turned yellow. In this case when "For x As Int32 =
oWB.Sheets.Count To 2 Step -1" was yellow and I pressed F11 "For x As
Int32 = oWB.Sheets.Count To 2 Step -1" was executed AND
"oWB.Worksheets(x).delete()" was executed! "oWB.Worksheets(x).delete()"
was left yellow as it should be but it had already been executed.
it to
create a new project called test.
Which directory did you rename, the solution directory or the project
directory?
Solution directory? Project directory?
I renamed C:\Documents and Settings\cj\My Documents\Visual Studio
2005\Projects\test to C:\Documents and Settings\cj\My Documents\Visual
Studio 2005\Projects\oldtest And I assure you it was renamed.
I don't know what it is but I also found and deleted C:\Documents and
Settings\cj\My Documents\Visual Studio 2005\Backup Files\test
I didn't find any other directories called test so I assume that is
where the VB2005 saves the programs. In VB2003 I would have renamed
C:\Documents and Settings\cj\My Documents\Visual Studio Projects\test to
C:\Documents and Settings\cj\My Documents\Visual Studio Projects\oldtest
Did you create a new project calle test with a new solution or
within the previous solution?
I had VB2005 closed when the directory was renamed. I started VB2005
and on the start page I clicked on project just to the left of create.
I then changed the name from windowsapplication1 to test and clicked OK.
If finally got these steps to work but I had to reboot my computer
before they did.