Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / March 2006

Tip: Looking for answers? Try searching our database.

IF statement doing the impossible?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DGibson - 14 Mar 2006 21:49 GMT
The behavior of my InfoPath form should be impossible, but it's happening.  
There's something that I'm missing that's keeping this from working right.

Background:
There is a Status field in my form that I use to keep track of what step of
a process the form is in.  When the form is first opened, this Status field
is given a default value of "New".  Then as certain steps are taken, the
Status is updated to different values.  Each step of the process has the form
saved to a different Sharepoint document library to await the next step.  The
save portion of the form code works fine, but I need to also delete the form
from the old document library.

In my save function, I do a test of the status field to see if it's a new
form to see if there is an old form to delete.  The code for this is:

XDocument.UI.Alert("oldDocLib: " + oldDocLib);
if (oldDocLib = "New")
{
    XDocument.UI.Alert("New document.  No delete needed.");
}
else
{
    XDocument.UI.Alert("Deleting from " + oldDocLib);
}

When I first open the form and submit it, it displays the alert "oldDocLib:
New" and then I get another alert "New document. No delete needed."  That's
expected and everything is fine there.  
I close Infopath and go to the new document library where the form has been
saved to and open it.  I take the next step and submit it (which uses a
different submit button and function that calls the same above save
function).  This time, I get an alert "oldDocLib: Review" and then the next
alert is "New document. No delete needed."

This is where I'm confused.  The IF statement is based on a variable that
I'm alerting off of just before and the variable is obviously not "New", but
no matter what happens, the IF statement is *always* testing true for some
reason.

Can anyone even take a shot in the dark on this one?
S.Y.M. Wong-A-Ton - 15 Mar 2006 10:06 GMT
Instead of

if (oldDocLib = "New")

try

if (oldDocLib == "New")

Notice the "==" instead of the "="?
---
S.Y.M. Wong-A-Ton

> The behavior of my InfoPath form should be impossible, but it's happening.  
> There's something that I'm missing that's keeping this from working right.
[quoted text clipped - 36 lines]
>
> Can anyone even take a shot in the dark on this one?
DGibson - 15 Mar 2006 18:10 GMT
Yes, that does fix it.  Thank you very much!

Now the hard question, why does it exhibit that behavior?

Does "if (oldDocLib = "New")" reset the value of the variable and then
perform the comparison test?

> Instead of
>
[quoted text clipped - 48 lines]
> >
> > Can anyone even take a shot in the dark on this one?
S.Y.M. Wong-A-Ton - 15 Mar 2006 19:01 GMT
Hard question? :)  

"=" is an assignment operator
"==" is a comparison operator

By using oldDocLib = "New" you gave oldDocLib the value "New" instead of
comparing it to "New", which is why your test failed.
---
S.Y.M. Wong-A-Ton

> Yes, that does fix it.  Thank you very much!
>
[quoted text clipped - 55 lines]
> > >
> > > Can anyone even take a shot in the dark on this one?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.