473,320 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Difference in using "With Me" statement in dotnet VB and access VBA

I recently wrote a program in Access VBA that contains this snippet of code:

For i = 1 to TotalBanks
With Me("txtBank" & Chr(i + 64))
.BackColor = vbBlue
.ForeColor = vbWhite
End With
Next i

The above code was tested and works.

I've attempted to do something similar in VB dotnet and I keep receiving
a syntax error. Here's the snippet:

For rowCtr = 0 To 2
For whlCtr = 0 To 4
With Me("r" & rowCtr & "w" & whlCtr)
.borderstyle = BorderStyle.Fixed3D
End With
Next whlCtr
Next rowCtr

The error is "Class 'TestApp.frmSlot' cannot be indexed because it has
not default property."

any ideas?

Thanks, Darrell
Sep 9 '06 #1
4 5267
Sept. 9, 2006

Hey Darrell... the "With" statement is to help cut down on the code you
have to write if you are going to be repeatingly changing settings on a
control. . . and therefore the syntax is "With [objectname]". The problem
you are running into is there is no "object' repesented by "Me("r" & rowCtr
& "w" & whlCtr)".

Me is the current component the code is running under, and passing something
between ()s doesn't give anything back. You can do what you are wanting with
*other* components such as collections...

dim A() as string
With A(3) ' Represents the 4th string object in this 0-based string array
end with

A.GetValue(int) is the set default property for people who want to use the
short-hand version A(int)... it is just a shortcut. So while each class can
have a different type of default property & parameters, the "Me" class
doesn't have one.

So if there is an object in Me which you need... you'll need to dig through
Intellisense for Me to find the property/function you need to call to get
the contained object.

If you let us know what the object is and what it is doing in Me, then we
could probably help you in finding the property/function you need.

Hope this helps!
--

Joseph Bittman
Microsoft Certified Solution Developer
Microsoft Most Valuable Professional -- DPM

Blog/Web Site: http://CactiDevelopers.ResDev.Net/
"darrell" <da*****@nospam.comwrote in message
news:jEIMg.3411$8J2.3323@fed1read11...
>I recently wrote a program in Access VBA that contains this snippet of
code:

For i = 1 to TotalBanks
With Me("txtBank" & Chr(i + 64))
.BackColor = vbBlue
.ForeColor = vbWhite
End With
Next i

The above code was tested and works.

I've attempted to do something similar in VB dotnet and I keep receiving a
syntax error. Here's the snippet:

For rowCtr = 0 To 2
For whlCtr = 0 To 4
With Me("r" & rowCtr & "w" & whlCtr)
.borderstyle = BorderStyle.Fixed3D
End With
Next whlCtr
Next rowCtr

The error is "Class 'TestApp.frmSlot' cannot be indexed because it has not
default property."

any ideas?

Thanks, Darrell
Sep 10 '06 #2
darrell wrote:
I recently wrote a program in Access VBA that contains this snippet of code:

For i = 1 to TotalBanks
With Me("txtBank" & Chr(i + 64))
.BackColor = vbBlue
.ForeColor = vbWhite
End With
Next i

The above code was tested and works.

I've attempted to do something similar in VB dotnet and I keep receiving
a syntax error. Here's the snippet:

For rowCtr = 0 To 2
For whlCtr = 0 To 4
With Me("r" & rowCtr & "w" & whlCtr)
.borderstyle = BorderStyle.Fixed3D
End With
Next whlCtr
Next rowCtr

The error is "Class 'TestApp.frmSlot' cannot be indexed because it has
not default property."
You must pay attention to what is "Me" in each context. In the second
case, it seems it's your form and the error message is clear: it needs
a default, indexed property for that syntax to be valid.

I don't know what you were trying to select with those "coordinates",
so I'll pretend it was a Grid object (I'm inventing things here, due to
the lack of information from your post). So if you wanted your form to
return a given cell from that grid, you'd have:

<aircode>
Public Default ReadOnly Property _
Cell(Coords As String) As GridCell 'Whatever
Get
Dim Result As New GridCell
'Translate the coordinates
'Assign the cell to the result variable
Return Result
End Get
End Property
</aircode>

With something like this, I suppose you can use the short circuit
syntax Me(xxx) (where xxx, in your case, would be a valid coordinate).

HTH.

Regards,

Branco.

Sep 10 '06 #3
Thanks for responding, Joseph.

example 1:
For rowCtr = 2 To 5
With Me("TextBox" & rowCtr)
.borderstyle = Fixed3D
.BackColor = BlanchedAlmond
End With
Next rowCtr

example 2:
With Me.TextBox2
.BorderStyle = BorderStyle.Fixed3D
.BackColor = Color.BlanchedAlmond
End With
repeat for TextBox3 through <whatever>
or
Me.TextBox2.BorderStyle = BorderStyle.Fixed3D
Me.TextBox2.BackColor = Color.BlanchedAlmond
repeat for TextBox3 through <whatever>

I have four textboxes on my form (in this example), named TextBox2
through TextBox5. In VBA for Access, example 1 works - no squawks. In
dotnet VB, example 1 bombs, example 2 though works fine. That's fine
for three or four boxes...for ten or twelve, it's a pain. I'm
constantly changing background colors, and am developing with the border
style set to FixedSingle. It seems to me that VB dotnet should be able
to something like example 1. :)

Darrell
Joseph Bittman MVP MCSD wrote:
Sept. 9, 2006

Hey Darrell... the "With" statement is to help cut down on the code
you have to write if you are going to be repeatingly changing settings
on a control. . . and therefore the syntax is "With [objectname]". The
problem you are running into is there is no "object' repesented by
"Me("r" & rowCtr & "w" & whlCtr)".

