473,378 Members | 1,462 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,378 software developers and data experts.

I can't use an Array thats in un other Function in an other class??

I have made an array in a function in a Class now I need to get to that
Array from an other function in an other Class, How do I do that?

The Array has no fixed size as it is dependent on how much a user has put in
a txt file.

The Class with the Array is an object, objInternetClass and I want to reach
the Array by doing something like
This is the MSAgentClass:

General:
Dim objInternet As New InternetClass

Private Sub InitAgentCommands()

'I will later use this For loop in another function to get both the Name and
the URL, that's way it looks like this...

For X = 0 To UBound(objInternet.MyArray) Step 2
Debug.Print "objInternet.URLAddress ==> " & objInternet.MyArray(X)
Debug.Print "objInternet.NameAddress ==> " & objInternet.MyArray(X + 1)
Debug.Print "------------------------------------"

Merlin.Commands.Add objInternet.MyArray(X + 1) , objInternet.MyArray(X + 1)
, objInternet.MyArray(X + 1)

Next

End Sub

Yours, Jonas
Jul 17 '05 #1
10 2286
I can't get the Array to be Public...

From the Help text:
" To create a public array, use the Public statement in the Declarations
section of a module to declare the array. "

In my InternetClass where I am making the Array from a text file I am
declaring the myArray in the general Declarations sector like this:

Public MyArray() As String
but I get this Compile Error message:

" Constants, fixed-Length Strings, Arrays, User-defined types and declare
statements not allowed as Public members of object modules "

How can I get it Public than??
"BadOmen" <ba*******@hotmail.com> skrev i meddelandet
news:tL********************@newsc.telia.net...
I have made an array in a function in a Class now I need to get to that
Array from an other function in an other Class, How do I do that?

The Array has no fixed size as it is dependent on how much a user has put in a txt file.

The Class with the Array is an object, objInternetClass and I want to reach the Array by doing something like
This is the MSAgentClass:

General:
Dim objInternet As New InternetClass

Private Sub InitAgentCommands()

'I will later use this For loop in another function to get both the Name and the URL, that's way it looks like this...

For X = 0 To UBound(objInternet.MyArray) Step 2
Debug.Print "objInternet.URLAddress ==> " & objInternet.MyArray(X)
Debug.Print "objInternet.NameAddress ==> " & objInternet.MyArray(X + 1)
Debug.Print "------------------------------------"

Merlin.Commands.Add objInternet.MyArray(X + 1) , objInternet.MyArray(X + 1) , objInternet.MyArray(X + 1)

Next

End Sub

Yours, Jonas

Jul 17 '05 #2
"BadOmen" <ba*******@hotmail.com> wrote
I have made an array in a function in a Class now I need to get to that
Array from an other function in an other Class, How do I do that?

The Array has no fixed size as it is dependent on how much a user has put in
a txt file.


You should redesign your class so that you do not need to expose the array.
You might even make the array a collection which you would be able to
expose, if you really need to expose it.

What if you had these in your internet class:

Public Sub Addresses(ByVal Index As Long, Name as String, URL as String)
If Index >= LBound(MyArray) And Index <= UBound(MyArray) \ 2 Then
URL = MyArray(Index * 2)
Name = MyArray(Index * 2 + 1)
End if
End Sub

Public Function TotalCommands() As Long
TotalCommands = UBound(MyArray) \ 2
End Function
You could then loop through them elsewhere:

Dim x&, nam$, url$

For X = 0 to objIE.TotalCommands
ObjIE.Addresses x, nam, url
Merlin.Commands.Add nam, nam, nam
Next

(All untested code but you might get the idea)
LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #3
I don't know how to use that...I'm a real newbe...

This is what I have done and whant to do(it does not realy work...
*** marks questions and remarks

This is what I need to do:
This is in the InternetClass:

'**** I am making MyArray here

Public Function FromFile()

Dim X As Long
Dim FileNum As Long
Dim TotalFile As String
Dim MyArray() As String
FileNum = FreeFile
' Reads the entire file into memory all at once
Open "c:\testfile.txt" For Binary As #FileNum
TotalFile = Space(LOF(FileNum))
Get #FileNum, , TotalFile
Close #FileNum
' Replace all newline character sequences with commas
' This will create a long file with every item separated
' by a comma in the same order as presently in file
TotalFile = Replace$(TotalFile, vbNewLine, ",")

' Split the enormous single string at the commas and puts it in an Array
MyArray = Split(TotalFile, ",")
End Function

***** In the MS Agent Class I have this function:

Dim objInternet As New InternetClass

Private Sub InitAgentCommands()
' Purpose: Initialize the Commands menu
On Error Resume Next

Merlin.Commands.RemoveAll
Merlin.Commands.Caption = "My Menu Name"
Merlin.Commands.Add "ACO", "Advanced Character Options", "Advanced
Character Options"
Merlin.Commands.Add "SPEECHCP", "Speech Control Panel", "[Open] Speech
Control Panel"
Merlin.Commands.Add "SEP1", "______________________________", ""
Merlin.Commands.Add "Jonas Musik", "Jonas Musik", "Jonas Musik"
Merlin.Commands.Add "Read copy", "read copy", "read copy"
Merlin.Commands.Add "SEP2", "______________________________", ""
'****This must take the array made in the InternetClass under the Function
FromFile()
'****and use it here, How do I do that??? (I can't get the data from MyArray
I cant even use MyArray here...)

