Array syntax AS 2.0

Hello,
I have been going through the tutorials in Adobe's Flash 8
training from the source, and I have run into a syntax question
about arrays and was hoping someone could explain something for me.
specifically why I can trace an element in the first example
but not in the second. (IE. why does the second format not work and
what do i need to do to make it work.
ex1.
var directory:Array = [{name:"John", phone:"919-555-5698"},
{name:"Kelly", phone:"232-555-3333"}, {name:"Ross",
phone:"434-555-5655"}];
In this example I can run a trace to any item in the array.
ex 2.
var directory = new Array();
directory[0].Name = "John"
directory[0].Phone = "919-555-5698"
directory[1].Name = "Kelly"
directory[1].Phone = "232-555-3333"
directory[2].Name = "Ross"
directory[2].Phone = "434-555-5655"
all traces come up as undefined.
I have used the second examples format before with very few
problems, so any insight to this would be greatly appreciated.
Thanks.

directory[0] is undefined so trying to assign a property to
it (like Name or Phone) is going to fail.
to remedy you need to define directory[0] to be an object:

Similar Messages

  • Looking for proper rand/array syntax...

    I'm trying to make a link take a user to one of thirty possible pages, chosen randomly.
    I can imagine this is do-able via rand/array (php) but have no idea what the precise syntax would be. The various rand/array examples I've Googled do more than what I need, which is pretty basic... but I don't know PHP enough to customize myself.
    Say I have a normal <a href> tag... I just want it to randomly go to one of many selected pages. Nothing more. I don't want the link name to change.
    What would be the syntax for that?

    This one use JavaScript and an array of links.  You could put the script in an external file if desired.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Random Link</title>
    <script type="text/javascript">
    //The array. Specify links below. You can have as many as you want
    var randomlinks=new Array()
    randomlinks[0]="http://google.com"
    randomlinks[1]="http://yahoo.com"
    randomlinks[2]="http://dynamicdrive.com"
    randomlinks[3]="http://cnn.com"
    randomlinks[4]="http://msn.com"
    randomlinks[5]="http://bing.com"
    randomlinks[6]="http://youtube.com"
    function randomlink(){
    window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
    //-->
    </script>
    </head>
    <body>
    <a href="javascript:randomlink()">Random Link</a>
    </body>
    </html>
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • Confused with array syntax

    If I want to wiggle the X, Y and Z dimensions of a layer's position, I can do it with this expression:
    [wiggle(3,4)[0],wiggle(4,5)[1],wiggle(5,6)[2]]
    This addresses each dimension as an array member by index number.
    But if I want to randomize the  dimensions, I have to use syntax like this:
    [random(0,100),random(10,50),random(50,80)]
    If I try to explicitly reference the array members when using the Random function, AE throws an error.
    So how do I know which functions require addressing array members by index number and which functions require that I don't?

    Thanks for your reply. From the page you referred to, I see I can simplify my Random expression for X, Y and Z as:
    random([0,100],[4,5],[5,6])
    That's good. I understand that if I randomize only 1 value, it's a number, not an array. But what's confusing me is that whether I write a Random expression the long way or the short way to randomize X and Y or X, Y and Z values, I have to pass an array, because the Position property itself is an array -- and I have to pass the array implicitly. If I pass the array explicitly, as I have to with Wiggle, AE throws an error.
    My confusion isn't with the Random function itself. I'm wondering if there is a rule that tells me when to pass an array implicitly or explicitly. Or do I have to look at the syntax of each function to find out? With JavaScript, I have a choice of 3 ways to create an array, but AE seems to be more particular.

  • Array syntax

    hi all .. plz tell me how to declare an array in pl/sql editor .. why this help of oracle is not so helping ??? i m using 6i dev with 9i db. thanx

    BULK COLLECT might be better here.
    DECLARE
       TYPE myarray IS VARRAY (10) OF NUMBER (3);
       arr   myarray;
    BEGIN
    --  GO_BLOCK('CONF_ATT');
       SELECT months
       BULK COLLECT INTO arr
         FROM partial_frequencies;
       FOR i IN 1 .. 10
       LOOP
          IF arr.EXISTS (i)
          THEN
             message(arr (i));
          END IF;
       END LOOP;
    END;EDIT: actually you can't use bulk collect in a client-side program. I just noticed the go_block and realised you must mean the pl/sql editor in forms.
    You might get a better solution if you tell us what you're trying to achieve. For instance, in Forms you might actually want a record group. The Forms might be a better place for your question.
    Message was edited by:
    Dave Hemming

  • Collection Override: how to get collections instead of arrays from UML

    Has anybody sucessfuly used the Collection Override property for Java code generation from UML using JSE8??
    I have a simple case where class A has many class B. I want to get a Collection/List of Bs from A (public Collection<B> getBs(); ) and not an array of Bs (public B[] getBs();), which I can get by creating a navigable aggregation and setting multiplicity to *.
    I think Collection Override is the correct property to use, especially based on its documentation (below), but setting a number to multiplicity is not triggering it. How should I model the association so that I'll get collections generated instead of arrays?
    ' The value of this preference indicates the name of the Java
    collection type to be used instead of generating array syntax. For
    example, if this preference is set to "ArrayList" and multiplicity is
    set on an attribute of type "int", the type of the attribute in code will
    actually be generated as "ArrayList" instead of "int[]". '
    Thanks,
    Diego

    Hi,
    Hong_Lu, this bug is still bothering us. By any chance, do you have some info when we are going to get a patch for this? I didn't find any status information about this in the bug repository.
    If this is going to take forever, would it be possible for you to give us a hint how to fix this by ourselves, temporarily? I'd rather hard-code the ArrayList/Collection as a default value rather than plain arrays like now...
    Thanks.

  • C has no arrays! (on the heap)

    CC can't do this?
    int iary[] = (int[])iary_padr
    Who could imagine such a thing, if it didn't exist already? K&R's "stdc" appendix 6.8.2 iterates some drivel about static initializers, proposing a convenient (sic) workaround (sic) for dynamic memory
    iary[cc] <==> *(iary_padr+cc)
    This situation is plainly absurd. Someone has (very successfully) played a hideous joke on this language, and to the great benefit of their resume. One is left to replace clean array syntax with bug-prone, unreadable pointer arithmetic? what's the compiler for?
    the compiler helps one to avoid bugs by writing simpler expressions than available in a lower level language (asm).
    "As simple as possible, but no simpler." Which in this case means having array syntax, rather than not.
    Originally, "int[]" was syntactically and semantically identical to "int*" in parameter passing. This is C. We need to recognize that the standardizers have persued another language -- a higher level language, and one which would not have have pointers, ultimately, but some handle or object concept.
    How can the C programming language not be able to access the heap using array syntax?
    Sun folks need to JUST SAY NO to this absurdity. it necessarily won't break any code anywhere if CC were to allow array casts. If standardizers break the language, ignore them! No one needs this nonsensical jibberish for anything.
    John

    Hi,
    You may scan using the HP All-In-One Remote app, available for the App Store.
    You may find a step by step instructions below:
    http://support.hp.com/us-en/document/c02486319/
    Shlomi
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • Little glitch in annotation syntax?

    a very good thing with the Java syntax was that you were allowed to declare an array like this:
    String[] arr = {"one", "two",} ; // notice the last ","having written code generators for other language I thought this was a welcome idea
    (you didn't have to bother any more with the last "," in your loop)
    unfortunately is not true with annotations:
    @MyAnnotation (this=1, that=2,) //syntax error!sinec many annotations may be generated by programs (UML generators for example)
    I think this is a little syntactic glitch.... what do you think?

    This requires about 1 more line of code to fix in your
    code generator. I don't think it's an issue at all.unfortunately that's not true
    on some situation of code generation knowing that you are handling
    the "last" item might be cumbersome
    and you have to postpone the handling of the ","
    that's the very reason why the array syntax is different from other languages
    and tolerates a trailing comma

  • Generic syntax symetry

    The generic method syntax is:
    MethodHeader ::= MethodModifiersOpt TypeParametersOpt ResultType MethodDeclarator
    ThrowsOptWon't it be more natural (subjective concept) to have it like this (sorry, I can't access the JLS now that java.sun.com is down, to check for MethodDeclarator definition):
    MethodHeader ::= MethodModifiersOpt ResultType MethodDeclarator ThrowsOpt
    MethodDeclarator ::= MethodName TypeParametersOpt  MethodParametersThat way, you write:
    public T foo<T>(T x)instead of
    public <T> T foo(T x)The reasons (again subjective):
    - Orthogonality of the language, adding symetrie with generic class definitions, where generic parameters appears after class name.
    - Parameters, generic or not, are listed after the method name. For a human being, educated to functional languages, it's more obvious.
    Well, parsing is a bit more difficult as a type parameter use can appear before its definition.
    Is it only a matter of taste or is there another hidden reason against this syntax?

    Hi,
    Ambiguities in this syntax can be resolved with one character look ahead in the parser, making it context free.
    But isn't a similar a rule already introduce to disambiguate the >> and >>> sequences? The syntax rules are not particularly simple too:ReferenceType ::= ClassOrInterfaceType | ArrayType | TypeVariable
    ClassOrInterfaceType ::= Name | Name < ReferenceTypeList1
    ReferenceTypeList1 ::= ReferenceType1| ReferenceTypeList , ReferenceType1
    ReferenceType1 ::= ReferenceType > | Name < ReferenceTypeList2
    ReferenceTypeList2 ::= ReferenceType2 | ReferenceTypeList , ReferenceType2
    ReferenceType2 ::= ReferenceType >> | Name < ReferenceTypeList3
    ReferenceTypeList3 ::= ReferenceType3 | ReferenceTypeList , ReferenceType3
    ReferenceType3 ::= ReferenceType >>>
    TypeParameters ::= < TypeParameterList1
    TypeParameterList1 ::= TypeParameter1 | TypeParameterList , TypeParameter1
    TypeParameter1 ::= TypeParameter > | TypeVariable extends ReferenceType2I fear that the foo<T>(T x) syntax could appear in Java in a second shot, to accomodate programmers knowing other languages or to make it more orthogonal. Just like the String[] array or String array[] syntax is already accepted to accomodate C and C++ programmers...

  • Where do array Methods Come From?

    I've been curious about this for awhile. I can't find anything useful on google; all I end up with are array tutorials, which don't go into the "meat and potatoes" of my question at all.
    It's probably easiest to point out what I'm asking by posting the following first:
    public class TestArray{
       public static void main(String [] args){
          String [] catSounds = {"meow", "purr", "growl"};
          System.out.println(catSounds.toString());
          System.out.println("length: " + catSounds.length);
    }Okay, so given a basic String array (could be an array of anything, including primitives, but I just used String for simplicity's sake), we can call functions on it, like toString above. However, for lack of better wording, where does that method come from? I used eclipse's "open declaration" feature on the method, and it took me to toString in Object. But I didn't think a basic array was an Object?
    Similarly, where is the length field stored (eclipse's "open declaration" feature doesn't work on it)? It has to be encapsulated by some class somewhere, right?
    Is there a hidden class that extends Object (duh) and encapsulates the information for an array, and does the java compiler just translate the array syntax into calls to that class? Or am I missing something?

    kevinaworkman wrote:
    That link explains some of it. It explains all of it. ;o)
    So was I correct when I said there's a "hidden" (inaccessible and not listed in the API) class that extends Object and encapsulates the array data?Sort of yes, sort of no.
    10.8 Class Objects for Arrays
    Every array has an associated Class object, shared with all other arrays with the same component type. The direct superclass of an array type is Object. Every array type implements the interfaces Cloneable and java.io.Serializable.
    There isn't a general single Array class the way you're thinking (java.lang.reflect.Array isn't what you're looking for). Arrays have special support in the Java language, as described in the JLS.
    Why go through the trouble of having special syntax for an array if there's a class that could have been used just like any other class?Tradition.
    ~

  • Cast/interpret a string like "{{1,3},{2,5}}" as array

    is it possible to interpre or cast a string with "arraysyntax" like "{5,8}" as an array?
    or is the only way to parse the string and catch the values via string comparisons? this would mean it doesn't matter how the string looks like as long as i am able to get the values.
    probably it is possible via a script engine?
    i am using javascript to eval strings like "3+6".(representative = (Double) engine.eval("3.5");)
    but evaluating strings like "(1,2,3)" (javascript array syntax) is different?! And array=(double[]) engine.eval("(3.5,1.0)"); would not work?

    i am can freely specify the string. so it could also 1,2|3,4. but i thought it is some how possible to specify the string the right way and then cast/interpret it directly as a string.
    "What does engine.eval("(3.5,1.0)").getClass() return? Are you getting a List of Doubles?"
    that is exactly what i want to know -
    the correct way for javascript is:
    double[][] value = (double[][]) engine.eval("new Array(new Array(1.0,2.0),new Array(3.0,4.0))");i know javascript it self returns "[[1.0,2.0][3.0,4.0]]" but i don't know which class the eval returns. javadoc says object.

  • Trying to move a list of form variables to session variables of the same name

    I am trying to move a list of form variables to session variables of the same name and I am having a lot of trouble.
    I have never had to post of this forum with a language question in all the 10 years I have been using ColdFusion. I was a qa Engineer @ Allaire/Macromedia back when it was going from one to the other. I have a pretty good grasp of the language.
    I have software that runs off a list. The fieldnames are variable and stored off in an array. It's survey software that runs off a "meta file". In this example; I have the number of fields in the survey set to 12 in the "metafile". I have each field declared in that file in array Session.SurveyField[1] and the above loop works fine. I include this "metafile" at the start of the process.
    I cfloop around a struct and it works wherever I have needed to use it; such as here - writing to the database for example;
    <CFQUERY NAME="InsertRec" DATASOURCE="Survey">
    INSERT into #variables.SurveyTableName#
    (EntryTime
    <cfloop from="1" to="#Session.NumberOfSurveyFields#" index="arrayindex">
    ,#Session.SurveyField[arrayindex]#
    </cfloop>
    <!--- EXAMPLE OF WHAT THE ABOVE GENERATES
    ,q01_name,q02_AcadTechORNA,q03_Water,q04_FirstAid,q05_CPR,q06_LifeGuard,q07_AED
    ,q08_ProjAdv,q09_Color,q10_SantaClaus,q11_Supervisor,q12_SupervisorOpinion --->
       VALUES
        ('#EntryTime#'
    <cfloop from="1" to="#Session.NumberOfSurveyFields#" index="arrayindex">
    <cfset thisname = "Session." & Session.SurveyField[arrayindex]>
    ,'#evaluate(variables.thisname)#'
    </cfloop>
    <!--- EXAMPLE OF WHAT THE ABOVE GENERATES
    ,'#Session.q01_name#','#Session.q02_AcadTechORNA#','#Session.q03_Water#','#Session.q04_Fi rstAid#'
    ,'#Session.q05_CPR#','#Session.q06_LifeGuard#','#Session.q07_AED#','#Session.q08_ProjAdv# ',
    ,'#Session.q09_Color#','#Session.q10_SantaClaus#','#Session.q11_Supervisor#','#Session.q1 2_SupervisorOpinion#' --->
    </CFQUERY>
    NOW HERE'S THE PROBLEM: I am running into trouble when trying to move the form variables to session variables of the same name. It is the only part of the software that I still need the datanames hard coded and that is a roadblock for me.
    <cfloop from="1" to="#Session.NumberOfSurveyFields#" index="arrayindex">
    <cfset thissessionfield = "Session." & Session.SurveyField[arrayindex]>
    <cfset thisformfield = "Form." & Session.SurveyField[arrayindex]>
    <cfset #thissessionfield# = #evaluate(thisformfield)#>
    </cfloop>
    I have tried it with or without the "evaluate"; same result. It doesn't give an error; it just ignores them (session variables look as such in the next page in the chain)
    q01_name=
    q02_acadtechorna=
    q03_water=
    q04_firstaid=
    q05_cpr=
    q06_lifeguard=
    q07_aed=
    q08_projadv=
    q09_color=
    q10_santaclaus=
    q11_supervisor=
    q12_supervisoropinion=
    Note: they exist because I CFPARAM them in a loop like the above at the start of the procedure) - and this works just fine!
    <cflock scope="Session" type="EXCLUSIVE" timeout="30">
    <cfloop from="1" to="#Session.NumberOfSurveyFields#" index="arrayindex">
    <cfset dataname = "Session." & Session.SurveyField[arrayindex]>
    <cfparam name="#variables.dataname#" default="">
    </cfloop>
    </cflock>
    I EVEN tried exploiting the Form.Fieldnames list using CFLoop over the list and the same sort of logic within and it still gives me nothing....
    Here's the FORM.FIELDNAMES value
    "Q01_NAME,Q02_ACADTECHORNA,Q03_WATER,Q04_FIRSTAID,Q05_CPR,Q06_LIFEGUARD,Q07_AED,Q08_PROJAD V,Q09_COLOR,
    Q10_SANTACLAUS,Q11_SUPERVISOR,Q12_SUPERVISOROPINION"
    Here's the logic; SAME RESULT - The session variables don't get set.
    <cfoutput>
    <cfloop list="#Form.FieldNames#" index="thisfield">
    <!--- <br>#thisfield# --->
    <cfscript>
    thisSESSIONfield = "Session." & thisfield;
    thisFORMfield = "Form." & thisfield;
    #thisSESSIONfield# = #thisFORMfield#;
    </cfscript>
    </cfloop>
    </cfoutput>
    The CFPARAM in a loop with variable output name works just fine; so does the post (which I included above) as does the SQL Create, Param Form Variables, Param Session Variables, etc.
    THIS even works for moving BLANK to each session variable, to zero them all out at the end of the process;
    <cflock scope="Session" type="EXCLUSIVE" timeout="30">
    <cfloop from="1" to="#Session.NumberOfSurveyFields#" index="arrayindex">
    <cfset thislocalfield = Session.SurveyField[arrayindex]>
    <cfscript>
    thissessionfield = "Session." & thislocalfield;
    </cfscript>
    <cfset #thissessionfield# = "">
    </cfloop>
    </cflock>
    Expanding on that code, you would think this would work, but it doesn't;
    <cfloop from="1" to="#Session.NumberOfSurveyFields#" index="arrayindex">
    <cfset thislocalfield = Session.SurveyField[arrayindex]>
    <cfscript>
    thissessionfield = "Session." & thislocalfield;
    thisformfield = "Form." & thislocalfield;
    </cfscript>
    <!--- debug --->
    <!--- <cfoutput>#thissessionfield# = "#evaluate(thisformfield)#"</cfoutput><br> --->
    <cfoutput>
    <cfset #thissessionfield# = "#evaluate(thisformfield)#">
    </cfoutput>
    </cfloop>
    And see that debug code in the middle? To add insult to injury... When I uncomment that it shows me this. So it certainly looks like this should work....
    Session.q01_name = "Me"
    Session.q02_AcadTechORNA = "N/A"
    Session.q03_Water = "Yes (certificate expired)"
    Session.q04_FirstAid = "Yes (certificate is current)"
    Session.q05_CPR = "No"
    Session.q06_LifeGuard = "Yes (certificate expired)"
    Session.q07_AED = "Yes (certificate expired)"
    Session.q08_ProjAdv = "Yes (certificate expired)"
    Session.q09_Color = "Gray"
    Session.q10_SantaClaus = "Yes"
    Session.q11_Supervisor = "Da Boss"
    Session.q12_SupervisorOpinion = "Not a bad thing"
    There must be some simpler way to do this. This way won't work against all odds even though it seems so much like it should.
    So I end up having to hardcode it; still looking for an automated way to set these #@%$*@!## session variables over the list from the form variables of the same @#@!$#%$%# name. Do I sound frustrated???
    No matter what I do, if I don't HARDCODE like this;
    <cfset Session.q01_name = Form.q01_name>
    <cfset Session.q02_AcadTechORNA = Form.q02_AcadTechORNA>
    <cfset Session.q03_Water = Form.q03_Water>
    <cfset Session.q04_FirstAid = Form.q04_FirstAid>
    <cfset Session.q05_CPR = Form.q05_CPR>
    <cfset Session.q06_LifeGuard = Form.q06_LifeGuard>
    <cfset Session.q07_AED = Form.q07_AED>
    <cfset Session.q08_ProjAdv = Form.q08_ProjAdv>
    <cfset Session.q09_Color = Form.q09_Color>
    <cfset Session.q10_SantaClaus = Form.q10_SantaClaus>
    <cfset Session.q11_Supervisor = Form.q11_Supervisor>
    <cfset Session.q12_SupervisorOpinion = Form.q12_SupervisorOpinion>
    I always get this from my next page because the session variables are empty;
    You must answer question 1.
    You must answer question 2.
    You must answer question 3.
    You must answer question 4.
    You must answer question 5.
    You must answer question 6.
    You must answer question 7.
    You must answer question 8.
    You must answer question 9.
    You must answer question 10.
    I tried duplicate as well, but I can not get the above to work...
    Can anyone help me do this thing that one would think is simple????

    I think if you use structure array syntax you should get the results you want.
    <cfloop from="1" to="#Session.NumberOfSurveyFields#" index="arrayindex">
          <cfset session[Session.SurveyField[arrayindex]] = Form[Session.SurveyField[arrayindex]]>
    </cfloop>
    Or probably even easier.
    <cfset session = duplicate(form)>

  • A rant about C with a question at the end. :P

    C is okay. It's just really hard to understand.
    So this is my rant about it. It starts out by listing where I've been in terms of programming and then lists my difficulties with C itself.
    I discovered C many years ago. I'm not too sure how. All I know is that for many years I've wanted to know what this C thing was all about, but had no way or knowledge of how to. I didn't really know anybody before I got the 'net last year, so asking someone else was out of the question. Plus, I wouldnt've known what question(s) to ask.
    As I became more proficient with the whole technology thing, I began to go to the local libraries nearby and use their free internet access to look stuff up. But I didn't get the idea to do any research about C, most likely because I didn't have the mental capacity to plan well and my access was once or twice weekly at best. Plus, the only computer I had at home was 66MHz and ran DOS, and I only knew BASIC around that time which I was comfortable and content with, so wasn't looking for a new language. I think I knew about assembly language but didn't pursue it if I did.
    A couple of computer upgrades later, I finally got the 'net at home and began to see the convenience of being able to spontaneously look something up when I wanted to as good, rather than weird. Ideas gradually began to pop into my head that I'd run off and look up, and one day C became one of them. So I did some research on C and finally began to learn what it was: an incomprehensible mess of manually managed memory and low-level trickery. Since I knew a fair bit about assembly language now I decided C was worse than asm (and I had no chance of learning asm back then), and left it at that.
    Being the BASIC coder I was (pun intended), I found the syntax and concepts over my head by several miles. But the fascination never died, and kept poking at me again and again. And I just had to keep forgetting about it.
    I moved on from QuickBASIC, which I'd been using for just about everything, to FreeBASIC, which was in such a beta state when I tried it, I disliked it enough to move on and discovered PHP.
    PHP has been called the BASIC of the 21st century, and I can understand why. There are typically at least 10 ways to do something whether in principle or method, multiple functions do the same or an equivalent task, and overall it just doesn't look like a good language. But beyond all that, PHP made sense to me. As I went along many of the things I expected to perform in a given way performed in said way, which was a huge confidence boost. The model it followed might have been convoluted, but something inside my head "clicked" when I saw PHP, so I liked it, since I could understand it easily.
    But recently, I found myself hitting too many walls. I wanted to get into graphical software development, and none of the graphical extensions PHP had available would work for me. PHP-GTK did work but prevented PHP from outputting anything as an Apache module, without throwing a single error anywhere. PHP-QT wouldn't compile on my system. PHP-TK did compile, but both segfaulted when any tk_* function was called and also exhibited the Apache module issue.
    So I decided then and there that I needed to switch languages.
    The problem was, my current machine happens to be so slow that a GIMP operation that executes in 6 seconds on the lowest generation AMD CPU from 4-5 years ago will execute in 38 seconds on mine. I have no idea why; the machine is, after all, 2.66GHz.
    Although PHP is pretty snappy on my system, I don't know how other languages would fare and don't really want to risk the experiment; I want to switch to a language I know will be as fast as, or faster than, PHP. So I decided that a compiled language would have to be it, since I regarded PHP as the fastest language I knew. I was probably wrong, but whatever.
    So I set my mind to understanding C. I'd asked around online before, and someone took pity on me and explained the basics of C and I did my best to understand them. This was great for a couple of days, but didn't last all that long unfortunately. So I asked around again, dreading their responses, and with good reason too: most of the tutorials I read often left me boggled and flew over my head at one point or another, which didn't help.
    But I got some dreaded tutorial links, and did my best to read them. It took me a couple of weeks to finally convince my brain to understand the point of a language that utilizes variables that doesn't contain any data, but instead references to other variables. I eventually grasped the why, but am still having quite a hard time understanding the how.
    So then, after that initial hurdle, I moved onto other topics. Or rather tried to. I quickly discovered that C interconnects some of its issues so deeply that it's hard to learn one thing at a time, move on and learn the next thing - how I best learn. I don't create paths very well by reading information; I create those paths by staying away from information and letting it slowly process in my mind. But to actually remember it in the first place, it needs to make sense, and C doesn't make sense because things are so interconnected and... we come full circle.
    To be honest, after about a fortnight of trying to understand pointers, I still don't understand them. I've read what is probably the best the web has to offer about pointers. Has it helped? Not really.
    Either the documentation:
    - is too terse and I have to slow down, risking losing interest in what I'm reading
    - skips over vital points or assumes I know Pascal or some other language
    - is hard to understand or is poorly written
    - puts segments in the wrong order, so I don't understand everything something might depend on before I reach that something
    ...and in general I either give up on reading the documentation, give up on C or just cry. I've done the 3rd a few times, the 2nd quite a few times and the 1st pretty much as many times as I've read documentation.
    So what are my issues with C?
    Let me address the two I can think of right now:
    Pointers aren't addressed "simply"; if I declare a pointer to int named x I have to use *x to access what x points to, rather than use *x to get x's location, like one does with non-pointer variables where & is used to get an address. It'd be nice if we used &x to get x's value if x wasn't a pointer and *x to get x's value if x was a pointer, rather than use this convoluted scheme.
    Also, I've heard that it's a common misconception that C handles arrays natively. Elsewhere, I've heard that strings are merely arrays of char. I can understand the 2nd, but what do I do with the 1st?
    I do understand that if I say printf("%d\n", x[1]) I'm effectively saying x++; printf("%d\n", x), but I don't understand how this fully works. For example, let us consider the following code:
    char *filename = "<insert file here>";
    int i;
    struct stat filebuffer;
    int status;
    FILE *handle;
    handle = fopen(filename, "r");
    status = stat(filename, &filebuffer);
    char *buffer = malloc(filebuffer.st_size);
    for (i = 0; i < filebuffer.st_size; i++) buffer[i] = fgetc(handle);
    printf("%s\n", buffer);
    You'll of course notice the array notation. Do I understand why if I replace said notation with something to the effect of...
    buffer++
    buffer = fgetc(handle);
    ...the program segfaults? No. Likewise, I don't understand why the...
    buffer++
    *buffer = fgetc(handle);
    ...in the loop does work, printf("%s"...); causes segfaults and printf("%d"...); does not.
    Another thing I found is that declaring a char *, filling it with data, and then using memcpy on said char *, the program works fine, but if I declare for example char x[1] = "hi"; the compiler will shout at me for not allocating enough arrays. Only while writing this did I realize that the 2nd element is for the null byte.
    Suffice to say that C confuses me. To bits. Although I have written a 500 line program in it (579 to be exact). All said program does is display a message on the screen via Xlib, but I managed to figure out how to make a word wrapping engine using strsep and how to use XDrawPoint XDrawLine to not only create a nice UI but also let me define various UI "styles" which can be loaded at startup.
    Said program uses a very big helping of "if it doesn't work stab it until it does", so not only do I not understand how a lot of it works, it probably wouldn't compile under anything except gcc. Which is from a theory perspective quite a problem, IMHO. Almost every 2nd variable is typecast to this or that type.
    So put simply, every tutorial or introduction to C hasn't made a lot of sense to me. Maybe I learn slowly; I'm hoping it's that, because I can't see anything besides assembly language which would be faster than C. I plan to learn asm after I've mastered the very basics of C, but I may end up having to learn the other way around if I expect to get anywhere.
    Like I said in the title, I have one actual question in this post. So here it is:
    Are there any fun, easy reading tutorials out there that don't visually look like they came out of 1992 and read like http://poignantguide.net/ or http://learnyouahaskell.com/?
    -dav7

    dav7 wrote:Pointers aren't addressed "simply"; if I declare a pointer to int named x I have to use *x to access what x points to, rather than use *x to get x's location, like one does with non-pointer variables where & is used to get an address. It'd be nice if we used &x to get x's value if x wasn't a pointer and *x to get x's value if x was a pointer, rather than use this convoluted scheme.
    Pointer syntax is extremely unfortunate. The best part:
    char *a; // It's a pointer.
    *a; // It's a character. Good move, guys.
    Also, I've heard that it's a common misconception that C handles arrays natively. Elsewhere, I've heard that strings are merely arrays of char. I can understand the 2nd, but what do I do with the 1st?
    Insofar as C has arrays, C strings are character arrays. C arrays are just a promise that the system won't mess within a certain set of memory addresses. Array syntax is a concise way to calculate and dereference a specific location in memory, relative to an address that you hope is the beginning of some memory you reserved. array[n] = *(array + n), right? Personally, I would have left out the subscript notation entirely. Regardless, any time you choose to use brackets, you can mentally substitute in an explicit addition and dereference there. You're saying, "Give me the number stored at the memory address I have just calculated, which I know by my science holds something I put there intentionally, and not garbage at all."
    One more clarification with regard to pointer arithmetic is necessary: when you add 2 to an int*, the resulting address is actually 2*sizeof(int) bytes after your base address. Same for a double*: 2*sizeof(double).
    I do understand that if I say printf("%d\n", x[1]) I'm effectively saying x++; printf("%d\n", x), but I don't understand how this fully works.
    It's not the same! First of all, in example #2, you're passing a pointer to an int. In example #1, you're passing an integer, since [] dereferences pointers for you. Any time you use those brackets, it's as if you had typed an asterisk yourself. Second, in example #1 you're not messing with x. In example #2 you're incrementing x by four bytes (the likely size of one integer). Doesn't make a difference in this short example, but if x ever gets used again it will be very significant.
    Another thing I found is that declaring a char *, filling it with data, and then using memcpy on said char *, the program works fine, but if I declare for example char x[1] = "hi"; the compiler will shout at me for not allocating enough arrays. Only while writing this did I realize that the 2nd element is for the null byte.
    Looks like a counting problem. Arrays are indexed from 0, but sizes are specified from 1 on up. Your "char x[1]" has only index [0]. To hold a two-character string, you'll need at least size three (char x[3]), so that x[0]='h', x[1]='i', x[2]='\0', the null terminator.
    Suffice to say that C confuses me. To bits.
    Any time you get confused by pointers or arrays (which are the same thing), take a step back and think about what's happening in terms of memory addresses. Draw it out on paper if you think you're making a mistake. In some languages you can ignore low-level details like that and write perfectly fine programs, even though you won't be able to optimize them without knowing how your code maps onto the machine. But in C, everything that looks like a high-level feature is just shorthand for setting a few bytes to different numbers, and the abstraction is so leaky that you can't get by without understanding it. Types are just a way for the compiler to catch dumb mistakes (some people believe this is helpful) and to automate some math, like the pointer arithmetic above. In a running program there are no types, so when you're trying to figure out what a program is actually doing, you need to consider what the types are shorthand for.
    If you're having trouble "thinking like a programmer", by which I mean sanity-checking your use of syntax and stepping through a program so you know what it does, you might want to get up to speed in a different language, or by working through a book on algorithms.
    Last edited by pauldonnelly (2008-11-03 22:54:12)

  • Purchase order sample - drop down list populating another drop down list

    hello, when i use this sample script, it works fine. but when i add additional arrays to it, it doesn't work at all. please let me know what i need to change in this script in order to add additional items into the drop down lists. here is the script that works (displays 3 options in first drop down list (blank, option, another option)):
    // This script object controls the interaction between the carrier and plan Drop-down lists.
    // The array contains the carriers and the corresponding plans.
    var myCarriers = new Array(new Array(2), new Array(14), new Array(17)); // Create a two-dimensional array.
    // For each carrier, add a 'new Array(number of plan +1)'.
    // Define the carrier and the corresponding plans.
    // The array syntax is arrayName[index][index].
    // The first index number represents the carrier,
    // the second index number is the actual data value.
    myCarriers[0][0] = " "; // The first items in the Drop-dowm Lists should be blank.
    myCarriers[0][1] = " ";
    myCarriers[1][0] = "ANERT"; // The first data value is the carrier name,
    myCarriers[1][1] = "MC250"; // the rest are plans.
    myCarriers[1][2] = "MC2501";
    myCarriers[1][3] = "MC5002";
    myCarriers[1][4] = "MC5003";
    myCarriers[1][5] = "MC1000";
    myCarriers[1][6] = "MC2000";
    myCarriers[1][7] = "MCHC2300";
    myCarriers[1][8] = "MCHC3000";
    myCarriers[1][9] = "MC2500";
    myCarriers[1][10] = "MB";
    myCarriers[1][11] = "P500";
    myCarriers[1][12] = "MHH3000";
    myCarriers[1][13] = "MHH5000";
    myCarriers[2][0] = "BCCA"; // This is a new carrier, see how the first number is now [1].
    myCarriers[2][1] = "S Plan";
    myCarriers[2][2] = "BPlan";
    myCarriers[2][3] = "P40";
    myCarriers[2][4] = "P30";
    myCarriers[2][5] = "P35*";
    myCarriers[2][6] = "P45*";
    myCarriers[2][7] = "Ad25*";
    myCarriers[2][8] = "Pr20";
    myCarriers[2][9] = "Pr10";
    myCarriers[2][10] = "PH750*";
    myCarriers[2][11] = "PH500*";
    myCarriers[2][12] = "2400HD";
    myCarriers[2][13] = "3500HD";
    myCarriers[2][14] = "2000HD";
    myCarriers[2][15] = "LH1500";
    myCarriers[2][16] = "LH3000";
    // This function will populate the carrier Drop-down List.
    // This function is called from the initialize event of the carrier Drop-down List.
    function getCarriers(dropdownField)
    dropdownField.clearItems();
    for (var i=0; i < myCarriers.length; i++)
    dropdownField.addItem(myCarriers[i][0]);
    // This function will populate the plans Drop-down List for any event EXCEPT the change event.
    // This function is called by the initialize event of the plan Drop-down List.
    function getPlans(carrierField, dropdownField)
    dropdownField.clearItems(); // Clear the items of the Drop-down List.
    for (var i=0; i < myCarriers.length; i++) // Look through all the carriers until we find the one that matches the carrier selected.
    if(myCarriers[i][0] == carrierField.rawValue) // Check to see if they match.
    for (var j=1; j < myCarriers[i].length; j++) // When they match, add the plans to the Drop-down List.
    dropdownField.addItem(myCarriers[i][j]);
    dropdownField.rawValue = myCarriers[i][1]; // Display the first item in the list.
    // This function will populate the plans Drop-down List for the change event.
    // This function is called by the change event of the carrier Drop-down List.
    // The first parameter is simply a pointer to the xfa object model.
    function getPlansOther(myXfa, dropdownField)
    dropdownField.clearItems(); // Clear the items of the Drop-down list.
    for (var i=0; i < myCarriers.length; i++) // Look through all the carriers until we find the one that matches the carrier selected.
    if(myCarriers[i][0] == myXfa.event.newText) // Check to see if they match. Note: we have to use the event.newText in this case because
    { // the ch

    continued...
    change hasn't been committed yet.
    for (var j=1; j < myCarriers[i].length; j++) // When they match, add the states/provinces to the Drop-down List.
    dropdownField.addItem(myCarriers[i][j]);
    dropdownField.rawValue = myCarriers[i][1]; // Display the first item in the list.
    when i try to add 4 more arrays (add items to first drop down list and second drop down list), nothing displays in either drop down lists. please let me know the items that need to be changed - besides these items (i know i need to add arrays and add myCarriers[1][0],[2][0],[3][0] to [6][0] --- for 4 additional items in the first drop down):
    var myCarriers = new Array(new Array(2), new Array(14), new Array(17)); // Create a two-dimensional array.
    // For each carrier, add a 'new Array(number of plan +1)'.
    // Define the carrier and the corresponding plans.
    // The array syntax is arrayName[index][index].
    // The first index number represents the carrier,
    // the second index number is the actual data value.
    myCarriers[0][0] = " "; // The first items in the Drop-dowm Lists should be blank.
    myCarriers[0][1] = " ";
    myCarriers[1][0] = "ANERT"; // The first data value is the carrier name,
    myCarriers[1][1] = "MC250"; // the rest are plans.
    myCarriers[1][2] = "MC2501";
    myCarriers[1][3] = "MC5002";
    any help would be greatly appreciated. thank you!

  • Get Fields In Table Dynamically

    I am trying to create a dynamic query that will allow me to
    query a table, pull all of the fields and dump all of the data into
    a text file: I have been able to make the dynamic query, but I am
    unable to display all of the data on the page when I loop through
    my fields... Does anyone know how to do this... Here is my query to
    get the fields dynamically... How would I go about actually
    querying the datasource and grabbing all of the data from the
    fields?
    <cfquery name="getfields" datasource="#db#">
    select *
    from billing
    </cfquery>
    <cfset thecolumnlist = getfields.columnlist>
    <cfloop list="#thecolumnlist#" index="i">
    <cfoutput>
    #i#
    </cfoutput>
    </cfloop>
    Thanks to anyone who can help me!!!

    There are pros/cons to using SELECT *. Its easier typing, but
    more db work. Its also easier
    to accidentally include columns like "Password" or "Salary".
    You can output the query values using array syntax:
    #QueryName[ColumnName][rowNumber]# .
    <cfoutput query="getFields">
    <cfloop list="#getfields.ColumnList#"
    index="columnName">
    #getFields[columnName][currentRow]#
    </cfloop>
    <br/>
    </cfoutput>
    There are a few functions at cflib.org for converting a query
    to a CSV file
    http://www.cflib.org/udf.cfm?id=1197.
    http://www.cflib.org/udf.cfm?ID=404
    Or you could do it yourself. Loop through the query and
    append the values to a string variable, adding a newline after each
    record. Use cffile if you want to save the output to disk. Use
    cfcontent/cfheader if you want the output to be downloaded. This is
    a popular question so there are many examples. Google for
    ColdFusion CSV or ColdFusion CSV download

  • How to create a loop?

    I have this function:
    private function setUpHeaders():void {
    sLabel1 = xmlData.step1.ing..title+" -
    "+xmlData.step1..amt+":";
    sLabel2 = xmlData.step2.ing..title+" -
    "+xmlData.step2..amt+":";
    sLabel3 = xmlData.step3.ing..title+" -
    "+xmlData.step3..amt+":";
    sLabel7 = xmlData.step7.ing..title+" -
    "+xmlData.step7..amt+":";
    It lloks like an excellent candidate for a loop. However, the
    attempts I made at a "for" loop failed. How would you folks make a
    loop here?

    I am not sure of the class of the xmlData object, and I am
    also uncertain of what the "..title" and "..amt" notation means,
    but in general it is possible to use the array syntax in AS for
    properties. I would try:
    for (var i: int = 1; i < 8; ++i)
    this["sLabel" + i] = xmlData["step" + i]..title + "-" +
    xmlData["step" + i]..amt + ";";
    You may need to cast the properties from the xmlData object
    in order to apply the "..title" and "..amt" accessors.
    You can access properties in any Object using brackets and a
    string within the brackets.

Maybe you are looking for

  • Error parsing a XML file

    Hi! I'm using the package org.apache.xerces when I run this code: DOMParser parser= new DOMParser(); parser.parse(new InputSource(new FileInputStream("test.xml"))); Document doc=parser.getDocument(); Node node=(Node)doc; NodeList nodeList = node.getC

  • Will DVD studio Pro convert Real Media

    I have some real media clips and I want to convert them and burn them to DVD. Will DVD studio Pro convert them. IF they will how long will it take for 50 mins of video. Thanks

  • Netra t1 with solaris 9 fresh install on/standby switch

    Hi, I recently installed solaris 9 onto my Netra 105 box. For the likes off me I can't figure out why the on/standby switch simply does not work since reinstalling. The only way I can power down the box is by literally unplugging it from the wall. I

  • Essbase admin server is not responding in 11.1.2.2 and related services ??

    Hi All, I've installed & configured Hyperion 11.1.2.2. When i entered admin & password in EAS console, the message is displaying as Essbase Administration server is not responding. Can you pls. let me know, what is the service for Essbase Admin servi

  • Not able to save Objects  in Oraganisational management

    Dear Gurus, When i am creating Objects in OM system was given error message it is not saving objects, objects are creating in golden master server but unable to create objects in testing and quality. Please guide me how ti solve this issue.