1 error after option strict on
1 error after option strict on
1 error after option strict on
1 error after option strict on
1 error after option strict on
1 error after option strict on 1 error after option strict on 1 error after option strict on 1 error after option strict on 1 error after option strict on 1 error after option strict on 1 error after option strict on 1 error after option strict on
1 error after option strict on 1 error after option strict on
1 error after option strict on
Go Back  Xtreme Visual Basic Talk > > > 1 error after option strict on


Reply
 
Thread Tools Display Modes
  #1  
Old 09-07-2010, 01:41 AM
xxentric xxentric is offline
Newcomer
 
Join Date: Jul 2010
Posts: 6
Default 1 error after option strict on


i turned Option Strict On

and i get an error on all the ".Cells" lines saying option strict on disallows late binding.

Code:
                a = 1
                b = 3
                c = 2
                d = 1
                With oSheet
                    Do Until a > 7
                        Do Until .Cells(b, a).Value = ""
                            .Cells(b, a).activate()
                            If .Cells(b, a).Value = .Range("IV" & d).Value Then
                                .Cells(b, c).Value = .Cells(b, c).Value + 1
                                d = d + 1
                            Else
                                If .Range("IV" & d).Value = "" And d < 20 Then
                                    d = d + 1
                                    b = b - 1
                                End If
                            End If
                            b = b + 1
                        Loop
                        a = a + 2
                        b = 3
                        c = c + 2
                        d = 1
                    Loop
                End With
Reply With Quote
  #2  
Old 09-07-2010, 03:23 AM
PlausiblyDamp's Avatar
PlausiblyDamp1 error after option strict on PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Where are you defining oSheet? Is it defined as object or as a worksheet?
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 09-07-2010, 05:36 AM
xxentric xxentric is offline
Newcomer
 
Join Date: Jul 2010
Posts: 6
Default

in a module
Code:
    Public oExcel As Microsoft.Office.Interop.Excel.Application
    Public oBook As Microsoft.Office.Interop.Excel.Workbook
    Public oBooks As Microsoft.Office.Interop.Excel.Workbooks
    Public oSheet As Microsoft.Office.Interop.Excel.Worksheet
in my form
Code:
            oExcel = New Microsoft.Office.Interop.Excel.Application
            oBook = oExcel.Workbooks.Open("C:\Jared FC Project Desktop\Fixture Tracking.xls")
            oSheet = CType(oBook.Sheets.Item("Sheet1"), Microsoft.Office.Interop.Excel.Worksheet)
Reply With Quote
  #4  
Old 09-07-2010, 10:25 AM
AtmaWeapon's Avatar
AtmaWeapon1 error after option strict on AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

It's not usually nice to post the same thread on two different forums. Since neither party necessarily knows that the other thread exists, you'll end up causing at least half of the people to waste their time. It's especially confusing when you head to forum B and say "People on another forum said this..." because the forum A people may not understand the context in which the advice was given.

As the discussion on the other forum is going (and not ending up anywhere useful at the rate it's going), Option Strict On is part of why you're getting the error. But you have to understand what Option Strict is to understand why you're getting an error.

The short version of what Option Strict does is it doesn't allow you to assign a value of type B to a variable of type A without first performing a cast. Why is this useful? It helps catch a whole class of silly mistakes that you can accidentally make, like assigning some text box's text to an Integer variable without first checking that the string represents a number. If you have to call CInt() to make the assignment, it might make you think, "Hmm, this might not be a number so I should probably use TryParse() instead to avoid exceptions."

So why are you getting errors? I'm not familiar with Office interop, but I can read documentation and make guesses. Workbook.Sheets is of type Sheets, a collection of Worksheet objects. Worksheet.Cells returns a Range object. Range.Value is of type Object. Aha! Now we have the answer.

Code:
Do Until .Cells(b, a).Value = ""
Value is Object. "" is String. In order to compare Object to String, you have to first convert it to a string. This error could be addressed by changing the line:
Code:
Do Until .Cells(b, a).Value.ToString() = ""
You'll have to find an appropriate conversion for each line...

...or, for just this time, turn Option Strict Off. Office interop tends to rely heavily on late binding, and having Option Strict On when doing Office interop tends to get in the way. There is no such thing as a "never" in programming, so though you may have been told "never turn Option Strict Off", it carries an implied "Unless you know what you're doing and you're in a scenario where early binding makes your life more miserable than late binding." With Option Strict Off, you'll have to be more careful that you know the type of any value you work with.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 09-07-2010, 10:27 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline
Out Of Office

Retired Moderator
* Expert *
 
Join Date: Mar 2005
Location: London, UK
Posts: 3,402
Default

For reference, I strongly encouraged the use of Option Strict On on xxtentric's related thread:
closing excel ...
Reply With Quote
  #6  
Old 09-07-2010, 10:54 AM
AtmaWeapon's Avatar
AtmaWeapon1 error after option strict on AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

To be fair, I'm basing that opinion on the viewpoint that the documentation for Office interop is a shambles and when I dabbled with it I found it difficult to figure out what the devil the type that's returned by a particular method/property will be. I could be wrong, but since so much stuff returns Object it feels like a situation where Option Strict Off should be used with caution.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
1 error after option strict on
1 error after option strict on
1 error after option strict on 1 error after option strict on
1 error after option strict on
1 error after option strict on
1 error after option strict on 1 error after option strict on 1 error after option strict on 1 error after option strict on 1 error after option strict on 1 error after option strict on 1 error after option strict on
1 error after option strict on
1 error after option strict on
 
1 error after option strict on
1 error after option strict on
 
-->