?
Solved

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

Posted on 2005-02-28
10
Medium Priority
?
2,087 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

800 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