Home All Groups Group Topic Archive Search About

2005 too smart for it's own good?

Author
19 Sep 2006 7:33 PM
cj
I have a program I'm writing that has started executing the line
following the line that is highlighted in the debugger.

For instance

for x = 1 to 3
    messagebox.show(x)
next

when for x = 1 to 3 is highlighted and I press F11 the message box pops up.

I'm not sure why but I decided to wipe the program and start over.  I
cut my code and pasted into notepad.  I closed VB.NET 2005.  I renamed
the directory test to oldtest.  I started VB.NET 2005 and told it to
create a new project called test.  It told me it could not because
another project already exists in test.

What??????? There is no test any more.  What the heck is going on.  I
really hate it when a program tells me I can't do something.  Who's the
boss here.  How do I fix this?

Author
19 Sep 2006 8:56 PM
Spam Catcher
cj <cj@nospam.nospam> wrote in
Show quoteHide quote
news:e###FKC3GHA.324@TK2MSFTNGP05.phx.gbl:

>
> I have a program I'm writing that has started executing the line
> following the line that is highlighted in the debugger.
>
> For instance
>
> for x = 1 to 3
>      messagebox.show(x)
> next
>
> when for x = 1 to 3 is highlighted and I press F11 the message box
> pops up.

for x as integer = 1 to 3

You need to declare a data type - this isn't vbscript ;-)



Show quoteHide quote
> I'm not sure why but I decided to wipe the program and start over.  I
> cut my code and pasted into notepad.  I closed VB.NET 2005.  I renamed
> the directory test to oldtest.  I started VB.NET 2005 and told it to
> create a new project called test.  It told me it could not because
> another project already exists in test.
>
> What??????? There is no test any more.  What the heck is going on.  I
> really hate it when a program tells me I can't do something.  Who's
> the boss here.  How do I fix this?
Author
20 Sep 2006 12:40 PM
cj
The dim is several line above the sample code I gave you.

Spam Catcher wrote:
Show quoteHide quote
> cj <cj@nospam.nospam> wrote in
> news:e###FKC3GHA.324@TK2MSFTNGP05.phx.gbl:
>
>> I have a program I'm writing that has started executing the line
>> following the line that is highlighted in the debugger.
>>
>> For instance
>>
>> for x = 1 to 3
>>      messagebox.show(x)
>> next
>>
>> when for x = 1 to 3 is highlighted and I press F11 the message box
>> pops up.
>
> for x as integer = 1 to 3
>
> You need to declare a data type - this isn't vbscript ;-)
>
>
>
>> I'm not sure why but I decided to wipe the program and start over.  I
>> cut my code and pasted into notepad.  I closed VB.NET 2005.  I renamed
>> the directory test to oldtest.  I started VB.NET 2005 and told it to
>> create a new project called test.  It told me it could not because
>> another project already exists in test.
>>
>> What??????? There is no test any more.  What the heck is going on.  I
>> really hate it when a program tells me I can't do something.  Who's
>> the boss here.  How do I fix this?
>
Author
20 Sep 2006 4:15 AM
Linda Liu [MSFT]
Hi Cj,

> for x = 1 to 3
>    messagebox.show(x)
> next
> when for x = 1 to 3 is highlighted and I press F11 the message box pops
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?

> I renamed the directory test to oldtest.  I started VB.NET 2005 and told
it to
create a new project called test.

Which directory did you rename, the solution directory or the project
directory? Did you create a new project calle test with a new solution or
within the previous solution?

I look forward to your reply.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
20 Sep 2006 1:54 PM
cj
Linda Liu [MSFT] wrote:
Show quoteHide quote
> Hi Cj,
>
>> for x = 1 to 3
>>     messagebox.show(x)
>> next
>> when for x = 1 to 3 is highlighted and I press F11 the message box pops
> 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.

>
>> I renamed the directory test to oldtest.  I started VB.NET 2005 and told
> 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.
>
> I look forward to your reply.

Thanks!

Show quoteHide quote
>
> Sincerely,
> Linda Liu
> Microsoft Online Community Support
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.

> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================

> This posting is provided "AS IS" with no warranties, and confers no rights.
>
Author
21 Sep 2006 9:24 AM
Linda Liu [MSFT]
Hi Cj,

I performed a test based on your sample code and did see the problem. When
the line of code 'oWB.Worksheets(x).delete()' is just highlighted, it has
been executed.

I think this problem is caused by the 'style' of this line of code. If I
replace this line of code with the following code,

Dim oWS As Worksheet
oWS = oWB.Worksheets(x)
oWS.Delete()

all works fine. When the this line of code 'oWS.Delete()' is just
highlighted, it isn't executed. It's after I press F11 that this line of
code is executed.

It is recommended to declare each object as a new variable when we automate
a Microsoft Office application from Microsoft Visual Basic .NET or
Microsoft Visual C#. Otherwise, it may cause some exceptional errors, e.g
Office application does not quit after automation from Visual Studio .NET
client (you could visit the link
'http://support.microsoft.com/kb/317109/en-us' to get more information on
this error).

As for your second question, it seems that you have renamed the directory
of the solution, which is correct. However, make sure that the path
'C:\Documents and Settings\cj\My Documents\Visual Studio
2005\Projects\test' is the right directory of the previous solution.

Hope this helps.


Sincerely,
Linda Liu
Microsoft Online Community Support
Author
25 Sep 2006 1:04 PM
cj
Thanks Linda.  Sorry it took me so long to say that.

I ended up writing the data to a CSV file and manually importing it into
Excel because adding the data cell by cell was way to slow.  So my Excel
automation attempts were dropped.


Linda Liu [MSFT] wrote:
Show quoteHide quote
> Hi Cj,
>
> I performed a test based on your sample code and did see the problem. When
> the line of code 'oWB.Worksheets(x).delete()' is just highlighted, it has
> been executed.
>
> I think this problem is caused by the 'style' of this line of code. If I
> replace this line of code with the following code,
>
> Dim oWS As Worksheet
> oWS = oWB.Worksheets(x)
> oWS.Delete()
>
> all works fine. When the this line of code 'oWS.Delete()' is just
> highlighted, it isn't executed. It's after I press F11 that this line of
> code is executed.
>
> It is recommended to declare each object as a new variable when we automate
> a Microsoft Office application from Microsoft Visual Basic .NET or
> Microsoft Visual C#. Otherwise, it may cause some exceptional errors, e.g
> Office application does not quit after automation from Visual Studio .NET
> client (you could visit the link
> 'http://support.microsoft.com/kb/317109/en-us' to get more information on
> this error).
>
> As for your second question, it seems that you have renamed the directory
> of the solution, which is correct. However, make sure that the path
> 'C:\Documents and Settings\cj\My Documents\Visual Studio
> 2005\Projects\test' is the right directory of the previous solution.
>
> Hope this helps.
>
>
> Sincerely,
> Linda Liu
> Microsoft Online Community Support
>
Author
26 Sep 2006 10:33 AM
Linda Liu [MSFT]
Hi Cj,

Thanks for your update.

It seems that your first question has been solved. Then how about your
second question?

If the problem is not solved or you need our further assistance, please
feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
Author
26 Sep 2006 1:49 PM
cj
I did get that project deleted after rebooting my pc.  Don't know why it
didn't work the first time but stuff happens.  If I have any problems
when I delete a project in the future I'll post another question.  Thanks.

Linda Liu [MSFT] wrote:
Show quoteHide quote
> Hi Cj,
>
> Thanks for your update.
>
> It seems that your first question has been solved. Then how about your
> second question?
>
> If the problem is not solved or you need our further assistance, please
> feel free to let me know.
>
>
> Sincerely,
> Linda Liu
> Microsoft Online Community Support
>
Author
23 Sep 2006 1:57 PM
Michael D. Ober
Excel programming has a lot of quirks.  In excel, create a new workbook and
report back the number of worksheets in it.  The default is 3, but you can
change this default to anything you want from 1 to 255  (Tools->Options
General Tab).  It may be that you have the default set to 1 or 2 already, in
which case the loop will never execute.

Also, add the line

debug.print (oWB.Sheets.Count.toString())

immediately before the for loop and after the worksheet delete statement.

debug.print (oWB.Sheets.Count.toString())
For x As Int32 = oWB.Sheets.Count To 2 Step -1
      oWB.Worksheets(x).delete()
      debug.print (oWB.Sheets.Count.toString())
