Indigo Rose Software

Professional Software Development Tools

 
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Oct 2004
    Posts
    11

    Huh? Table, row and column

    I have a table (shopping cart) with the following data in:

    2;;Rotherham - Case Study;;1
    1;;Wincanton - Case Study;;1
    1;;Wincanton - Case Study;;1
    2;;Rotherham - Case Study;;1


    The user can add and remove any number of items from their list.

    OK I can create a table from the text file:
    basket = TextFile.ReadToTable("C:\\MyFile.txt");
    I can return the indiviual rows:
    Dialog.Message("Test", basket[1], MB_OK, MB_ICONNONE, MB_DEFBUTTON1)
    Or
    Dialog.Message("Test", basket[2], MB_OK, MB_ICONNONE, MB_DEFBUTTON1)

    But how can I return the indiviual values from a row?
    i.e.
    Dialog.Message("Test", "Wincanton - Case Study", MB_OK, MB_ICONNONE, MB_DEFBUTTON1)
    Or
    Dialog.Message("Test", "1", MB_OK, MB_ICONNONE, MB_DEFBUTTON1)


    Any takers?

  2. #2
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    try:

    Dialog.Message("Test", basket[1][2], MB_OK, MB_ICONNONE, MB_DEFBUTTON1)

    [1] = row
    [2] = column

  3. #3
    Join Date
    May 2003
    Location
    Pendleton, Oregon
    Posts
    1,038
    How about after getting a line from your text file, you use the String.Replace action to replace the ;; with a comma, then read that in as a table that you can quarry. For this example I’ll refer to that ‘sub table’ as ‘sub_basket’

    Dialog.Message("Test", "Wincanton - Case Study", MB_OK, MB_ICONNONE, MB_DEFBUTTON1)

    might become something like:
    Dialog.Message("Test", sub-basket[2], MB_OK, MB_ICONNONE, MB_DEFBUTTON1)
    Add-ons for AMS. Toolbar Buttons Galore, System Animations, the Window Construction Kit, and more.
    Visit Acme-Tek

  4. #4
    Join Date
    Oct 2003
    Posts
    164
    If you set the table up as an associative array then you could do something along these lines...

    Code:
    tBasket = { FirstElement="2", SecondElement="Rotherham - Case Study", ThirdElement="1"};
    
    Dialog.Message("Element 'first' contains:", tBasket.SecondElement);
    -Scott F.

  5. #5
    Join Date
    May 2003
    Location
    Pendleton, Oregon
    Posts
    1,038
    Sorry Worm, didn’t see your post. That’s cool, as soon as I get my head around it. Thanks, I learn something new each day.
    Add-ons for AMS. Toolbar Buttons Galore, System Animations, the Window Construction Kit, and more.
    Visit Acme-Tek

  6. #6
    Join Date
    Oct 2003
    Posts
    164
    Right On! I was a bit slow on the reply button myself.
    -Scott F.

  7. #7
    Join Date
    Oct 2004
    Posts
    11

    Doesn't work for me

    Hi Worm,

    Thanks for getting back to me.
    It doesn't work for me.

    -- Start load basket
    basket = TextFile.ReadToTable("C:\\MyFile.txt");
    basket_total = Table.Count(basket);
    Label.SetText("basket_ammount", basket_total);
    -- End load basket

    Dialog.Message("Test", basket[1][2], MB_OK, MB_ICONNONE, MB_DEFBUTTON1)

    if (basket ~= "") then
    for n=1, basket_total do
    ListBox.AddItem("basket_list", basket[n][2], "");
    end
    end


    I'd upload the project but the upload function doesn't work!!

  8. #8
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Oops! I apologize. I thought the data you were showing was merely a representation of the table, and the ;; was a field delimter. Now I see that your table actually has only 1 column which contains delimited fields. That being the case, you'll need to get a little more tricky.

    Here's a function that will return a field/column of a delimited string. Put it in your Global Functions.

    Code:
    function GetDelimField(sSourceIn, sDelim, nField)
    	nFieldCtr = 1
    	if String.Right(sSourceIn, String.Length(sDelim)) ~= sDelim then
    		sSourceIn = sSourceIn..sDelim
    	end
    	nFind = String.Find(sSourceIn, sDelim, 1, false)
    	sReturn = ""
    	if nFind ~= -1 then
    		while nFind > -1 do
    			if nFieldCtr == nField then
    				sReturn = String.Left(sSourceIn, nFind -1)
    				nFind = -1
    			else
    				sSourceIn = String.Mid(sSourceIn, nFind + String.Length(sDelim), -1)
    				nFind = String.Find(sSourceIn, sDelim, 1, false)
    				nFieldCtr = nFieldCtr + 1
    			end 
    		end
    	else
    		sReturn = sSourceIn
    	end	
    	return sReturn
    end
    Use it like this:

    Code:
    -- Start load basket
    basket = TextFile.ReadToTable("C:\\MyFile.txt");
    basket_total = Table.Count(basket);
    Label.SetText("basket_ammount", basket_total);
    -- End load basket
    
    Dialog.Message("Test", basket[1][2], MB_OK, MB_ICONNONE, MB_DEFBUTTON1)
    
    if (basket ~= "") then
         for n=1, basket_total do
              sResult = GetDelimField(basket[n],";;",2);
              ListBox.AddItem("basket_list", sResult, "");
         end
    end

  9. #9
    Join Date
    Oct 2004
    Posts
    11
    Fantastic Worm.

    Cheers mate

  10. #10
    Join Date
    Oct 2004
    Posts
    11
    Is there a better way to write out the text file?
    I don't have to write it out in that format!

  11. #11
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    If you are getting the desired results, then no, there isn't a better way. There may be a more efficient way, but is recoding worth the miliseconds you might save, probably not.

    What app are you writing the file out from?

  12. #12
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Quote Originally Posted by embine
    Is there a better way to write out the text file?
    I don't have to write it out in that format!
    If you are are building a shopping cart, have you thought of using a SQL Database to store the information or even just a table until the shopper checks out? Does it need to be written to a file?
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  13. #13
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Exactly where I was going Tig, that's why I asked what program was writing out the text file.

  14. #14
    Join Date
    Oct 2004
    Posts
    11
    No it doesn't need to be a text file, I guess it's the web developer in me wanting to write a cookie!!!
    I guess I could create a SQlite database on the users PC just as easily!!

    Thanks for the reality check guys.

    PS
    Have either of you decided about my proposal?

  15. #15
    Join Date
    Oct 2004
    Posts
    11
    The text file is being written out by AM5 by the way

Page 1 of 2 1 2 LastLast

Similar Threads

  1. SQLite – Column names and number of columns
    By csd214 in forum AutoPlay Media Studio 5.0
    Replies: 7
    Last Post: 08-17-2004, 09:55 AM
  2. Text File, Strings, ???
    By tbybee in forum AutoPlay Media Studio 5.0
    Replies: 4
    Last Post: 02-08-2004, 03:39 PM
  3. Easily Convert Spreadsheet to AMS5 Table
    By kpsmith in forum AutoPlay Media Studio 5.0
    Replies: 1
    Last Post: 12-11-2003, 08:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts