Search Results

Search found 13794 results on 552 pages for 'variable scope'.

Page 42/552 | < Previous Page | 38 39 40 41 42 43 44 45 46 47 48 49  | Next Page >

  • Passing a variable from Excel 2007 Custom Task Pane to Hosted PowerShell

    - by Uros Calakovic
    I am testing PowerShell hosting using C#. Here is a console application that works: using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Management.Automation; using System.Management.Automation.Runspaces; using Microsoft.Office.Interop.Excel; namespace ConsoleApplication3 { class Program { static void Main() { Application app = new Application(); app.Visible = true; app.Workbooks.Add(XlWBATemplate.xlWBATWorksheet); Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); runspace.SessionStateProxy.SetVariable("Application", app); Pipeline pipeline = runspace.CreatePipeline("$Application"); Collection<PSObject> results = null; try { results = pipeline.Invoke(); foreach (PSObject pob in results) { Console.WriteLine(pob); } } catch (RuntimeException re) { Console.WriteLine(re.GetType().Name); Console.WriteLine(re.Message); } } } } I first create an Excel.Application instance and pass it to the hosted PowerShell instance as a varible named $Application. This works and I can use this variable as if Excel.Application was created from within PowerShell. I next created an Excel addin using VS 2008 and added a user control with two text boxes and a button to the addin (the user control appears as a custom task pane when Excel starts). The idea was this: when I click the button a hosted PowerShell instance is created and I can pass to it the current Excel.Application instance as a variable, just like in the first sample, so I can use this variable to automate Excel from PowerShell (one text box would be used for input and the other one for output. Here is the code: using System; using System.Windows.Forms; using System.Management.Automation; using System.Management.Automation.Runspaces; using System.Collections.ObjectModel; using Microsoft.Office.Interop.Excel; namespace POSHAddin { public partial class POSHControl : UserControl { public POSHControl() { InitializeComponent(); } private void btnRun_Click(object sender, EventArgs e) { txtOutput.Clear(); Microsoft.Office.Interop.Excel.Application app = Globals.ThisAddIn.Application; Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); runspace.SessionStateProxy.SetVariable("Application", app); Pipeline pipeline = runspace.CreatePipeline( "$Application | Get-Member | Out-String"); app.ActiveCell.Value2 = "Test"; Collection<PSObject> results = null; try { results = pipeline.Invoke(); foreach (PSObject pob in results) { txtOutput.Text += pob.ToString() + "-"; } } catch (RuntimeException re) { txtOutput.Text += re.GetType().Name; txtOutput.Text += re.Message; } } } } The code is similar to the first sample, except that the current Excel.Application instance is available to the addin via Globals.ThisAddIn.Application (VSTO generated) and I can see that it is really a Microsoft.Office.Interop.Excel.Application instance because I can use things like app.ActiveCell.Value2 = "Test" (this actually puts the text into the active cell). But when I pass the Excel.Application instance to the PowerShell instance what gets there is an instance of System.__ComObject and I can't figure out how to cast it to Excel.Application. When I examine the variable from PowerShell using $Application | Get-Member this is the output I get in the second text box: TypeName: System.__ComObject Name MemberType Definition ---- ---------- ---------- CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObj... Equals Method System.Boolean Equals(Object obj) GetHashCode Method System.Int32 GetHashCode() GetLifetimeService Method System.Object GetLifetimeService() GetType Method System.Type GetType() InitializeLifetimeService Method System.Object InitializeLifetimeService() ToString Method System.String ToString() My question is how can I pass an instance of Microsoft.Office.Interop.Excel.Application from a VSTO generated Excel 2007 addin to a hosted PowerShell instance, so I can manipulate it from PowerShell? (I have previously posted the question in the Microsoft C# forum without an answer)

    Read the article

  • What is the most idiomatic way to emulating Perl's Test::More::done_testing?

    - by DVK
    I have to build unit tests for in environment with a very old version of Test::More (perl5.8 with $Test::More::VERSION being '0.80') which predates the addition of done_testing(). Upgrading to newer Test::More is out of the question for practical reasons. And I am trying to avoid using no_tests - it's generally a bad idea not catching when your unit test exits prematurely - say due to some logic not executing when you expected it to. What is the most idiomatic way of running a configurable amount of tests, assuming no no_tests or done_testing() is used? Details: My unit tests usually take the form of: use Test::More; my @test_set = ( [ "Test #1", $param1, $param2, ... ] ,[ "Test #1", $param1, $param2, ... ] # ,... ); foreach my $test (@test_set) { run_test($test); } sub run_test { # $expected_tests += count_tests($test); ok(test1($test)) || diag("Test1 failed"); # ... } The standard approach of use Test::More tests => 23; or BEGIN {plan tests => 23} does not work since both are obviously executed before @tests is known. My current approach involves making @tests global and defining it in the BEGIN {} block as follows: use Test::More; BEGIN { our @test_set = (); # Same set of tests as above my $expected_tests = 0; foreach my $test (@tests) { my $expected_tests += count_tests($test); } plan tests = $expected_tests; } our @test_set; # Must do!!! Since first "our" was in BEGIN's scope :( foreach my $test (@test_set) { run_test($test); } # Same sub run_test {} # Same I feel this can be done more idiomatically but not certain how to improve. Chief among the smells is the duplicate our @test_test declarations - in BEGIN{} and after it. Another approach is to emulate done_testing() by calling Test::More->builder->plan(tests=>$total_tests_calculated). I'm not sure if it's any better idiomatically-wise.

    Read the article

  • refactoring this function in Java

    - by Joel
    Hi folks, I'm learning Java, and I know one of the big complaints about newbie programmers is that we make really long and involved methods that should be broken into several. Well here is one I wrote and is a perfect example. :-D. public void buildBall(){ /* sets the x and y value for the center of the canvas */ double i = ((getWidth() / 2)); double j = ((getHeight() / 2)); /* randomizes the start speed of the ball */ vy = 3.0; vx = rgen.nextDouble(1.0, 3.0); if (rgen.nextBoolean(.05)) vx = -vx; /* creates the ball */ GOval ball = new GOval(i,j,(2 *BALL_RADIUS),(2 * BALL_RADIUS)); ball.setFilled(true); ball.setFillColor(Color.RED); add(ball); /* animates the ball */ while(true){ i = (i + (vx* 2)); j = (j + (vy* 2)); if (i > APPLICATION_WIDTH-(2 * BALL_RADIUS)){ vx = -vx; } if (j > APPLICATION_HEIGHT-(2 * BALL_RADIUS)){ vy = -vy; } if (i < 0){ vx = -vx; } if (j < 0){ vy = -vy; } ball.move(vx + vx, vy + vy); pause(10); /* checks the edges of the ball to see if it hits an object */ colider = getElementAt(i, j); if (colider == null){ colider = getElementAt(i + (2*BALL_RADIUS), j); } if (colider == null){ colider = getElementAt(i + (2*BALL_RADIUS), j + (2*BALL_RADIUS)); } if (colider == null){ colider = getElementAt(i, j + (2*BALL_RADIUS)); } /* If the ball hits an object it reverses direction */ if (colider != null){ vy = -vy; /* removes bricks when hit but not the paddle */ if (j < (getHeight() -(PADDLE_Y_OFFSET + PADDLE_HEIGHT))){ remove(colider); } } } You can see from the title of the method that I started with good intentions of "building the ball". There are a few issues I ran up against: The problem is that then I needed to move the ball, so I created that while loop. I don't see any other way to do that other than just keep it "true", so that means any other code I create below this loop won't happen. I didn't make the while loop a different function because I was using those variables i and j. So I don't see how I can refactor beyond this loop. So my main question is: How would I pass the values of i and j to a new method: "animateBall" and how would I use ball.move(vx + vx, vy + vy); in that new method if ball has been declared in the buildBall method? I understand this is probably a simple thing of better understanding variable scope and passing arguments, but I'm not quite there yet...

    Read the article

  • Global and local variables in my script

    - by Acorn
    I'm starting out learning javascript, and tried to write a little script that would make a grid of divs on a page. Here's the script: var tileWidth=50; var tileHeight=100; var leftPos=10; var topPos=10; var columns=10; var rows=10; var spacing=5; $('document').ready(function() { placeTiles(); }); function makeRow() { for (var i=0; i<columns; i++) { $('#canvas').append('<div class="tile" style="left:' + leftPos + 'px;top:' + topPos + 'px;"></div>'); var leftPos = leftPos + tileWidth + spacing; } } function placeTiles() { for (var i=0; i<rows; i++) { makeRow(); var topPos = topPos + tileHeight + spacing; } } At the moment, 100 <div>s get created, all with a top position of 10px and a left position of undefined (for the first <div> in the row) or NaN. What should I be doing differently? Why can't makerow() see my global leftPos variable (and all the other variables for that matter)? Thanks.

    Read the article

  • Why does my simple event handling example not work?

    - by njreed
    I am trying to make a simple event handler. (Note, I'm not trying to implement a full-blown publish/subscribe model; I'm just interested in why my example doesn't work as I think it should) var myObj = (function () { var private = "X"; function triggerEvent(eventName) { if (this[eventName]) { this[eventName](); } } // Setter / Getter function getProp() { return private; } function setProp(value) { private = value; triggerEvent("onPropChange"); } // Public API return { // Events "onPropChange": null, // Fires when prop value is changed // Methods "getProp": getProp, "setProp": setProp }; })(); // Now set event handler myObj.onPropChange = function () { alert("You changed the property!"); }; myObj.setProp("Z"); // --> Nothing happens. Wrong // Why doesn't my alert show? I set the onPropChange property of my object to a simpler handler function but it is not being fired. I have debugged this and it seems that in triggerEvent the variable this is referencing the global window object. I thought it should reference myObj (which is what I need). Can someone explain the error in my thinking and how I correct this? Help much appreciated. jsFiddle here

    Read the article

  • globals and locals in python exec()

    - by hawkettc
    Hi, I'm trying to run a piece of python code using exec. my_code = """ class A(object): pass print 'locals: %s' % locals() print 'A: %s' % A class B(object): a_ref = A """ global_env = {} local_env = {} my_code_AST = compile(my_code, "My Code", "exec") exec(my_code_AST, global_env, local_env) print local_env which results in the following output locals: {'A': <class 'A'>} A: <class 'A'> Traceback (most recent call last): File "python_test.py", line 16, in <module> exec(my_code_AST, global_env, local_env) File "My Code", line 8, in <module> File "My Code", line 9, in B NameError: name 'A' is not defined However, if I change the code to this - my_code = """ class A(object): pass print 'locals: %s' % locals() print 'A: %s' % A class B(A): pass """ global_env = {} local_env = {} my_code_AST = compile(my_code, "My Code", "exec") exec(my_code_AST, global_env, local_env) print local_env then it works fine - giving the following output - locals: {'A': <class 'A'>} A: <class 'A'> {'A': <class 'A'>, 'B': <class 'B'>} Clearly A is present and accessible - what's going wrong in the first piece of code? I'm using 2.6.5, cheers, Colin * UPDATE 1 * If I check the locals() inside the class - my_code = """ class A(object): pass print 'locals: %s' % locals() print 'A: %s' % A class B(object): print locals() a_ref = A """ global_env = {} local_env = {} my_code_AST = compile(my_code, "My Code", "exec") exec(my_code_AST, global_env, local_env) print local_env Then it becomes clear that locals() is not the same in both places - locals: {'A': <class 'A'>} A: <class 'A'> {'__module__': '__builtin__'} Traceback (most recent call last): File "python_test.py", line 16, in <module> exec(my_code_AST, global_env, local_env) File "My Code", line 8, in <module> File "My Code", line 10, in B NameError: name 'A' is not defined However, if I do this, there is no problem - def f(): class A(object): pass class B(object): a_ref = A f() print 'Finished OK' * UPDATE 2 * ok, so the docs here - http://docs.python.org/reference/executionmodel.html 'A class definition is an executable statement that may use and define names. These references follow the normal rules for name resolution. The namespace of the class definition becomes the attribute dictionary of the class. Names defined at the class scope are not visible in methods.' It seems to me that 'A' should be made available as a free variable within the executable statement that is the definition of B, and this happens when we call f(), but not when we use exec(). This can be more easily shown with the following - my_code = """ class A(object): pass print 'locals in body: %s' % locals() print 'A: %s' % A def f(): print 'A in f: %s' % A f() class B(object): a_ref = A """ which outputs locals in body: {'A': <class 'A'>} A: <class 'A'> Traceback (most recent call last): File "python_test.py", line 20, in <module> exec(my_code_AST, global_env, local_env) File "My Code", line 11, in <module> File "My Code", line 9, in f NameError: global name 'A' is not defined So I guess the new question is - why aren't those locals being exposed as free variables in functions and class definitions - it seems like a pretty standard closure scenario.

    Read the article

  • Changes to data inside class not being shown when accessed from outside class.

    - by Hypatia
    I have two classes, Car and Person. Car has as one of its members an instance of Person, driver. I want to move a car, while keeping track of its location, and also move the driver inside the car and get its location. However, while this works from inside the class (I have printed out the values as they are calculated), when I try to access the data from main, there's nothing there. I.e. the array position[] ends up empty. I am wondering if there is something wrong with the way I have set up the classes -- could it be a problem of the scope of the object? I have tried simplifying the code so that I only give what is necessary. Hopefully that covers everything that you would need to see. The constructer Car() fills the offset array of driver with nonzero values. class Car{ public: Container(float=0,float=0,float=0); ~Container(); void move(float); void getPosition(float[]); void getDriverPosition(float[]); private: float position[3]; Person driver; float heading; float velocity; }; class Person{ public: Person(float=0,float=0,float=0); ~Person(); void setOffset(float=0,float=0,float=0); void setPosition(float=0,float=0,float=0); void getOffset(float[]); void getPosition(float[]); private: float position[3]; float offset[3]; }; Some of the functions: void Car::move(float time){ float distance = velocity*time; location[0] += distance*cos(PI/2 - heading); location[1] += distance*sin(PI/2 - heading); float driverLocation [3]; float offset[3]; driver->getOffset(offset); for (int i = 0; i < 3; i++){ driverLocation[i] = offset[i] + location[i]; } } void Car::getDriverPosition(float p[]){ driver.getPosition(p); } void Person::getPosition(float p[]){ for (int i = 0; i < 3; i++){ p[i] = position[i]; } } void Person::getOffset(float o[]){ for (int i = 0; i < 3; i++){ o[i] = offset[i]; } } In Main: Car * car = new Car(); car->move(); float p[3]; car->getDriverPosition(p); When I print driverLocation[] inside the move() function, I have actual nonzero values. When I print p[] inside main, all I get are zeros.

    Read the article

  • The Use-Case Driven Approach to Change Management

    - by Lauren Clark
    In the third entry of the series on OUM and PMI’s Pulse of the Profession, we took a look at the continued importance of change management and risk management. The topic of change management and OUM’s use-case driven approach has come up in few recent conversations. So I thought I would jot down a few thoughts on how the use-case driven approach aids a project team in managing the project’s scope. The use-case model is one of several tools in OUM that is used to establish and manage the project's scope.  Because a use-case model can be understood by both business and IT project team members, it can serve as a bridge for ongoing collaboration as well as a visual diagram that encapsulates all agreed-upon functionality. This makes it a vital artifact in identifying changes to the project’s scope. Here are some of the primary benefits of using the use-case model as part of the effort for establishing and managing project scope: The use-case model quickly communicates scope in a straightforward manner. All project stakeholders can have a common foundation for the decisions regarding architecture and design and how they relate to the project's objectives. Once agreed upon, the model can be put under change control and any updates to the model can then be quickly identified as potentially affecting the project’s scope.  Changes requested or discovered later in the project can be analyzed objectively for their impact on project's budget, resources and schedule. A modular foundation for the design of the software solution can be established in Elaboration.  This permits work to be divided up effectively and executed in so that the most important and riskiest use-cases can be tackled early in the project. The use-case model helps the team make informed decisions about implementation priorities, which allows effective allocation of limited project resources.  This is very helpful in not only managing scope, but in doing iterative and incremental planning which relies heavily on the ability to identify project priorities. Bottom line is that the use-case model gives the project team solid understanding of scope early in the project.  Combine this understanding with effective project management and communication and you have an effective tool for reducing the risk of overruns in budget and/or time due to out of control scope changes. Now that you’ve had a chance to read these thoughts on the use-case model and project scope, please let me know your feedback based on your experience.

    Read the article

  • Why can't Java/C# implement RAII?

    - by mike30
    Question: Why can't Java/C# implement RAII? Clarification: I am aware the garbage collector is not deterministic. So with the current language features it is not possible for an object's Dispose() method to be called automatically on scope exit. But could such a deterministic feature be added? My understanding: I feel an implementation of RAII must satisfy two requirements: 1. The lifetime of a resource must be bound to a scope. 2. Implicit. The freeing of the resource must happen without an explicit statement by the programmer. Analogous to a garbage collector freeing memory without an explicit statement. The "implicitness" only needs to occur at point of use of the class. The class library creator must of course explicitly implement a destructor or Dispose() method. Java/C# satisfy point 1. In C# a resource implementing IDisposable can be bound to a "using" scope: void test() { using(Resource r = new Resource()) { r.foo(); }//resource released on scope exit } This does not satisfy point 2. The programmer must explicitly tie the object to a special "using" scope. Programmers can (and do) forget to explicitly tie the resource to a scope, creating a leak. In fact the "using" blocks are converted to try-finally-dispose() code by the compiler. It has the same explicit nature of the try-finally-dispose() pattern. Without an implicit release, the hook to a scope is syntactic sugar. void test() { //Programmer forgot (or was not aware of the need) to explicitly //bind Resource to a scope. Resource r = new Resource(); r.foo(); }//resource leaked!!! I think it is worth creating a language feature in Java/C# allowing special objects that are hooked to the stack via a smart-pointer. The feature would allow you to flag a class as scope-bound, so that it always is created with a hook to the stack. There could be a options for different for different types of smart pointers. class Resource - ScopeBound { /* class details */ void Dispose() { //free resource } } void test() { //class Resource was flagged as ScopeBound so the tie to the stack is implicit. Resource r = new Resource(); //r is a smart-pointer r.foo(); }//resource released on scope exit. I think implicitness is "worth it". Just as the implicitness of garbage collection is "worth it". Explicit using blocks are refreshing on the eyes, but offer no semantic advantage over try-finally-dispose(). Is it impractical to implement such a feature into the Java/C# languages? Could it be introduced without breaking old code?

    Read the article

  • Pass variable to regular expression pattern string in jquery

    - by phil
    Is that possible to pass variable into regular expression pattern string in jquery ( or javascript)? For example, I want to validate a zip code input field every time while user type in a character by passing variable i to the regular expression pattern. How to do it right? $('#zip').keyup( function(){ var i=$('#zip').val().length for ( i; i<=5; i++){ var pattern=/^[0-9]{i}$/; if ( !pattern.test( $('#zip').val() ) ) {$('#zip_error').css('display','inline');} else {$('#zip_error').css('display','none');} } })

    Read the article

  • How to convert a Mat variable type in an IplImage variable type in OpenCV 2.0 ?

    - by user290613
    Hi all, I am trying to rotate an image in OpenCV. I've used this code that I found here on StackOverflow Mat source(img); Point2f src_center(source.cols/2.0, source.rows/2.0); Mat rot_mat = getRotationMatrix2D(src_center, 40.0, 1.0); Mat dst; warpAffine(source, dst, rot_mat, source.size()); Once I have my dst Mat variable type filled up I would like to put it back to an IplImage variable type, any idea about how to do this ? Thank you,

    Read the article

  • ASP.NET MVC: ensure user always has a session variable set

    - by pcampbell
    Consider an ASP.NET MVC application that requires a session variable be set. It's used throughout the app. It'll be set by either reading a hashed value on the browser cookie, or after having the user login. In the WebForms + Master Page model, I'd check the Page_Load() of the master page. Perhaps not the ultimate event, but it was an easy one to find. How would you check and enforce the existance of a session variable in ASP.NET MVC? Consider that this question might not involve user login details, but some other piece of data (first visit time, perhaps).

    Read the article

  • ASP Classic Session Variable Not Always Getting Set

    - by Mike at KBS
    I have a classic ASP site I'm maintaining and recently we wanted to do special rendering actions if the visitor was coming from one specific set of websites. So in the page where those visitors have to come through to get to our site, I put a simple line setting a session variable: <!-- #include virtual="/clsdbAccess.cs"--> <% set db = new dbAccess %> <html> <head> ... <script language="javascript" type="text/javascript"> ... </script> </head> <body> <% Session("CAME_FROM_NEWSPAPER") = "your local newspaper" ... %> ... html stuff ... </body> </html> Then, in all the following pages, whenever I need to put up nav links, menus, etc., that we don't want to show to those visitors, I test for if that session variable is "" or not, then render accordingly. My problem is that it seems to work great for me in development, then I get it out into Production and it works great sometimes, and other times it doesn't work at all. Sometimes the session variable gets set, sometimes it doesn't. Everything else works great. But our client is seeing inconsistent results on pages rendered to their visitors and this is a problem. I've tried logging on from different PC's and I confirm that I get different, and unpredictable, results. The problem is I can't reproduce it at will, and I can't troubleshoot/trace Production. For now I've solved this by just creating duplicate pages with the special rendering, and making sure those visitors go there. But this is a hack and will eventually be difficult to maintain. Is there something special or inconsistent about session variables in Classic ASP? Is there a better way to approach the problem? TIA.

    Read the article

  • Add a Session Variable or Custom field to the Elmah Error Log table

    - by VJ
    I want to add my own session variable to elmah error log table and display it. I already have modified the source code and added the new fields to Error.cs and other fields but I don't know but when I assign an HttpContext.Current.Session["MyVar"].tostring() value to my field in the constructor it stops logging exceptions and does not log any exception. I just need to get the value of the session variable is there other way for this. I read a post which he added fields for the email but it does not say where exactly should I get the session value.

    Read the article

  • Passing variable to Google Charts URL

    - by Rob A
    Hi All, This is probably something really simple, however I am quite new to PHP, and havent done any HTML in years. I need to get a PHP variable filled with an array of figures into Google Charts. My code for this so far is: <img src="http://chart.apis.google.com/chart? &chs=340x175 &chd=t:<?=$filedetail[1]?> &cht=lc &chtt=Test "> However, Google reports an error, as it stops at the ?=$filedetail[1] for some reason. It doesnt seem that reading the variable is the problem, more that the API simply cant read past the start of the PHP tags. Thanks, Rob A.

    Read the article

  • Undefined variable from import when using wxPython in pydev

    - by Bibendum
    I just downloaded wxPython, and was running some of the sample programs from here. However, on every line that uses a variable from wx.*, I get a "Undefined variable from import error" For example, the following program generates five errors on lines 1,4,8, and two on line 5: import wx class MyFrame(wx.Frame): """ We simply derive a new class of Frame. """ def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title, size=(200,100)) self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) self.Show(True) app = wx.App(False) frame = MyFrame(None, 'Small editor') app.MainLoop() The program, however, compiles and runs perfectly. I haven't made any significant modifications to pydev or eclipse, and the wxPython install is fresh.

    Read the article

  • How do you hide/show UISearchBar's scope bar with animation?

    - by zekel
    I want to show no scope bar when the table is empty (before the search bar edits for the first time), no scope bar when it's editing, and finally show it when editing done. I know about the UISearchBarDelegate protocol, but I don't know how to show/hide the scope bar with animation. I know UISearchBar has setShowsScopeBar:, but no setShowsScopeBar:animated: the way it does for setShowsCancelButton:animated.

    Read the article

  • retrieve cobol s9(2) COMP onto C variable

    - by Pablo Cazallas
    Hi, I need to retrieve data from a COBOL variable of the type: "PIC S9(2) COMP" onto a C variable of the type "int". It's stored using two bytes of a string, so I receive it as a couple of chars. I know COBOL stores decimal data onto a "S9(2) COMP" in binary format, so It would be a great help letting me know any algorithm or way to convert it safely. Any kind of help & suggestion will be welcome. Thanks in advance and regards, Pablo.

    Read the article

  • Isset and PHP Global Variable

    - by justjoe
    i have doubt on this particular problem : Global variabe initiation. i got this code and has global variable named conditional_random here : function hello_testing() { global $conditional_random; if (isset($conditional_random)) { echo "foo is inside"; } } As it's name, the global variable (conditional_random) can be or not initiate before the hello_testing function been called. So, what happen to my validation via isset() when $conditional_random is not initiate before the hello_testing function ? will it failed to check or it will always be true cause by the 'global' ?

    Read the article

  • Environment variable does not get read?

    - by sanjeev40084
    I have a console application in Visual studio. i have log4net stuff with smtp appender in my app.config file. I have set environment variable in my code (i.e. my email address) and trying to reference this environment variable to send email. However log4net doesn't seem to read this value when the application is run. My log4net: <?xml version="1.0" encoding="utf-8" ?> <Configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net> <appender name="smtp" type="log4net.Appender.SmtpAppender"> <param name="to" value="${EmailAddress}" /> <param name="from" value="[email protected]" /> <param name="subject" value="testing app" /> <param name="smtpHost" value="<smtp host name>" /> <param name="bufferSize" value="1" /> <param name="lossy" value="false" /> <param name="Threshold" value="ERROR"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%d{ISO8601} [%t] [%-5p] %c - %m%n" /> </layout> </appender> <!-- Setup the root category, add the appenders and set the default priority --> <root> <priority value="ALL" /> <appender-ref ref="smtp" /> </root> </log4net> </Configuration> In my console app, i have set environment variable something like this: Environment.SetEnvironmentVariable("EmailAddress", "[email protected]", EnvironmentVariableTarget.Process); Does anyone know how can i make it work? Thanks.

    Read the article

  • using a php variable in the WHERE clause of a mysql query

    - by user1262890
    I'm running a very simple query that I think should work. The only thing that I haven't done before is put a php variable in the WHERE clause of the query. The variable $X is a numerical value, say 100. When I run this query, I just get a value of 0 returned. Am I doing something obviously stupid? SELECT generator_64k.n FROM generator_64k WHERE generator_64k.n<= '$X' I've looked around the web and also tried this: SELECT generator_64k.n FROM generator_64k WHERE generator_64k.n<= '" . $X . "' But this also just returns 0. Any ideas? Thanks in advance.

    Read the article

  • Updating / refreshing a live geojson layer | JSON & JS Variable

    - by Ozaki
    TLDR I am trying to get my geoJSON layer to update, currently it will 1. Create the vector mark, 2. Remove the vector mark, 3. Set the JS variable for lat and lon, 4. Unset the variable??? :S Hey S O. I have a geojson layer set up as follows: //GeoJSON Layer// var layer1 = new OpenLayers.Layer.GML("My GeoJSON Layer", "coordinates", {format: OpenLayers.Format.GeoJSON, styleMap: style_red}); My features are set up as follows: var latitude = 0.0; // as 0.0 it will draw the point in. var longitude = 0.0; // as 0.0 it will draw the point in. //var longitude = getlongitude; where getlongitude = JSON string of longitude. var point = new OpenLayers.Geometry.Point(longitude, latitude); pointFeature = new OpenLayers.Feature.Vector(point, null, style_red); var style_red = OpenLayers.Util.extend({}, layer_style); style_red.strokeColor = "red"; style_red.fillColor = "black"; style_red.fillOpacity = 0.5; style_red.graphicName = "circle"; style_red.pointRadius = 3.8; style_red.strokeWidth = 2; style_red.strokeLinecap = "butt"; and my layer updating function: function UpdateLayer(){ var p = new OpenLayers.Format.GeoJSON({ 'internalProjection': new OpenLayers.Projection("EPSG:900913"), 'externalProjection': new OpenLayers.Projection("EPSG:4326") }); var url = "coordinates"; OpenLayers.loadURL(url, {}, null, function(r) { var f = p.read(r.responseText); map.layers[2].destroyFeatures(); map.layers[2].addFeatures(pointFeature); }); setTimeout("UpdateLayer()",1000) } Any idea what I am doing wrong or what I am missing? Edit1 It now removes the feature (was map.layers[1]) previously... But will not add the new feature.. Edit2 I managed to get it to redraw a point but not with live data. It should draw the point at what (latitude) & (longitude) are equal to. I am trying to set latitude & longitude to some JSON string but every time straight after it sets the variable it changes it back to "undefined" as soon as it passes the line after var latitude? (using firebug & firequery to debug)

    Read the article

  • jQuery .Ajax() function selector , store specific data in variable

    - by user279321
    I am new to jQuery and I have the following problem. My project has say 2 pages, 1.JSP and 2.html. Now I want to pick selected data from 2.html and use it on 1.JSP. Now this was achieved very easily using .load but I want the data to be present in a JavaScript variable rather than put it on the page (div tags, etc.), so that I can work upon that data (modify or add to database). I tried using .ajax and was able to write the following code: var value = (function () { var val = nulll; var filename = " 2.html"; $.ajax ({ 'async': false, 'global': false, 'url': filename, 'success' : function(data) { val = data; } }) return val; })() document.write(value) Where do I put the selector format (say div.id5) so that my variable have only relevant data rather than the full file data?

    Read the article

  • jQuery global variable best practice & options?

    - by Kris Krause
    Currently I am working on a legacy web page that uses a ton of javascript, jquery, microsoft client javascript, and other libraries. The bottom line - I cannot rewrite the entire page from scratch as the business cannot justify it. So... it is what it is. Anyway, I need to pollute (I really tried not too) the global namespace with a variable. There are the three options I was thinking - Just store/retrieve it using a normal javascript declaration - var x = 0; Utilize jQuery to store/retrieve the value in a DOM tag - $("body").data("x", 0); Utilize a hidden form field, and set/retrieve the value with jQuery - $("whatever").data("x", 0); What does everyone think? Is there a better way? I looked at the existing pile of code and I do not believe the variable can be scoped in a function.

    Read the article

< Previous Page | 38 39 40 41 42 43 44 45 46 47 48 49  | Next Page >