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

how to make my own classes show their methods and/or variables while typing?

P: n/a
Sorry, but I have no idea how to phrase the subject better than that.
I've come across this a few different times and decided to ask in case
there's a way to do it. It would simplify things a bit and I figured
if anyone knows, more than likely that someone is here.

I have a class for storing filenames and it's path along with a little
more info. Here it is

Public Class myFiles
Public oldFileName As String
Public oldPathAndName As String
Public newFileName As String
Public newPathAndName As String
Public fileExtention As String
End Class

Now when using functions and such that are built in and you begin
typing VS.net either pops up with what you can possibly use or you can
force it by ctrl+space. Thats pretty much what I want to do. I may be
doing something wrong that is making it so it isn't including it, but,
if so hopefully any replies will point that out to me.

I declare a new arraylist

Public sourceArray, directoryListing As New ArrayList
Then in a sub I do this

For x As Integer = 0 To sourceArray.Count - 1
If sourceArray.Item(x).oldFileName.Contains(",") Then
MessageBox.Show(sourceArray.Item(x).oldfilename)
Else
MessageBox.Show("No comma in name!" & vbCrLf & _
sourceArray.Item(x).oldfilename)
End If
Next

Ok, now when I go to typing

sourceArray.Item(x).oldFileName

and I get this much done

sourceArray.Item(x).ol

or even if I just get to this

sourceArray.Item(x).

pressing ctrl+space should popup, or at least I would like it to, the
possible variables/methods/fuctions/etc.. I have for that class
stored in the arraylist. Did I explain this enough for you to
understand what I'm trying to accomplish? If so, is there a way for me
to get the classes variables to popup in the drop down box of the
'code completer'?

Even though it doesn't automatically popup for quicker completion it
does work just fine when I run it. But my memory isn't the greatest
for all the different names and such I use in different parts of my
project and would love to have the 'code completer' assist me with
this.
Thank you in advance for any help anyone can provide.
-------
Kyote
Please reply to the group.
Jul 27 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
oops! I forgot to mention I'm using VS.NET 2005
Jul 27 '06 #2

P: n/a
Kyote,

The arraylist holds objects. You need to cast the object back to an instance
of your class.

For example:

Dim myFile As myFiles
For x As Integer = 0 To sourceArray.Count - 1
myFile = DirectCast (sourceArray.Item(x), myFiles)
If myFile.oldFileName.Contains(",") Then
MessageBox.Show(myFile.oldfilename)
etc.

Another option would be to use a List instead of ArrayList and have it only
contain objects of type myFiles.

Kerry Moorman
"Kyote" wrote:
Sorry, but I have no idea how to phrase the subject better than that.
I've come across this a few different times and decided to ask in case
there's a way to do it. It would simplify things a bit and I figured
if anyone knows, more than likely that someone is here.

I have a class for storing filenames and it's path along with a little
more info. Here it is

Public Class myFiles
Public oldFileName As String
Public oldPathAndName As String
Public newFileName As String
Public newPathAndName As String
Public fileExtention As String
End Class

Now when using functions and such that are built in and you begin
typing VS.net either pops up with what you can possibly use or you can
force it by ctrl+space. Thats pretty much what I want to do. I may be
doing something wrong that is making it so it isn't including it, but,
if so hopefully any replies will point that out to me.

I declare a new arraylist

Public sourceArray, directoryListing As New ArrayList
Then in a sub I do this

For x As Integer = 0 To sourceArray.Count - 1
If sourceArray.Item(x).oldFileName.Contains(",") Then
MessageBox.Show(sourceArray.Item(x).oldfilename)
Else
MessageBox.Show("No comma in name!" & vbCrLf & _
sourceArray.Item(x).oldfilename)
End If
Next

Ok, now when I go to typing

sourceArray.Item(x).oldFileName

and I get this much done

sourceArray.Item(x).ol

or even if I just get to this

sourceArray.Item(x).

pressing ctrl+space should popup, or at least I would like it to, the
possible variables/methods/fuctions/etc.. I have for that class
stored in the arraylist. Did I explain this enough for you to
understand what I'm trying to accomplish? If so, is there a way for me
to get the classes variables to popup in the drop down box of the
'code completer'?

Even though it doesn't automatically popup for quicker completion it
does work just fine when I run it. But my memory isn't the greatest
for all the different names and such I use in different parts of my
project and would love to have the 'code completer' assist me with
this.
Thank you in advance for any help anyone can provide.
-------
Kyote
Please reply to the group.
Jul 28 '06 #3

P: n/a

"Kyote" <tr******@nospamgmail.comwrote in message
news:4e********************************@4ax.com...
Sorry, but I have no idea how to phrase the subject better than that.
I've come across this a few different times and decided to ask in case
there's a way to do it. It would simplify things a bit and I figured
if anyone knows, more than likely that someone is here.

I have a class for storing filenames and it's path along with a little
more info. Here it is

Public Class myFiles
Public oldFileName As String
Public oldPathAndName As String
Public newFileName As String
Public newPathAndName As String
Public fileExtention As String
End Class

Now when using functions and such that are built in and you begin
typing VS.net either pops up with what you can possibly use or you can
force it by ctrl+space. Thats pretty much what I want to do. I may be
doing something wrong that is making it so it isn't including it, but,
if so hopefully any replies will point that out to me.

I declare a new arraylist

Public sourceArray, directoryListing As New ArrayList
Then in a sub I do this

For x As Integer = 0 To sourceArray.Count - 1
If sourceArray.Item(x).oldFileName.Contains(",") Then
MessageBox.Show(sourceArray.Item(x).oldfilename)
Else
MessageBox.Show("No comma in name!" & vbCrLf & _
sourceArray.Item(x).oldfilename)
End If
Next

Ok, now when I go to typing

sourceArray.Item(x).oldFileName

and I get this much done

sourceArray.Item(x).ol

or even if I just get to this

sourceArray.Item(x).

pressing ctrl+space should popup, or at least I would like it to, the
possible variables/methods/fuctions/etc.. I have for that class
stored in the arraylist. Did I explain this enough for you to
understand what I'm trying to accomplish? If so, is there a way for me
to get the classes variables to popup in the drop down box of the
'code completer'?

Even though it doesn't automatically popup for quicker completion it
does work just fine when I run it. But my memory isn't the greatest
for all the different names and such I use in different parts of my
project and would love to have the 'code completer' assist me with
this.
Just a quick read of your example code and your desired behavior...

.... you have sourceArray defined as an ArrayList object. The Class myFiles
is not referenced. That is part of the reason why typing "sourceArray." does
not yield the Properties/Methods of the myFiles Class.

If sourceArray were an array of myFiles, and there were Property Get/Let's
for the objects in the myFiles Class, you would get the desired behavior.

Assuming your myFiles Class, with the addition of Property Get/Let's, you
could define sourceArray as...

Private sourceArray() As myFiles

You would ReDim sourceArray as needed to grow the array.

There are other tricks. This is but the most simple of examples (IMO, of
course). There might even be an error in the following 'cus the coffee has
yet to kick in for the morning.

If you haven't used ReDim on an empty array, the one thing you'll notice is
attempting to detect the empty array using Nothing or UBound/LBound will not
yield the desired outcome. You have to trap a runtime error condition.

There is overhead with ReDim'ing arrays. If you are working with small
arrays and not ReDim'ing the heck out of them the overhead should be
tollerable.

=====myFiles Class=====
Public Class myFiles
Private m_oldFileName As String
Property oldFileName() As String
Get
oldFileName = m_oldFileName
End Get
Set(ByVal value As String)
m_oldFileName = value
End Set
End Property
End Class
=====End myFiles Class=====

=====Some other Class=====
Public Class DummyForm
Private sourceArray() As myFiles ' empty array, no rows defined yet
Private Sub GrowArray()
On Error Resume Next
ReDim Preserve sourceArray(UBound(sourceArray) + 1)
If Err Then
ReDim sourceArray(0) ' one row array
End If
On Error GoTo 0
' Do other array entry initialization stuff here including...
sourceArray(UBound(sourceArray)) = New myFile
End Sub
End Class
=====End some other Class=====
Jul 28 '06 #4

P: n/a
>Just a quick read of your example code and your desired behavior...
>
... you have sourceArray defined as an ArrayList object. The Class myFiles
is not referenced. That is part of the reason why typing "sourceArray." does
not yield the Properties/Methods of the myFiles Class.

If sourceArray were an array of myFiles, and there were Property Get/Let's
for the objects in the myFiles Class, you would get the desired behavior.

Assuming your myFiles Class, with the addition of Property Get/Let's, you
could define sourceArray as...

Private sourceArray() As myFiles

You would ReDim sourceArray as needed to grow the array.

There are other tricks. This is but the most simple of examples (IMO, of
course). There might even be an error in the following 'cus the coffee has
yet to kick in for the morning.

If you haven't used ReDim on an empty array, the one thing you'll notice is
attempting to detect the empty array using Nothing or UBound/LBound will not
yield the desired outcome. You have to trap a runtime error condition.

There is overhead with ReDim'ing arrays. If you are working with small
arrays and not ReDim'ing the heck out of them the overhead should be
tollerable.

