Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Option Strict On prohibits operands of type Object for operator '&'

Posted on 2005-02-28
10
Medium Priority
?
2,132 Views
Last Modified: 2012-06-27
hi,

i get the compiling error "Option Strict On prohibits operands of type Object for operator '&'" when i try run this code:


    Private Sub Drive_info()
        Dim fso As New Scripting.FileSystemObject
        Dim drv As Scripting.Drive
        Dim string_builder As New System.Text.StringBuilder

        For Each drv In fso.Drives
            string_builder.Append(drv.DriveLetter & ":" & vbCrLf & _
            "                                           " & vbCrLf & _
                "  Type:                       " & _
                    drv.DriveType.ToString() & vbCrLf)
            If drv.IsReady Then
                string_builder.Append( _
                    "  File System:          " & drv.FileSystem & _
                        vbCrLf & _
                    "  Free Space:           " & drv.FreeSpace & _
                        vbCrLf & _
                    "  Total Size:              " & drv.TotalSize & _
                        vbCrLf & _
                    "  Volume Name:      " & drv.VolumeName & _
                        vbCrLf & _
                    "  Serial Number:     " & drv.SerialNumber & _
                        vbCrLf & _
                    "------------------------------------------" & vbCrLf)

            Else
                string_builder.Append( _
                    "  Not ready" & vbCrLf & _
                    "------------------------------------------" & vbCrLf)
            End If
        Next drv
        RichTextBox1.Text = string_builder.ToString()
    End Sub



the 'drv.FreeSpace' statement is underlined and none of the others.....?

i've added the 'Microsoft Scripting Runtime' reference but still getting errors...

can anyone help?
0
Comment
Question by:minichicken
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13418891
Can't be sure but a possible solution would be to use the   .ToString()  method for each of the Drive properties (just like you have with the DriveType property).

            If drv.IsReady Then
                string_builder.Append( _
                    "  File System:          " & drv.FileSystem.ToString() & _
                        vbCrLf & _
                    "  Free Space:           " & drv.FreeSpace.ToString() & _
                        vbCrLf & _
                    "  Total Size:              " & drv.TotalSize.ToString() & _
                        vbCrLf & _
                    "  Volume Name:      " & drv.VolumeName.ToString() & _
                        vbCrLf & _
                    "  Serial Number:     " & drv.SerialNumber.ToString() & _
                        vbCrLf & _
                    "------------------------------------------" & vbCrLf)
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 1500 total points
ID: 13418899
               string_builder.Append( _
                    "  File System:          " & drv.FileSystem & _
                        vbCrLf & _
                    "  Free Space:           " & drv.FreeSpace.ToString() & _
                        vbCrLf & _
                    "  Total Size:              " & drv.TotalSize.ToString() & _
                        vbCrLf & _
                    "  Volume Name:      " & drv.VolumeName & _
                        vbCrLf & _
                    "  Serial Number:     " & drv.SerialNumber & _
                        vbCrLf & _
                    "------------------------------------------" & vbCrLf)
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 13418901
try this change, from:

           If drv.IsReady Then
                string_builder.Append( _
                    "  File System:          " & drv.FileSystem & _
                        vbCrLf & _
                    "  Free Space:           " & drv.FreeSpace & _
                        vbCrLf & _
                    "  Total Size:              " & drv.TotalSize & _
                        vbCrLf & _
                    "  Volume Name:      " & drv.VolumeName & _
                        vbCrLf & _
                    "  Serial Number:     " & drv.SerialNumber & _
                        vbCrLf & _
                    "------------------------------------------" & vbCrLf)

To:

           If drv.IsReady Then
                string_builder.Append( _
                    "  File System:          " & cStr(drv.FileSystem) & _
                        vbCrLf & _
                    "  Free Space:           " & cStr(drv.FreeSpace) & _
                        vbCrLf & _
                    "  Total Size:              " & cStr(drv.TotalSize) & _
                        vbCrLf & _
                    "  Volume Name:      " & cStr(drv.VolumeName) & _
                        vbCrLf & _
                    "  Serial Number:     " & cStr(drv.SerialNumber) & _
                        vbCrLf & _
                    "------------------------------------------" & vbCrLf)


AW
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 12

Expert Comment

by:S-Twilley
ID: 13418905
As far as i can tell, it's throwing the error because you're trying to concatinate a string with an object... I'm not sure of the types returned from each of those properties, but since you have option strict on, its best to convert them to strings (least that's what I think)
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13418907
Sorry, I am late.
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13418958
No problem Alex... looks like we were all thinkin the same thing, I did a quick refresh just before posting just in case someone had got there before me
0
 
LVL 12

Author Comment

by:minichicken
ID: 13419130
how would i get a form other than form1 to be the first form shown on run
0
 
LVL 12

Author Comment

by:minichicken
ID: 13419165
oh wait got it thanks
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13419169
doesn't look like it mattered you were late Alex :P  ... and u should post it as a seperate question mini... but since it is a simple enough question... right click on your project in the Solution Explorer, and goto properties, then u can set the Startup Object
0
 
LVL 12

Author Comment

by:minichicken
ID: 13419304
thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question