php - Excel VBA: Dynamic Variable Name -


note: limited php <-> vba. please not suggest requires excel addon, or other language/method.

i have function connect specified url, submits data, , retrieves other data. works great. i'm trying write can use generic function can use connect file need connect - each return different data (one user data, 1 complex calculations etc).

when retrieves data php, there way dynamically set variables based on received - if not know has been received.

i can make php return vba string in format, i'm using below example:

string received in vba:

myvalue1=dave&someothervalue=hockey&hockeydate=yesterday 

if parse in php, similar (not accurate, written example purposes);

$mydata = "myvalue1=dave&someothervalue=hockey&hockeydate=yesterday" $myarr = explode("&",$mydata) foreach($myarr $key => $value){     ${$key} = $value; } echo $someothervalue; //would output screen 'hockey'; 

i similar in vba. string receiving php file, can format way (json etc etc), want able define variables when outputting string php. possible in vba?.

the current state of function have working great connections below:-

function kick_connect(url string, formdata)  'on error goto connecterror dim http set http = createobject("msxml2.xmlhttp") http.open "post", url, false http.setrequestheader "content-type", "application/x-www-form-urlencoded"  http.send (formdata) kick_connect = http.responsetext exit function  connecterror: kick_connect = false  end function 

ultimately, want able like

sub mysub     mydata = "getid=" & range("a1").value     myvalue = kick_connect("http://path-to-my-php-file.php",mydata)     if myvalue = false         'handle connection error here         exit sub     end if      'do snazzy here split "myvalue" string (eg "myvalue1=dave&someothervalue=hockey&hockeydate=yesterday") own variables      msgbox(myvalue1) 'should output "dave"   end sub 

obviously put values array, , reference that, want know if exact thing possible, allow flexibility scripts exist.

i hope makes sense, , grateful replies get.

thank you.

you can use collection:

dim tmp string dim s string dim integer dim colvariabili new collection  tmp = "myvalue1=dave&someothervalue=hockey&hockeydate=yesterday"  dim fieldstr() string dim fieldsplitstr() string fieldstr = split(tmp, "&")  each xx in fieldstr     fieldsplitstr = split(xx, "=")     colvariabili.add fieldsplitstr(1), fieldsplitstr(0) next  debug.print colvariabili("myvalue1") debug.print colvariabili("someothervalue") debug.print colvariabili("hockeydate") 

it's ok if don't have correct sequence of var...


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -