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

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?
LVL 12
minichickenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

S-TwilleyCommented:
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
AlexFMCommented:
               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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Arthur_WoodCommented:
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

S-TwilleyCommented:
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
AlexFMCommented:
Sorry, I am late.
0
S-TwilleyCommented:
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
minichickenAuthor Commented:
how would i get a form other than form1 to be the first form shown on run
0
minichickenAuthor Commented:
oh wait got it thanks
0
S-TwilleyCommented:
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
minichickenAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.