For X = 0 To UBound(objInternet.MyArray) Step 2

'URLAddress ís MyArray(X) I will use this in an other place.
'NameAddress Is MyArray(X + 1)

Merlin.Commands.Add objInternet.MyArray(X + 1), objInternet.MyArray(X + 1),
objInternet.MyArray(X + 1)
Next
Merlin.Commands.Add "Back", "Back", "Back"
Merlin.Commands.Add "Forward", "Forward", "Forward"
Merlin.Commands.Add "Close", "Close", "Close"

End Sub
"Larry Serflaten" <Ab***@SpamBusters.com> skrev i meddelandet
news:40********@corp.newsgroups.com...
"BadOmen" <ba*******@hotmail.com> wrote
I have made an array in a function in a Class now I need to get to that
Array from an other function in an other Class, How do I do that?

The Array has no fixed size as it is dependent on how much a user has put in a txt file.
You should redesign your class so that you do not need to expose the

array. You might even make the array a collection which you would be able to
expose, if you really need to expose it.

What if you had these in your internet class:

Public Sub Addresses(ByVal Index As Long, Name as String, URL as String)
If Index >= LBound(MyArray) And Index <= UBound(MyArray) \ 2 Then
URL = MyArray(Index * 2)
Name = MyArray(Index * 2 + 1)
End if
End Sub

Public Function TotalCommands() As Long
TotalCommands = UBound(MyArray) \ 2
End Function
You could then loop through them elsewhere:

Dim x&, nam$, url$

For X = 0 to objIE.TotalCommands
ObjIE.Addresses x, nam, url
Merlin.Commands.Add nam, nam, nam
Next

(All untested code but you might get the idea)
LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 17 '05 #4
"BadOmen" <ba*******@hotmail.com> wrote
I don't know how to use that...I'm a real newbe...


Then you need to get experienced. By that I mean you need
to practise, practise, practise. If I explained all the theories of
aerodynamics, and told you how to build an airplane, would
you be able to fly? No, you would probably still need some
one to build the airplane, and someone else to explain how
to fly it. Why is that?

You are looking for answers to some very basic programming
questions. The trouble is that you do not have enough experience
to understand the answers. You basically need someone to do
it for you. You even posted code pasted in from someone
elses answer....

Copy and Paste is not a good method to program by. You
should understand every aspect of the code you add, in case
you need to make alterations. I don't want to discourage you
from learning to program, but you really have to learn to crawl
before you can learn to run! To do that, you should be taking
on very simple tasks, finding code examples, and seeing how
they work, and so on.

I know we all started out knowing nothing, but it is also your
own responsibility to read the Programmer's Guide, and Help
files to learn about using VB.

I already explained what you needed to do to expose your array
to the users of your class. You also need to make that array
available to all the routines in your class: Instead of declaring
MyArray inside the FromFile procedure, it needs to be declared
at the top of the module, ahead of any of the procedures. Then
add the two routines I posted last time and try it like I shown....

LFS



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #5
Ok....
Well I made some changes to your code to make it work with mine... So now it
works fine...

It is just in one place it does not work. It is in this Select:

Select Case UserInput.Name

Case "SEP2"
'Emty line
Dim x&, nam$, url$

For x = 0 To objReadFile.TotalCommands
objReadFile.Addresses x, nam, url
Case nam
Address = url
objInternet.Navigate Address
Next

Case "Back"
objInternet.Back
End Select

If I do the for loop here, i will get the error message telling me that Case
is without Select Case
Is it not possible to make it work in a Select Case???
Or is it just me having to go back to the "Hello World"??
"Larry Serflaten" <Ab***@SpamBusters.com> skrev i meddelandet
news:40********@corp.newsgroups.com...
"BadOmen" <ba*******@hotmail.com> wrote
I don't know how to use that...I'm a real newbe...


