How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Zabo04 Your Own Question

Zabo04
Zabo04, Programming Enthusiast
Category: Programming
Satisfied Customers: 282
Experience:  C/C++, python, perl, excel, matlab/octave, java, and R experience. Genetic algorithm, vision, GUIs.
58597962
Type Your Programming Question Here...
Zabo04 is online now

I want to declare a public array to that data I place in it

Customer Question

I want to declare a public array to that data I place in it can be used many times in different procedures. I have successfully loaded my data and run one of the routines I will be using from within the same procedure but when I separate the data loading from the routine in to two separate procedures, the data is lost to the second
I have tried declaring the array as global and public without success.
Submitted: 2 years ago.
Category: Programming
Expert:  LogicPro replied 2 years ago.
Hi
Welcome here
Zip the project; upload the zipped file to http://wikisend.com or http://ge.tt and post download link here.
Customer: replied 2 years ago.

Far too big and containing mostly irrelevant stuff to send whole project. Attached is a module with the code that's relevant.


I want to be able to load data from a very large text file in to an array. I want the array to be persistent for access by other procedures.


In the attached module, the get_data() reads the text file, parsing it to elements within the array tracedata() which is dynamically re-dimmed depending on the constituents of the text file (it's seismic positioning data).


The Draw_the_lines() sub uses the data to draw the track of the seismic equipment on a form and calculate some attributes en route.


There will be other subs required in the final program so I don't want to have to re-read the data in to an array each time.


 


The file attached and not a graphic it has been renamed to allow attachment: please rename to .bas.

Attachments are only available to registered users.

Register Here

Attachments are only available to registered users.

Register Here

Attachments are only available to registered users.

Register Here
View Full Image

Attachments are only available to registered users.

Register Here


 


Cheers,


 


John Q

Customer: replied 2 years ago.

Far too big and containing mostly irrelevant stuff to send whole project. Attached is a module with the code that's relevant.


I want to be able to load data from a very large text file in to an array. I want the array to be persistent for access by other procedures.


In the attached module, the get_data() sub reads a text file, parsing it to elements within the array tracedata() which is previously and dynamically re-dimmed depending on the constituents of the text file (it's seismic positioning data).


The Draw_the_lines() sub uses the data to draw the track of the seismic equipment on a form and calculate some attributes en route.


There will be other subs required in the final program so I don't want to have to re-read the data in to an array each time.


 


The file, justanswer.bas has been uploaded to the wikisend url


 


Cheers,


 


John Q

Expert:  LogicPro replied 2 years ago.
which version of VB you are using?
Customer: replied 2 years ago.


VB6

Expert:  LogicPro replied 2 years ago.

My apologies. I am not familiar with this version and opting out for other Professionals to answer. Please wait. You will be notified by email as soon as any Professional joins you. I will help you with your other questions though. Thank you for your patience.

Expert:  Zabo04 replied 2 years ago.
Have you tried Public Shared?
Customer: replied 2 years ago.


Just tried that now and it doesn't like it. The shared word is automatically erased as soon as I leave the line. Never seen that before. Usually goes red, beeps at me and puts up a messagebox if it doesn't like something.

Expert:  Zabo04 replied 2 years ago.
Are both subs in the same module?
Expert:  Zabo04 replied 2 years ago.
I would assume they are in the same class namespace, however since I do not have all of your code I don't know that and it makes a difference, because you would have to call the variables across the namespace. In any event this is a scope issue, and you are referencing local variables instead of the global, but I do not have all of your code so I have to keep asking you questions to determine where the scope is lost.
Customer: replied 2 years ago.


The code I uploaded to the wikisend URL contained the sections that are relevant.


I'm just prototyping for an application that I'm planning. As it stands, The declarations, the procedure to dimension the array and then populate it and the procedure that attempts to use the array are all in the same module. The array appears as undimensioned when an attempt to use it is made in the second procedure. I could live with the array scope only being available across the one procedure but would prefer it if it could be made available outside to other modules.


I don't know if it's relevant but the array is extremely large.

Expert:  Zabo04 replied 2 years ago.
I'll put it this way, I don't know if the code is relevant or irrelevant because I haven't seen it. It is definitely a scope issue, but because I don't have the code, I can't determine what scope the program thinks it is in. At a minimum I need to know whether all of the "relevant" code is in the same module, and it the "irrelevant" code is in the same module or not.

Now, the simplest way to solve this is to put both sets of code in the same module, then have your action call the function by referencing the module. Public and global are the same in VB6, with the exception public is available in forms and such whereas global works only in modules.
Customer: replied 2 years ago.

OK, well you should have the code as I have, as stated previously, uploaded it to the wikisend URL as initially directed.


The array in question is named tracedata.


 


I had placed everything in one module to try to make it work prior to you suggesting this. The uploaded data is a single module.


 


The difference between global and public that you have told me about is interesting but not relevant in this case as I have placed everything in to the same module and the associated form just activates the procudre in the module.


 


I don't think that it is fully a scope issue. I've been playing around with the problem this evening using a small array and some dummy data and the array is seen in other procedures as expected. I think the problem I've been having is connected to the size of the array. In my prototype the tracedata() array is redimensioned as tracedata(2159, 12, 654, 2), following a data snooping run to check the requirements, and has to be set as LONG as there is insufficient memory otherwise: I have to multiply coordinates, which are to one decimal place, by ten to make them LONG to restrict the memory required.


Is memory requirement close to the limit likely to affect scope?


 

Expert:  Zabo04 replied 2 years ago.
if you use the dim command then the data becomes private. So if you redim, it make s a local copy, that is not accessible outside of the function.

Build a class that has the globals as local, then access the class using global functions that set the global variables.

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer
< Previous | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C.
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C.
 
 
 

Meet The Experts:

 
 
 
  • ATLPROG

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7260
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
< Last | Next >
  • http://ww2.justanswer.com/uploads/SP/spatlanta2010/2011-6-23_12450_photo.64x64.gif ATLPROG's Avatar

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7260
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Computer Software Engineer

    Satisfied Customers:

    5514
    Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
  • http://ww2.justanswer.com/uploads/lifesaver333/2010-10-17_191349_ls.jpeg lifesaver's Avatar

    lifesaver

    Computer Software Engineer

    Satisfied Customers:

    936
    Several years of intensive programming and application development experience in various platforms.
  • http://ww2.justanswer.com/uploads/EH/ehabtutor/2012-8-2_202016_1.64x64.jpg ehabtutor's Avatar

    ehabtutor

    Computer Software Engineer

    Satisfied Customers:

    766
    Bachelor of computer science, 5+ years experience in software development, software company owner
  • http://ww2.justanswer.com/uploads/eljonis/2010-01-06_130406_eljon2.jpg Eljon's Avatar

    Eljon

    Consultant

    Satisfied Customers:

    558
    Founder of StockCanvas.com
  • http://ww2.justanswer.com/uploads/FA/fael/2011-1-15_104041_profile500x500.64x64.jpg Rafael Martins's Avatar

    Rafael Martins

    Computer Software Engineer

    Satisfied Customers:

    446
    Desktop, Mobile and Web Developer. 7+ years of experience. Creative solutions provider.
  • http://ww2.justanswer.com/uploads/CH/chutz747/2011-11-6_14231_me.64x64.jpg The-PC-Guy's Avatar

    The-PC-Guy

    Software Engineer

    Satisfied Customers:

    320
    Extensive Knowledge in PHP, MYSQL, CSS & Javascript