By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

using left and right function

P: 13
Hello
I'm trying to format a string with the left and right fxn but am getting an error "Public read only property () as integer has no parameters and it's return type cannot be indexed"

This code uses an API call to get the volume serial number

Expand|Select|Wrap|Line Numbers
  1. Imports vb = Microsoft.VisualBasic
  2. Imports Microsoft.VisualBasic
  3.  
  4. Public Class Form1
  5.     Private Declare Function GetVolumeSerialNumber Lib "kernel32.dll" Alias "GetVolumeInformationA" _
  6.         (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
  7.          ByVal lpVolumeSerialNumber As Long, ByVal lpMaximumComponentLength As Long, ByVal lpFileSystemFlags As Long, _
  8.          ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
  9.  
  10. Public Function VolumeSerialNumber(ByVal RootPath As String) As String
  11.         Dim VolLabel As String
  12.         Dim VolSize As Long
  13.         Dim Serial As Long
  14.         Dim MaxLen As Long
  15.         Dim Flags As Long
  16.         Dim Name As String
  17.         Dim NameSize As Long
  18.         Dim s As String
  19.  
  20.         If GetVolumeSerialNumber(RootPath, VolLabel, VolSize, Serial, MaxLen, Flags, Name, NameSize) Then
  21.             'Create an 8 character string
  22.             s = Format(Hex(Serial), "00000000")
  23.             'Adds the '-' between the first 4 characters and the last 4 characters
  24.             VolumeSerialNumber = Left(s, 4) + "-" + Right(s, 4)
  25.         Else
  26.             'If the call to API function fails the function returns a zero serial number
  27.             VolumeSerialNumber = "0000-0000"
  28.         End If
  29.  End Function
  30.  
the errors are a squiggly right under the left and right commands
Jul 29 '10 #1
Share this Question
Share on Google+
4 Replies


Joseph Martell
Expert 100+
P: 196
Is this in VB .Net or vb 4/5/6?
In either event, you are getting the error because you are in a form and the form has properties called "Left" and "Right".

If you are using VB .Net, I would suggest using some of the string class's methods for string parsing instead of Left and Right. If you are dead-set on using these functions then you can fully qualify them using
Expand|Select|Wrap|Line Numbers
  1. Microsoft.VisualBasic.Left
If you are NOT using VB .Net, then I'm not sure how to get around this problem, but I bet someone in the VB 4/5/6 forum would know.
Jul 29 '10 #2

!NoItAll
100+
P: 296
If using vb 4/5/6 then use vba.left and vba.right
Aug 3 '10 #3

MrMancunian
Expert 100+
P: 569
If you need those functions more often, you can also add
Expand|Select|Wrap|Line Numbers
  1. Imports Microsoft.VisualBasic
on top of your page.

Steven
Aug 5 '10 #4

P: 13
The imports statement fixed it.
Thank you

Steve
Aug 5 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.