ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 16th, 2005, 10:33 AM
midimidi midimidi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 83 midimidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 29 m
Reputation Power: 4
Insert Structure into 2-dimensional Array?

Introduction - I'm just learning arrays and structures in CF MX. I am making a schedule with Mon-Sun up top and 9am-2am the following day going down the left-most column.

I have already accomplished this using one very lengthy method, but I'm trying to combine it all into one big cfloop.

What I want to know as of now...

I have a 2-dimensional Array where we have say TimeArray[timeofday][episode]. I would like to make "episode" as a structure consisting of two keys - one for the episode name, and a second signifying a rowspan number (i.e. if episode = 30 minutes then rowspan = 1. if episode = 1 hour then rowspan = 2, etc.). So in the end, I can reference as something like:

TimeArray[9:00am][Episode.Name AND Episode.Rowspan]

Is this even possible? I have most of the logic down, but I can't seem to figure out how to attach this structure for each element in the second portion of the array. I keep getting things like "Object of type class java.lang.String cannot be used as an array" etc.


The basics of the code I have so far is attached below. This is of course NOT LITERAL, but summarized. It is basically searching through a database for a specific time, then adding it to the array when found:

Code:
<cfset Time_Start = CreateTime(09,00,00)>
<cfset TimeArray = ArrayNew(2)>

<cfloop index="time" from="1" to="36">
  <cfset TimeArray[time] = Time_Start>

  <cfloop index="SearchAllEpisodes" from="1" to="#scheduledata.end#">
    <cfif scheduledatabase.Time = Time_Start>
      <cfset CurrentEpisode = scheduledata.Episode[SearchAllEpisodes]>
      <cfset Episodes = structNew()>
      <cfset Episodes.Name = CurrentEpisode>

      <cfif scheduledata.Duration[SearchAllEpisodes] = 30 minutes>
        <cfset Episodes.Rowspan = "1">
      <cfelseif scheduledata.Duration[SearchAllEpisodes] = 1 hour>
        <cfset Episodes.Rowspan = "2">
      </cfif>


      <CODE HERE to somehow append the structure Episodes to each element in second dimension of TimeArray[time]>


    </cfif>
  </cfloop>

  <cfset Time_Start = Time_Start + 30 minutes>
</cfloop>

Reply With Quote
  #2  
Old February 16th, 2005, 11:45 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,700 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 17 h 45 m 21 sec
Reputation Power: 53
Quote:
Originally Posted by midimidi
Introduction - I'm just learning arrays and structures in CF MX. I am making a schedule with Mon-Sun up top and 9am-2am the following day going down the left-most column.

I have already accomplished this using one very lengthy method, but I'm trying to combine it all into one big cfloop.

What I want to know as of now...

I have a 2-dimensional Array where we have say TimeArray[timeofday][episode]. I would like to make "episode" as a structure consisting of two keys - one for the episode name, and a second signifying a rowspan number (i.e. if episode = 30 minutes then rowspan = 1. if episode = 1 hour then rowspan = 2, etc.). So in the end, I can reference as something like:

TimeArray[9:00am][Episode.Name AND Episode.Rowspan]

Is this even possible?


Not like that, first of all an array is indexed numerically, there is no way you have an array that is indexed like timeArray[9:00am]. It can only be something like timeArray[1].

But you can make episode a structure and do it like this:

#timeArray[1].episode.name# #timeArray[1].episode.rowSpan#

You'd do that like this:

<cfscript>
timeArray = arrayNew(1);
timeArray[1].episode = structNew();
timeArray[1].episode.name = "the name";
timeArray[1].episode.rowSpan = 5;
// and if you wanted to have the time as a structure element...
timeArray[1].episode.time = "9:00 am";
</cfscript>
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old February 16th, 2005, 11:53 AM
midimidi midimidi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 83 midimidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 29 m
Reputation Power: 4
Quote:
Originally Posted by kiteless
Not like that, first of all an array is indexed numerically, there is no way you have an array that is indexed like timeArray[9:00am]. It can only be something like timeArray[1].

But you can make episode a structure and do it like this:


Thanks - I'll try this out.

The 9:00am reference was just an example piece of data. I wasn't being literal.

Reply With Quote
  #4  
Old February 16th, 2005, 12:00 PM
midimidi midimidi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 83 midimidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 29 m
Reputation Power: 4
I keep getting the following error. Could someone explain this to me in simple terms?

"You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members."

For instance - why doesn't something as simple as the following work?! Here I get "The element at position 1 of dimension 1, of array variable "TIMEARRAY," cannot be found. "

Code:
<cfset timeArray = ArrayNew(1)>

<cfloop index="i" from="1" to="36">
  <cfscript>
    timeArray[i].Episodes = structNew();
    timeArray[i].Episodes.Name = "CurrentEpisode";
  </cfscript>
</cfloop>



There's some very basic syntax that I'm missing here and there, and every once in a while it drives me nuts!

Reply With Quote
  #5  
Old February 17th, 2005, 07:48 AM
midimidi midimidi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 83 midimidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 29 m
Reputation Power: 4
Quote:
Originally Posted by kiteless
<cfscript>
timeArray = arrayNew(1);
timeArray[1].episode = structNew();
timeArray[1].episode.name = "the name";
timeArray[1].episode.rowSpan = 5;
// and if you wanted to have the time as a structure element...
timeArray[1].episode.time = "9:00 am";
</cfscript>


Confused kiteless...have you tried this code yourself? It comes back with said error above:

"The element at position 1 of dimension 1, of array variable "TIMEARRAY," cannot be found."

Reply With Quote
  #6  
Old February 17th, 2005, 08:08 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,700 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 17 h 45 m 21 sec
Reputation Power: 53
No I wrote it off the top of my head. This works:

<cfscript>
timeArray = arrayNew(1);
timeArray[1] = structNew();
timeArray[1].episode = structNew();
timeArray[1].episode.name = "the name";
timeArray[1].episode.rowSpan = 5;
// and if you wanted to have the time as a structure element...
timeArray[1].episode.time = "9:00 am";
</cfscript>

Reply With Quote
  #7  
Old February 17th, 2005, 10:56 AM
midimidi midimidi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 83 midimidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 29 m
Reputation Power: 4
This makes sense now - thank you!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Insert Structure into 2-dimensional Array?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT