Work :
publicity.Target = IIF(radioTarget1.Checked, "_blank", "_self").toString
Doesn't work :
IIF(radioTarget1.Checked, publicity.Target = "_blank", publicity.Target = "_self")
Why isn't the second option working?
Because it's not assignments you are doing inside the function call, it's comparisons.
It does the same as:
Dim result As Boolean
If radioTarget1.Checked Then
result = (publicity.Target = "_blank")
Else
result = (publicity.Target = "_self")
End If
IIF is a function, not a language feature.
The second two parameters are objects that are potential return values of the function... not a block of code.
http://msdn.microsoft.com/en-us/library/27ydhh0d%28v=VS.90%29.aspx
Related
// but the code is throwing unexpected terminal operator new
function MovePokemon(argument0, argument1) {
old = argument0;
new = argument1;
TPartyID = global.PartyID[old]
global.PartyID[old] = global.PartyID[new]
global.PartyID[new] = TPartyID;
new is a keyword in the current versions of GameMaker, so you'll need to rename that variable (say, to _new).
The project in question may leave some to be desired given the complete absence of local variable declarations (var).
Try use this code in your script to avoid use "new"
function MovePokemon(argument0, argument1) {
TPartyID = global.PartyID[argument0]
global.PartyID[argument0] = global.PartyID[argument1]
global.PartyID[argument1] = TPartyID;
not sure what is happening. i have a recursive function getting data from a table. and it's finds an key to be true and then false twice within it being false..
i am wanting to check the isActive boolean and if it's false return false. if it's true then continue the script.
DUMMY_DATA
local DummyData = {
data = {
['id'] = 34523456,
['question'] = 'whats milk?',
['isActive'] = true,
['questionCountdownTimerInSeconds'] = (60),
}
}
RECURSIVE
function FindQuestionInfo(Object)
local Data = {
['id'] = '',
['question'] = '',
['isActive'] = true or false,
['questionCountdownTimerInSeconds'] = (0),
}
for index, child in pairs(Object) do
local ChildIsTable = type(child) == 'table'
if not ChildIsTable then
local isActive = index == 'isActive'
local isId = index == 'id'
local isQuestion = index == 'question'
local isQuestionCountDDownTImerInSeconds = index == 'questionCountdownTimerInSeconds'
if isQuestion then
Data['question'] = child
end
if isId then
Data['id'] = child
end
end
if ChildIsTable then
local FoundItem = FindQuestionInfo(child)
if FoundItem then
return FoundItem
end
end
end
return Data
end
PRINT
Your code doesn't make too much sense. I'm not even sure what you want to achieve with it.
I'll just mention a few issues:
['isActive'] = true or false
As Nifim already pointed out in his comment true or false equals true. Sou you could simply do
['isActive'] = true
You don't need parenthesis around numbers as in ['questionCountdownTimerInSeconds'] = (0)
You don't mention how you use this code. I assume you call FindQuestionInfo(DummyData)
So let's run your code. First you define Data
local Data = {
['id'] = '',
['question'] = '',
['isActive'] = true or false,
['questionCountdownTimerInSeconds'] = (0),
}
Then you traverse over the table Object with a generic for loop and the pairs iterator. Assuming Object is DummyData this will give us a key value pair of DummyData each cycle.
First you check if child (our value) is a table. I don't see how it can be a table with the provided code. If it is not a table you create various booleans.
local isActive = index == 'isActive'
local isId = index == 'id'
local isQuestion = index == 'question'
local isQuestionCountDDownTImerInSeconds = index == 'questionCountdownTimerInSeconds'
And then you assign values conditionally.
if isQuestion then
Data['question'] = child
end
if isId then
Data['id'] = child
end
So only if index equals one of the keys you assign the same table field from Object to Data.
This whole loop doesn't make sense. If you want to assign values from one table to another you simply assign them. You don't traverse over the entire table until you find the right key to assign.
Aside from your isTable condition which seems to be always false you can replace that for loop by
Data.isQuestion = Object.isQuestion and Object.isQuestion or Data.isQuestion
Data.isId = Object.isId and Object.isId or Data.isId
Because you simply assign those values if they exist in Object.
Then there is this section which I cannot make sense of as I don't see how child will ever be a table:
if ChildIsTable then
local FoundItem = FindQuestionInfo(child)
if FoundItem then
return FoundItem
end
end
Also FindQuestionInfo(child) always returns Data so the condition
if FoundItem then
return FoundItem
end
is not necessary.
So unless your Object will have a table inside that you didn't show in your example I don't see any reason to have this code at all. Especially not the recursive part.
You only copy parts of Object into a new table Data.
I cannot make sense of your problem description either.
I'm assuming you're asking about a xy-problem here. So I suggest you ask a new question about the actual problem you're trying to solve rather than about how to fix this code.
bool Res = false;
DataView DV = new DataView(DT);
DV.RowFilter = "Trim(Originator)='"+OrginatorName.Trim()+"'";
if (DV.Count > 0)
{
Res = true;
}
I need to get "Originator" from the database and compare it with the OrginatorName to check duplicate values. I need to remove all the white spaces before checking.
For example, the function must consider "John Van" to be the same as "JohnVan". My above code doesn't work. How can I achieve this?
String.Trim() removes whitespace from the beginning and end only, not in the middle. You want to use the String.Replace() method
DV.RowFilter = "Trim(Originator)='"+OrginatorName.Replace(" ", "")+"'";
this line should be
DV.RowFilter = "Trim(Originator)='"+OrginatorName.Replace(" ","")+"'";
User .Replace instead of .Trim()
List<business.clspluginsprp> objprp = new List<business.clspluginsprp>();
business.clsplugins obj = new business.clsplugins();
for (Int32 i = 0; i < k.Length; i++)
{
Int32 z = Convert.ToInt32(k.GetValue(i));
objprp.Add(obj.fnd_plugins(z));
}
GridView2.DataSource = objprp;
GridView2.DataBind();
An error arrived which is as: The best overloaded method match for 'System.Collections.Generic.List.Add(business.clspluginsprp)' has some invalid arguments while the other error is : Argument 1: cannot convert from 'System.Collections.Generic.List' to 'business.clspluginsprp'
Try changing this:
objprp.Add(obj.fnd_plugins(z));
to this:
objprp.AddRange(obj.fnd_plugins(z));
Since it seems fnd_plugins returns a list in and of itself. This will also error if fnd_plugins does not return a List generic implementation. Posting the signature of fnd_plugins will help debug this.
Thanks.
Assuming fnd_plugins returns a List of clsplugins objects, then you want to use AddRange instead of Add. AddRange lets you add multiple values in one call.
How do I modify the query below to properly handle the case where the "Summary" element is missing from one of the articles? Now when that happens I get an "Object reference not set to an instance of an object."
var articles = from article in xmlDoc.Descendants("Article")
select new {
articleId = article.Attribute("ID").Value,
heading = article.Element("Heading").Value,
summary = article.Element("Summary").Value,
contents = article.Element("Contents").Value,
cats = from cat in article.Elements("Categories")
select new {
category = cat.Element("Category").Value
}
};
The problem is that article.Element("Summary") returns null if the element is not found, so you get a NullReferenceException when you try to get the Value property.
To solve this, note that XElement also has an explicit conversion to string. This won't throw if the XElement is null - you will just get a null string reference.
So to solve your problem you can change this:
summary = article.Element("Summary").Value,
to this:
summary = (string)article.Element("Summary")