=====myFiles Class=====
Public Class myFiles
Private m_oldFileName As String
Property oldFileName() As String
Get
oldFileName = m_oldFileName
End Get
Set(ByVal value As String)
m_oldFileName = value
End Set
End Property
End Class
=====End myFiles Class=====

=====Some other Class=====
Public Class DummyForm
Private sourceArray() As myFiles ' empty array, no rows defined yet
Private Sub GrowArray()
On Error Resume Next
ReDim Preserve sourceArray(UBound(sourceArray) + 1)
If Err Then
ReDim sourceArray(0) ' one row array
End If
On Error GoTo 0
' Do other array entry initialization stuff here including...
sourceArray(UBound(sourceArray)) = New myFile
End Sub
End Class
=====End some other Class=====
What I'm doing is adding an instance of myFiles to the sourceArray
arraylist. That way I can avoid having to redim anything and also
avoid the redimming overhead.

My program is going to parse filenames and create directories based on
certain filename templates. Then it will move the files into the
appropriate directory. The reason I'm doing it this way is because it
allows me to keep all the information together and I can then send
only specific parts to my parsing subs which will then add the missing
information to each set of variables in each object in the arraylist.

I tried to think it through and determine the best approach for doing
what I wanted this app to do but I found myself not wanting to begin
because I could think of so many different ways to approach it. So
finally I decided to just do it and make alterations as my knowledge
grew. I know that's not really a good way to go about it but this app
is just a little tool to make certain things I do for a hobby of mine
easier to do. The added benefit is that it helps me learn vb.net a
little better as well.

So, is there a way for me to get the auto complete to appear doing it
the way I am? Or should I change my class to use get and sets as you
suggested?
-------
Kyote
Please reply to the group.
Jul 28 '06 #5

P: n/a

"Kyote" <tr******@nospamgmail.comwrote in message
news:k1********************************@4ax.com...
>
What I'm doing is adding an instance of myFiles to the sourceArray
arraylist. That way I can avoid having to redim anything and also
avoid the redimming overhead.

My program is going to parse filenames and create directories based on
certain filename templates. Then it will move the files into the
appropriate directory. The reason I'm doing it this way is because it
allows me to keep all the information together and I can then send
only specific parts to my parsing subs which will then add the missing
information to each set of variables in each object in the arraylist.

I tried to think it through and determine the best approach for doing
what I wanted this app to do but I found myself not wanting to begin
because I could think of so many different ways to approach it. So
finally I decided to just do it and make alterations as my knowledge
grew. I know that's not really a good way to go about it but this app
is just a little tool to make certain things I do for a hobby of mine
easier to do. The added benefit is that it helps me learn vb.net a
little better as well.

So, is there a way for me to get the auto complete to appear doing it
the way I am? Or should I change my class to use get and sets as you
suggested?
'Tho I haven't done (or seen) benchmarks comparing ReDim to ArrayList, I
suspect they will be about equal since both are expanding/contracting array
structures of some sort and that tends to be a memory-intensive process
(relatively speaking). Actual use of the array, I suspect, will have less
overhead than the ArrayList; I seem to recall ArrayList as being based on a
Collection and those tend to be slow, at least large Collections and in VB
classic.

Tinkering with code, especially new libraries, is a great way to pick up
skills and knowledge (IMO, of course). The "best approach" is the one that
works for you. I sometimes find myself pondering an idea for days on end
just trying to determine how I want to structure the solution. When it comes
time to write the code though it is not unusual for the whole idea to go
south and I end up falling back on old solutions. (Ah, but it is all about
the hunt. That's why they call fishing "fishing." If it were about actually
catching fish it would be called "catching.")

Some people (me) absolutely love to stumble around in the dark just for the
challenge. Others prefer the safety of a guided tour. Flailing around in
code allows you to discover alternative ways of accomplishing the task and,
in the process, generates far more intimate knowledge of the things you
touch along the way than any book or "expert" site can provide; the
knowledge sticks if you uncover it on your own and yields a certain
satisfaction once a solution is discovered. But enough of the soapbox
speech...

The only ways I know of that will give you the "auto complete" are defining
an object as a Class, a Structure (Type in VB classic), or an Enum. Since
your needs seem to indicate the "thing" requires validation routines and
other supporting code specific to this type of object, I would personally
use a Class. How that works in conjunction with ArrayList, I don't know
(yet). There is probably a slick trick, not necessarily inheritance, that
will allow you to use the Class with ArrayList yielding the best of both
worlds.

For now, the question you have to answer is which of the two - auto complete
or ArrayList - is of more value to you at the moment.
Jul 28 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.