Then you need to get experienced. By that I mean you need
to practise, practise, practise. If I explained all the theories of
aerodynamics, and told you how to build an airplane, would
you be able to fly? No, you would probably still need some
one to build the airplane, and someone else to explain how
to fly it. Why is that?

You are looking for answers to some very basic programming
questions. The trouble is that you do not have enough experience
to understand the answers. You basically need someone to do
it for you. You even posted code pasted in from someone
elses answer....

Copy and Paste is not a good method to program by. You
should understand every aspect of the code you add, in case
you need to make alterations. I don't want to discourage you
from learning to program, but you really have to learn to crawl
before you can learn to run! To do that, you should be taking
on very simple tasks, finding code examples, and seeing how
they work, and so on.

I know we all started out knowing nothing, but it is also your
own responsibility to read the Programmer's Guide, and Help
files to learn about using VB.

I already explained what you needed to do to expose your array
to the users of your class. You also need to make that array
available to all the routines in your class: Instead of declaring
MyArray inside the FromFile procedure, it needs to be declared
at the top of the module, ahead of any of the procedures. Then
add the two routines I posted last time and try it like I shown....

LFS



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 17 '05 #6
"BadOmen" <ba*******@hotmail.com> wrote
Ok....
Well I made some changes to your code to make it work with mine... So now it
works fine...

It is just in one place it does not work. It is in this Select:


You can't break up the Select/Case structure like that. It is
a bit more optimized but it is little more than the If/Then/Else
type.

If A Then
DoX
ElseIf B Then
DoY
Else
DoZ
End If

Select case is similar:

Select Case Input
Case A
DoX
Case B
DoY
Else
DoZ
End Select

From what you've posted, it looks like you'll need to test all
those you know about, and if they don't match then try the
object's commands

Select Case Input
Case "SEP2"
' Nothing?
Case "Back"
' Go back
Case "Quit"
' Quit
Case (etc... Whatever else you have)
Case Else
For x = 0 To objReadFile.TotalCommands
objReadFile.Addresses x, nam, url
If Input = nam then
' Do nam command
Exit Sub
End If
Next
End Select

LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #7

"Larry Serflaten" <Ab***@SpamBusters.com> skrev i meddelandet
news:40**********@corp.newsgroups.com...
"BadOmen" <ba*******@hotmail.com> wrote
Ok....
Well I made some changes to your code to make it work with mine... So now it works fine...

It is just in one place it does not work. It is in this Select:
You can't break up the Select/Case structure like that. It is
a bit more optimized but it is little more than the If/Then/Else
type.

If A Then
DoX
ElseIf B Then
DoY
Else
DoZ
End If


I was thinking of doing a bunch If instead so I will use that. I was just
curious of if it was possible with she Select Case :) It was in the original
code...

The problem with The if, end if, in a loop is that I must have if in the
loop I can't make an if statement outside the loop and just a bunch of
elseif in the loop because It then say that I don't have a If. That mean
that I cant have an Else at the end. If I have that it is just fore the last
if and elseif states that I have put under the loop. Example might be
needed...:
<Snip>

ElseIf UserInput.Name = "SEP2" Then
'Emty line
End If

Dim x&, nam$, url$

For x = 0 To objReadFile.ReadFile
objReadFile.Addresses x, nam, url

If UserInput.Name = nam Then
Adress = url
objInternet.Navigate Adress
End If
Next
If UserInput.Name = "Back" Then
objInternet.Back
ElseIf UserInput.Name = "Forward" Then
objInternet.Forward

ElseIf UserInput.Name = "Close" Then
objInternet.Quit

Else

'This Else wold just be for the last three if,elseif NOT for all
above, but I just have to be without the confused Merlin that don't
understand the voice command :)

End If
Thanx for all your help :-)

Select case is similar:

Select Case Input
Case A
DoX
Case B
DoY
Else
DoZ
End Select

From what you've posted, it looks like you'll need to test all
those you know about, and if they don't match then try the
object's commands

Select Case Input
Case "SEP2"
' Nothing?
The Nothing line is emty becouse it is just an Line ------- In the menue. It
will not hapen a thing if pressed. ( It is used with MS Agent voice
Commands)
Case "Back"
' Go back
Case "Quit"
' Quit
Case (etc... Whatever else you have)
Case Else
For x = 0 To objReadFile.TotalCommands
objReadFile.Addresses x, nam, url
If Input = nam then
' Do nam command
Exit Sub
End If
Next
End Select

