Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Filling a UDT Array

Author
Message
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 26th Sep 2011 21:51 Edited at: 26th Sep 2011 22:02
Hi all! I am having some problems populating an array made up of a UDT, i know this is something simple but i cant quite work out where i am going wrong so i have posted up what i think is the relevant code and if someone can steer me right to the no doubt daft mistake ill be very much appreciative.



It seems to be populating the first part of the array with a name (which is what i want) Faction(1).Kingname is fine but what works for that does not work for the rest as if it doesnt cycle through the others. So that little print bit at the end writes a full name correctly, then the correct faction number (which would be 1 at first) then a blank space therefore no name, then the right faction number again which is 2, then another blank space where faction 3's name is. So that peice of code is definately going through all the for loop and adding a new number to each of the faction numbers and it prints fine, its just it only seems to create 1 name and pop it in faction 1's name slot and then doesnt bother going through that function again.
It may be something to do with dimming the arrays over and over again every time it calls the name function, i will try this once and see how it works.

If i need to post more code i will.
Thanks.

*Edit: I knew writing it out here would be the only way i could figure it out. As usual i spend all my resources thinking how to solve a problem then only come up with the solution almost immediately after i have posted a stupid question. It was as i suspected that i am trying to remake the arrays everytime it calls that function and it doesnt like that so i moved it out of the way and it works a charm.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 27th Sep 2011 02:04 Edited at: 27th Sep 2011 02:08
I didn't think re-dimming the arrays would be a problem at all.

I AM surprised it likes the Data statements inside the function (usually they are at the end of a program, and some measure taking to make sure data lines don't execute.)... as well as the fact that I don't see a Restore command for the data pointer anywhere in your code (and it seemed in your snippet you were intending to read the same data multiple times)????

Your signature has been erased by a mod please reduce it to 600 x 120.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Sep 2011 20:48
DATA is global in scope and can be placed anywhere inside your code, including within a function.

I sometimes do this myself, to keep the data close to the function in the code for readability.

You are right about needing to use the RESTORE command too - generally you'd put a label just before the data statements to ensure that you can restore that particular chunk of data.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 27th Sep 2011 21:34
Thanks for the tips folks. I was surprised to see the data statement work myself but it is fine as Ian says.

A related issue:
I am trying to display the contents of a string but using the TEXT commands and i dont think they like variables at all. Now i know if i have an integer i can use str$(whatever) to convert an integer to a string to be read by the TEXT command, but how do i do a variable like:
Text 0, 0, "Faction Name", Faction(a).Kingname to show up even if that has already been declared as a string. I dont know if it can be done and if not ill have to use print and move all my stuff round on screen using set cursor but if there is a way id love to know. Thanks.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Sep 2011 22:07
You 'add' the strings together:
Text 0, 0, "Faction Name" + Faction(a).Kingname

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 28th Sep 2011 00:38
Ohhhh damn me i knew that i just couldnt for the life of me remember it ha ha. Thanks a bunch Ian i sort of thought i had done it before but because i forgot i convinced myself i was wrong

Login to post a reply

Server time is: 2024-11-22 12:05:47
Your offset time is: 2024-11-22 12:05:47