Next

The debug output will be in the immediate window.


Show quoteHide quote
"cj" <cj@nospam.nospam> wrote in message
news:OyGKXxL3GHA.1060@TK2MSFTNGP04.phx.gbl...
>
>
> Linda Liu [MSFT] wrote:
> > Hi Cj,
> >
> >> for x = 1 to 3
> >> messagebox.show(x)
> >> next
> >> when for x = 1 to 3 is highlighted and I press F11 the message box pops
> > 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.
>
> >
> >> I renamed the directory test to oldtest.  I started VB.NET 2005 and
told
> > 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.
> >
> > I look forward to your reply.
>
> Thanks!
>
> >
> > Sincerely,
> > Linda Liu
> > Microsoft Online Community Support
> >
> > ==================================================
> > Get notification to my posts through email? Please refer to
> >
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
Show quoteHide quote
> > ications.
> >
> > Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
> > where an initial response from the community or a Microsoft Support
> > Engineer within 1 business day is acceptable. Please note that each
follow
> > up response may take approximately 2 business days as the support
> > professional working with you may need further investigation to reach
the
> > most efficient resolution. The offering is not appropriate for
situations
> > that require urgent, real-time or phone-based interactions or complex
> > project analysis and dump analysis issues. Issues of this nature are
best
> > handled working with a dedicated Microsoft Support Engineer by
contacting
> > Microsoft Customer Support Services (CSS) at
> > http://msdn.microsoft.com/subscriptions/support/default.aspx.
> > ==================================================
> >
> > This posting is provided "AS IS" with no warranties, and confers no
rights.
> >
>
Author
25 Sep 2006 1:05 PM
cj
My Excel was set to come up with 3 and did but the problem still
occured.  Linda Liu's response solved the problem.

Michael D. Ober wrote:
Show quoteHide quote
> Excel programming has a lot of quirks.  In excel, create a new workbook and
> report back the number of worksheets in it.  The default is 3, but you can
> change this default to anything you want from 1 to 255  (Tools->Options
> General Tab).  It may be that you have the default set to 1 or 2 already, in
> which case the loop will never execute.
>
> Also, add the line
>
> debug.print (oWB.Sheets.Count.toString())
>
> immediately before the for loop and after the worksheet delete statement.
>
> debug.print (oWB.Sheets.Count.toString())
> For x As Int32 = oWB.Sheets.Count To 2 Step -1
>       oWB.Worksheets(x).delete()
>       debug.print (oWB.Sheets.Count.toString())
> Next
>
> The debug output will be in the immediate window.
>
>
> "cj" <cj@nospam.nospam> wrote in message
> news:OyGKXxL3GHA.1060@TK2MSFTNGP04.phx.gbl...
>>
>> Linda Liu [MSFT] wrote:
>>> Hi Cj,
>>>
>>>> for x = 1 to 3
>>>> messagebox.show(x)
>>>> next
>>>> when for x = 1 to 3 is highlighted and I press F11 the message box pops
>>> 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.
>>
>>>> I renamed the directory test to oldtest.  I started VB.NET 2005 and
> told
>>> 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.
>>> I look forward to your reply.
>> Thanks!
>>
>>> Sincerely,
>>> Linda Liu
>>> Microsoft Online Community Support
>>>
>>> ==================================================
>>> Get notification to my posts through email? Please refer to
>>>
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
>>> ications.
>>>
>>> Note: The MSDN Managed Newsgroup support offering is for non-urgent
> issues
>>> where an initial response from the community or a Microsoft Support
>>> Engineer within 1 business day is acceptable. Please note that each
> follow
>>> up response may take approximately 2 business days as the support
>>> professional working with you may need further investigation to reach
> the
>>> most efficient resolution. The offering is not appropriate for
> situations
>>> that require urgent, real-time or phone-based interactions or complex
>>> project analysis and dump analysis issues. Issues of this nature are
> best
>>> handled working with a dedicated Microsoft Support Engineer by
> contacting
>>> Microsoft Customer Support Services (CSS) at
>>> http://msdn.microsoft.com/subscriptions/support/default.aspx.
>>> ==================================================
>>>
>>> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
>