Me is the current component the code is running under, and passing
something between ()s doesn't give anything back. You can do what you
are wanting with *other* components such as collections...

dim A() as string
With A(3) ' Represents the 4th string object in this 0-based string array
end with

A.GetValue(int) is the set default property for people who want to use
the short-hand version A(int)... it is just a shortcut. So while each
class can have a different type of default property & parameters, the
"Me" class doesn't have one.

So if there is an object in Me which you need... you'll need to dig
through Intellisense for Me to find the property/function you need to
call to get the contained object.

If you let us know what the object is and what it is doing in Me, then
we could probably help you in finding the property/function you need.

Hope this helps!
Sep 10 '06 #4
Sept. 9, 2006

Hey Darrell... so what you want to do is just use a method to look up your
control name in the Me container basically.....

Common to other "container" objects (including big ones like Groupboxes,
panels, etc, and small ones like user controls), there is a "Controls"
property of Me to find a control. . . use the Find method (pass the ID of
the control - like Button1, and then pass True to search all child controls
as the second parameter).

This Me.Controls.Find method returns an array of Object types. . . . with
each member of the array being a match to your control ID paramter -
however, I absolutely have no idea how you could have more than one control
returned because .Net doesn't allow two controls to have the same name.

So since we know at design time that it will only return one object in that
array, we just use the first member - ie, Object(0) member.

So we've got our control by specifying the 0 index of the object array, but
since it is still of an Object type, we need to cast it to a Button type so
we can change its properties. . . which is done with the
Ctype(OriginalObject, newtypename) operation...

'loop with I as integer being your button1 , 2, 3, 4 etc
dim O() as object = Me.Controls.Find("Button" & I, True)
dim OurButton as Button = O(0)
*OurButton.Property = New Value

or in a very condensed form if you were only going to change 1 property:

Ctype(Me.Controls.Find("Button" & I, True)(0), Button).Property = Value

:) Hopefully this works for you!
--

Joseph Bittman
Microsoft Certified Solution Developer
Microsoft Most Valuable Professional -- DPM

Blog/Web Site: http://CactiDevelopers.ResDev.Net/
"darrell" <da*****@nospam.comwrote in message
news:0KLMg.3435$8J2.432@fed1read11...
Thanks for responding, Joseph.

example 1:
For rowCtr = 2 To 5
With Me("TextBox" & rowCtr)
.borderstyle = Fixed3D
.BackColor = BlanchedAlmond
End With
Next rowCtr

example 2:
With Me.TextBox2
.BorderStyle = BorderStyle.Fixed3D
.BackColor = Color.BlanchedAlmond
End With
repeat for TextBox3 through <whatever>
or
Me.TextBox2.BorderStyle = BorderStyle.Fixed3D
Me.TextBox2.BackColor = Color.BlanchedAlmond
repeat for TextBox3 through <whatever>

I have four textboxes on my form (in this example), named TextBox2 through
TextBox5. In VBA for Access, example 1 works - no squawks. In dotnet
VB, example 1 bombs, example 2 though works fine. That's fine for three
or four boxes...for ten or twelve, it's a pain. I'm constantly changing
background colors, and am developing with the border style set to
FixedSingle. It seems to me that VB dotnet should be able to something
like example 1. :)

Darrell
Joseph Bittman MVP MCSD wrote:
>Sept. 9, 2006

Hey Darrell... the "With" statement is to help cut down on the code you
have to write if you are going to be repeatingly changing settings on a
control. . . and therefore the syntax is "With [objectname]". The problem
you are running into is there is no "object' repesented by "Me("r" &
rowCtr & "w" & whlCtr)".

Me is the current component the code is running under, and passing
something between ()s doesn't give anything back. You can do what you are
wanting with *other* components such as collections...

dim A() as string
With A(3) ' Represents the 4th string object in this 0-based string array
end with

A.GetValue(int) is the set default property for people who want to use
the short-hand version A(int)... it is just a shortcut. So while each
class can have a different type of default property & parameters, the
"Me" class doesn't have one.

So if there is an object in Me which you need... you'll need to dig
through Intellisense for Me to find the property/function you need to
call to get the contained object.

If you let us know what the object is and what it is doing in Me, then we
could probably help you in finding the property/function you need.

Hope this helps!
Sep 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: bill | last post by:
I am trying to convince a client that dotNet is preferable to an Access project (ADP/ADE). This client currently has a large, pure Access MDB solution with 30+ users, which needs to be upgraded....
15
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
4
by: Philipp Sumi | last post by:
Hello all I have a thread that performs some simple I/O within a loop that runs on a separate thread. I used the using keyword to ensure the writer's disposal: using (writer) { while...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
8
by: Rasmus Kromann-Larsen | last post by:
The With Conundrum I'm currently writing a master thesis on (preparations for) static analysis of JavaScript, and after investigating the with statement, it only even more evident to me that the...
25
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For...
33
by: =?Utf-8?B?RE9UTkVUR1VZ?= | last post by:
Hello, In vb.net there is a with statement, Is there are similar constructor in c#?
14
by: Ivan Voras | last post by:
Hi, I'm looking for a construct that's similar to (Turbo) Pascal's "with" statement. I read about the Python's new "with" statement, but I was dissapointed to learn that it does something...
1
by: tensi4u | last post by:
Hi all, I've been in stuck on updating a table. Here is the query. with tab_one ( "col_1", "col_2", "col_3", "col_4" ) as ( select ax."col1", ax."col2", bx."col1", bx."col2" ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.