I am using the Else here all ready making the Merlin in MS Agent look
confused. When he don't understand the voice command he is given. LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 17 '05 #8
I have changed your code and maybe you can tell if it's bad or if it's ok?
It works fine, but there maybe problems that I haven't in countered...
This is what I have chained your code in to(you can se your original code
further down):

this is in my internet class:

Public Sub Addresses( Index As Long, Name as String, URL as String)
URL = MyArray(Index)
Name = MyArray(Index + 1)
End Sub

Public Function TotalCommands() As Long
TotalCommands = UBound(MyArray) -1
End Function
You could then loop through them elsewhere:

Dim x&, nam$, url$

For X = 0 to objIE.TotalCommands Step 2
ObjIE.Addresses x, nam, url
Merlin.Commands.Add nam, nam, nam
Next
Yours, Jonas
"Larry Serflaten" <Ab***@SpamBusters.com> skrev i meddelandet
news:40********@corp.newsgroups.com...
"BadOmen" <ba*******@hotmail.com> wrote
I have made an array in a function in a Class now I need to get to that
Array from an other function in an other Class, How do I do that?

The Array has no fixed size as it is dependent on how much a user has put in a txt file.
You should redesign your class so that you do not need to expose the

array. You might even make the array a collection which you would be able to
expose, if you really need to expose it.

What if you had these in your internet class:

Public Sub Addresses(ByVal Index As Long, Name as String, URL as String)
If Index >= LBound(MyArray) And Index <= UBound(MyArray) \ 2 Then
URL = MyArray(Index * 2)
Name = MyArray(Index * 2 + 1)
End if
End Sub

Public Function TotalCommands() As Long
TotalCommands = UBound(MyArray) \ 2
End Function
You could then loop through them elsewhere:

Dim x&, nam$, url$

For X = 0 to objIE.TotalCommands
ObjIE.Addresses x, nam, url
Merlin.Commands.Add nam, nam, nam
Next

(All untested code but you might get the idea)
LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 17 '05 #9
> this is in my internet class:

Public Sub Addresses( Index As Long, Name as String, URL as String)
URL = MyArray(Index)
Name = MyArray(Index + 1)
End Sub


That is just another way to do the same thing, but, you left out the Index check.

If you do not _verify_ that the input is valid, then you really should supply
error handling code in case you get bad input. For example what if someone
passes in an Index valuie of -1 or 100000, or other such numbers? Without
verification or error handling, that function could crash your program.

It pays to be defensive in all your code, even if you are the only one that is
going to use it. I prefer to verify the input, or, stop the trouble at the source,
so to speak. You might develop a different strategy....

LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #10

"Larry Serflaten" <Ab***@SpamBusters.com> skrev i meddelandet
news:40********@corp.newsgroups.com...
this is in my internet class:

Public Sub Addresses( Index As Long, Name as String, URL as String)
URL = MyArray(Index)
Name = MyArray(Index + 1)
End Sub
That is just another way to do the same thing, but, you left out the Index

check.
If you do not _verify_ that the input is valid, then you really should supply error handling code in case you get bad input. For example what if someone passes in an Index valuie of -1 or 100000, or other such numbers? Without
verification or error handling, that function could crash your program.

It pays to be defensive in all your code, even if you are the only one that is going to use it. I prefer to verify the input, or, stop the trouble at the source, so to speak. You might develop a different strategy....

LFS


I have now added the index verification, I think you have a point there...
:)

Thank you

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 17 '05 #11

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

Similar topics

5
by: Henrietta Denoue | last post by:
Hi I am new to C++ and suffering from dynamic allocation. I have a function that returns an integer pointer and want to assign this to another pointer: class cssReader { public:
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
14
by: dam_fool_2003 | last post by:
Hai, When I declare a zero-based array I get a compile time error stating that zero based array is not possible. But if I declare the same in the function argument I don't get any error. Is...
13
by: MJ | last post by:
as topic, if i wan to create an array where the content of the array can be edited by form1 and form2, how i going to do it? for example the content of array is {1,2,3} form2 change the content...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
2
by: Michael Isaksson | last post by:
Hello! I want to know how to passing an array-object from a function.. I have a class called brickCollection, in this class i have a function called getBricks() which a JFrame object should...
8
by: nephish | last post by:
hey there, is this ok? class MyClass { var $start; var $finish; function MyClass($start, $finish) { $this->start = $start; $this->finish=$finish,
12
by: Martien van Wanrooij | last post by:
I have been using for a while a class to create photo albums. Shortly, an array of photo's is declared, initially they are shown as thumbnails, by clicking on a thumbnail a larger photo is shown...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.