Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 11 of 11
  1. #1
    Join Date
    Jul 2004
    Posts
    313

    Arrays and ListBox{}

    Hi Guys,

    I am using this code to get my information from php as an AMS Array (I think it's an AMS Array)

    Code:
    
    ClickHTTPReq = luacom.CreateObject("WinHttp.WinHttpRequest.5.1") 
    if not ClickHTTPReq then 
    return 
    end 
    
    vars = "ian";
    ClickHTTPReq:Open("GET", "http://localhost/lua/index.php?fname=".. vars, 0) 
    ClickHTTPReq:Send(); 
    if ClickHTTPReq.Status ~= 200 then 
    return 
    end 
    
    phpCompanies = ClickHTTPReq.ResponseText
    
    // I tried adding this to retrieve the php return which is [echo "me, and, mydog";] unfortunatley it only displays me, and, mydog on the first line without breaking it up.
    
    ListBox.AddItem("companiesList",phpCompanies);
    If anyone can please help with getting all these values into the listBox it will be great.

  2. #2
    Join Date
    Jul 2004
    Posts
    313
    Still working on this one

    Here is what i have now

    Code:
    
    ClickHTTPReq = luacom.CreateObject("WinHttp.WinHttpRequest.5.1") 
    if not ClickHTTPReq then 
    return 
    end 
    
    vars = "ian";
    ClickHTTPReq:Open("GET", "http://localhost/lua/index.php?fname=".. vars, 0) 
    ClickHTTPReq:Send(); 
    if ClickHTTPReq.Status ~= 200 then 
    return 
    end 
    -- I can get this to work with this --
    phpCompanies = {"me","and","mydog"};
    
    -- BUT NOT THIS --
    -- phpCompanies = ClickHTTPReq.Response.Text
    -- My PHP File is Returning {"me","and","mydog"};
    
    for varTitle,varValue in phpCompanies do
         ListBox.AddItem("companiesList",varValue);
    end

  3. #3
    Join Date
    Jan 2007
    Posts
    56

    Grin

    Will this work for you?:

    In AMS Program:
    Code:
    ClickHTTPReq = luacom.CreateObject("WinHttp.WinHttpRequest.5.1") 
    if not ClickHTTPReq then 
    return 
    end 
    
    vars = "ian";
    ClickHTTPReq:Open("GET", "http://localhost/lua/index.php?fname=".. vars, 0) 
    ClickHTTPReq:Send(); 
    if ClickHTTPReq.Status ~= 200 then 
    return 
    end 
    
    phpCompanies = {ClickHTTPReq.ResponseText};
    
    Debug.ShowWindow(true);
    
    Table.Sort(phpCompanies, nil);
    
    for x,y in phpCompanies do
        Debug.Print(y.."\r\n");
    end
    
    for varTitle,varValue in phpCompanies do
    ListBox.AddItem("ListBox1", varValue, "");
    end

    In PHP Script:
    Code:
    echo "me,\r\nand,\r\nmydog";
    Peace

  4. #4
    Join Date
    Jul 2004
    Posts
    313
    Thanks,

    Unfortunatley this is returning me, and, mydog on 1 line.

  5. #5
    Join Date
    Jan 2007
    Posts
    56
    OK, this isn't pretty, but it works:

    AMS Code:
    Code:
    ClickHTTPReq = luacom.CreateObject("WinHttp.WinHttpRequest.5.1") 
    if not ClickHTTPReq then 
    return 
    end 
    
    vars = "ian";
    ClickHTTPReq:Open("GET", "http://localhost/lua/index.php?fname=".. vars, 0) 
    ClickHTTPReq:Send(); 
    if ClickHTTPReq.Status ~= 200 then 
    return 
    end 
    
    sString = String.Replace(ClickHTTPReq.ResponseText, ",", "\r\n", false);
    TextFile.WriteFromString("C:\\MyFile.txt", sString, false);
    phpCompanies = TextFile.ReadToTable("C:\\MyFile.txt");
    
    for varTitle,varValue in phpCompanies do
    ListBox.AddItem("ListBox1", varValue, "name");
    end

    PHP Code:
    Code:
    print("me,and,mydog");
    I tried it, and it seems to separate the lines in the ListBox.

  6. #6
    Join Date
    Jul 2004
    Posts
    313
    Code Ranger thanks very much for your effort on this one,

    Your a star

    Very much appreciated

  7. #7
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    If you want to get what is returned by the PHP script, you can just use this.

    Code:
    result = HTTP.Submit("http://localhost/lua/index.php", {fname="ian"}, SUBMITWEB_POST, 20, 80, nil, nil);
    You can use this function to convert a comma separated string into a table. This function is in the scripts folder.

    Code:
    function DelimitedStringToTable(DelimitedString, Delimiter)
    	tbReturn = {};
    	local strWorking;
    	local nPos = nil;
    	local strData;
    	local nTableIndex = 1;
    	local nDelimiterLength = String.Length(Delimiter);
    	
    	if(nDelimiterLength < 1)then
    		tbReturn[nTableIndex] = DelimitedString;
    		return tbReturn;
    	end
    	
    	strWorking = DelimitedString;
    	nPos = String.Find(strWorking,Delimiter);
    	while(nPos ~= -1)do
    		strData = String.Left(strWorking,nPos-1);
    		tbReturn[nTableIndex] = strData;
    		nTableIndex = nTableIndex + 1;
    		local nLength = String.Length(strWorking);
    		strWorking = String.Right(strWorking,nLength - (nPos + (nDelimiterLength-1)));
    		nPos = String.Find(strWorking,Delimiter);
    	end
    	if(strWorking ~= "")then
    		tbReturn[nTableIndex] = strWorking;
    	end
    	
    	return tbReturn;
    end
    So if you have the PHP script return like this echo("me,and,my,dog"), you can use this function to convert it to a table and then step through the table and add the values to the listbox. Removes the need to write text files etc.
    Last edited by Dermot; 02-22-2007 at 11:42 PM.
    Dermot

    I am so out of here

  8. #8
    Join Date
    Jan 2007
    Posts
    56

    Grin

    Hi Dermot,

    Excellent solution!

    Like Ian, I too need this type of solution for an application I've been working
    on, but one problem that I'm noticing with all of these, is that it seems to
    kind of freeze up the application until it finishes with connecting and receiving
    the data back into the app.

    Is there any way that you know of so the app doesn't go through this
    momentary application freeze or are we kind of stuck with it?

    Thanks for you help,
    Patrick

  9. #9
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    The hanging is a problem with the http actions. Even downloading a tiny text file takes too long. I use a small dll I created for downloading small files. It is almost instant. Of course it is no good for submitting to a PHP script.
    Dermot

    I am so out of here

  10. #10
    Join Date
    Jan 2007
    Posts
    56
    Quote Originally Posted by Dermot View Post
    I use a small dll I created for downloading small files.
    It is almost instant.
    What is different about the DLL than the code above?

    I mean, what is it that takes so long for the code above, but the code in the
    DLL can be so fast?

    Would it be a good idea to think about creating a DLL for posting/receiving
    data from the Internet, and use it in these instances where a user is sitting
    and waiting on the program?

    I would be willing to look into creating something like this for the community
    if it would help speed things up. (By speed things up, I mean to say help
    speed up our programs, not the creation of this utility. )

    Patrick

  11. #11
    Join Date
    Jul 2004
    Posts
    313
    Thanks Dermot,

    I am wondering if it is possible to place a progress bar on the page which will move untill the function is complete?

    Also, I am not too good with AMS and I cannot get this to work and populate my listBox1 so any help here would be great.

    Thanks

Posting Permissions

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