I've got a SQL Server function that returns a scalar BIT value and takes one parameter. The following gives you an idea:
CREATE FUNCTION dbo.[fnTest] (#StringToTest VARCHAR(10))
RETURNS BIT
AS
BEGIN
DECLARE #b BIT
IF #StringToTest = 'A' SET #b = 0 ELSE SET #b = 1
RETURN (#b)
END
GO
Being very new (days!) to SubSonic - how would I call this using SubSonic?
(I'm using a web site with the basic "subsonic.abp" file with an asterisk in it).
Got it!
Here's how in VB:
Return New SubSonic.InlineQuery().ExecuteScalar(Of Boolean)("SELECT dbo.[fnTest](#StringToTest)", StringToTest)
Thanks all, hope this helps someone else,
Thomas
Related
I'm looking for some guidance or tips for how to revise the function below. My goal is create a function that accepts one parameter and then returns a string. In this case the string will be a name of a super hero. The catch is that the function must output the full name concatenated together (ex. $FullName = $FName + "" +$LName). Can anyone give me some guidance on how I can accomplish this?
So far a have functional function that accepts one parameter but the output is the full name as one singular string. I am unable to find away to concatenate a first and last name and use it as my single parameter for this function. The commented out section of the function is just some trial and error code that I have attempted so far. Any help is appreciated!
The strings I'm working with:
Bat Man,
Wonder Woman,
Aqua Man
function Get-DCHero {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)][ValidateSet('Batman','Superman','Aquaman','Wonder Woman',ErrorMessage = "'{0}' is not a DC Super Hero. Please trying one of the following: '{1}'")]
[string]$Name
<#
[Parameter(Mandatory=$true)][ValidateSet('Batman','Superman','Aquaman','Wonder Woman',ErrorMessage = "'{0}' is not a DC Super Hero. Please trying one of the following: '{1}'")]
[string]$FullName = $FName + "" +$LName
[ValidateSet('Bat','Super','Aqua','Wonder','Flash',ErrorMessage = "'{0}' is not a DC Super Hero. Please trying one of the following: '{1}'")]
[string]$FName
[ValidateSet('Man','Man','Man','Woman','Flash',ErrorMessage = "'{0}' is not a DC Super Hero. Please trying one of the following: '{1}'")]
[string]$LName
#>
)
Write-OutPut "$Name is a DC Super hero."
}
I am trying to input a Double value into a Shape.SetFormula command
for example the following is something which I recorded via the journaling function of NX:
moveObjectBuilder1.TransformMotion.Angle.SetFormula("12.5")
According to the microsoft website, the value inside the () can only be an Integer, and obviously, any value (no matter Integer or Double value) written in this form "xxx" can be executed.
As far as I understood, "" is a String, so I changed the code like the following :
Function value() As String
Return 25/2
End Function
Sub Main(ByVal As String)
.
.
.
moveObjectBuilder1.TransformMotion.Angle.SetFormula(value())
.
.
.
End Sub
However, there will be a syntax error if the code is written like this.
May I ask, how can I let the Shape.Formula() command read a Double value? Or how can I let the Function return a value which will be in this format "..."?
Thank you very much!
I have no experience with that application but, as far as I can tell, the parameter for that method is type String because it accepts a String containing a mathematical formula that will be parsed internally. In that case, something like this should work:
moveObjectBuilder1.TransformMotion.Angle.SetFormula("25 / 2")
and do exactly the same thing as this:
moveObjectBuilder1.TransformMotion.Angle.SetFormula("12.5")
If that's not working for you then please explain EXACTLY what happens when you do it.
I've managed to solve my own problem. It was actually quite stupid, I am just simply not an expert in programming. It only took me several more tries to get the solution to my problem.
moveObjectBuilder1.TransformMotion.Angle.SetFormula("Sqrt(2)")
This is the correct way to express "Rotate this object with the angle of square root of 2."
Okay now let's talk about the problem which I've encountered. What I want is, import a value via a function, and then process it. So, SetFormula only accepts String. Therefore I can do the following :
Function value() As Double
Return 25/2
End Function
Sub Main(ByVal arg() As String)
.
.
.
moveObjectBuilder1.TransformMotion.Angle.SetFormula(value().ToString)
.
.
.
End Sub
I was trying to convert a match object to a string in perl6. The method Str on a match object is defined as:
method Str(Match:D: --> Str:D)
I would think I could use Str($match) to accomplish this. And it seems to convert it to a string, but I'm getting an error using the string with the following code:
my $searchme = "rudolph";
my $match = $searchme ~~ /.*dol.*/;
say $match.WHAT;
my $test1 = Str($match);
say $test1.WHAT;
say $test1;
With the output:
(Match)
(Str)
With the error:
Cannot find method 'gist': no method cache and no .^find_method in
block at .code.tio line 6
However, if I run:
my $searchme = "rudolph";
my $match = $searchme ~~ /.*dol.*/;
say $match.WHAT;
my $test1 = $match.Str;
say $test1.WHAT;
say $test1;
I get no error and the result:
(Match)
(Str)
rudolph
Is this a bug or me misunderstanding how it works?
Thanks for reading.
I'm writing this up as an answer even though it's actually an incomplete discussion of a bug, so not at all normal SO fare. The alternative of lots of comments doesn't seem better.
It's a bug. Perhaps you just golfed this.
dd $test1; instead of say $test1; is helpful in that it displays BOOTStr $test1 = (BOOTStr without .perl method).
Based on that I searched the rakudo repo for BOOTStr and that led to the above issue.
Golfing it further leads to:
say $ = Str(Match.new);
Note that these are all fine:
say Str(Match.new);
say $ = Int(Match.new);
say $ = Str(Date.new: '2015-12-31');
It appears to be a combination of leaking some implementation details regarding how Rakudo/NQP/MoarVM bootstrap; Match being an NQP object; Str() on that being wonky; and assigning it to a Scalar container (the $ is an anonymous one) making that wonkiness visible.
I'll add more when/if I figure it out.
Having an issue with a bit of code designed to add an email alias to a list box. I have a check built in to ensure the item you attempt to add isn't already in the list, but the check is case sensitive when I don't want it to be. I'm not sure how to make it ignore the case... Here's my code:
Dim ItemToAdd as String = ""
ItemtoAdd = tbxItemtoAdd.Text + "#emaildomain.co.uk"
If Not lbxEmailAliases.Items.Contains(ItemtoAdd) Then
lbxEmailAliases.Items.Add(ItemtoAdd)
End If
At the moment if the list box contains johnsmith24#emaildomain.co.uk and you try to add Johnsmith24 (capital J), it will add this successfully, but I don't want it to do that. How do I get it to ignore case?
I've tried changing lbxEmailAliases.Items.Contains(ItemtoAdd) to lbxEmailAliases.Items.Contains(ItemtoAdd, StringComparison.CurrentCultureIgnoreCase) but it's not happy with this as there are too many arguments, it will only take one.
Any ideas please?
If this is a standard WinForm ListBox control, then there is no way to do it without looping through all of the items and checking each one individually. For instance:
Dim found As Boolean = False
For Each item As Object In ListBox1.Items
found = item.ToString().Equals(ItemToAdd, StringComparison.CurrentCultureIgnoreCase)
If found Then
Exit For
End If
Next
If found Then
lbxEmailAliases.Items.Add(ItemtoAdd)
End If
However, if you are comfortable with LINQ, you can do it more concisely like this:
If ListBox1.Items.OfType(Of String).Any(Function(item) item.Equals(ItemToAdd, StringComparison.CurrentCultureIgnoreCase)) Then
lbxEmailAliases.Items.Add(ItemtoAdd)
End If
Or, as Andy G pointed out, the LINQ Contains method is even easier since it accepts an IEqualityComparer and a stock one which supports case insensitive string comparisons is provided by the framework:
If ListBox1.Items.OfType(Of String).Contains(ItemToAdd, StringComparer.CurrentCultureIgnoreCase) Then
lbxEmailAliases.Items.Add(ItemtoAdd)
End If
It should be StringComparer, not StringComparison:
lbxEmailAliases.Items.Contains(ItemtoAdd, StringComparer.InvariantCultureIgnoreCase)
The method accepts an IEqualityComparer, the docs.
As pointed out by Steven Doggart, ListBox Items require the use of OfType(Of T):
lbxEmailAliases.Items.OfType(Of String).Contains(ItemtoAdd, StringComparer.InvariantCultureIgnoreCase)
An alternative could be the FindString-method:
If lbxEmailAliases.FindString(ItemtoAdd) = ListBox.NoMatches Then
lbxEmailAliases.Items.Add(ItemtoAdd)
End If
Note: This method searches for items that start with the specified string and returns the index of the first found item.
Means it will find jdoe#domain.com even if the existing e-mail-address is jdoe#domain.computer.com.
So maybe it's not the best solution for your specific case.
EDIT:
You can use FindStringExact instead. Like this you'll get the wanted case insensitive, non-partial comparison.
If lbxEmailAliases.FindStringExact(ItemtoAdd) = ListBox.NoMatches Then
lbxEmailAliases.Items.Add(ItemtoAdd)
End If
Is there any way of getting all the non-nil parameters / properties
of an object? I found this: getmetadata(self.xxxx) and i am looking for something like: getalldata(self).
I'm currently working on a project where lua is involved. Unfortunately, there is no complete reference and i have to use precompiled stuff.
I hope you are able to understand what I am trying to say.
I'm going to assume that when you are referring to "objects" you are meaning "lua tables with an __index metatable pointing to other tables". If that is not the case, this answer will not help you.
If your object structure is made with tables (this is, all __indexes are tables) then you can "parse them up" to obtain all the properties and inherited properties.
If you have any function as __index then what you ask is impossible; there's no way to get the "list of values for which a function returns a non-nil value".
In the first case, the code would look like this:
function getAllData(t, prevData)
-- if prevData == nil, start empty, otherwise start with prevData
local data = prevData or {}
-- copy all the attributes from t
for k,v in pairs(t) do
data[k] = data[k] or v
end
-- get t's metatable, or exit if not existing
local mt = getmetatable(t)
if type(mt)~='table' then return data end
-- get the __index from mt, or exit if not table
local index = mt.__index
if type(index)~='table' then return data end
-- include the data from index into data, recursively, and return
return getAllData(index, data)
end
But remember, if any of your __indexes is a function, there is no way to get all the properties; at least not from Lua.
I wrote my own printObject code.. here it is
function printObj(obj, hierarchyLevel)
if (hierarchyLevel == nil) then
hierarchyLevel = 0
elseif (hierarchyLevel == 4) then
return 0
end
local whitespace = ""
for i=0,hierarchyLevel,1 do
whitespace = whitespace .. "-"
end
io.write(whitespace)
print(obj)
if (type(obj) == "table") then
for k,v in pairs(obj) do
io.write(whitespace .. "-")
if (type(v) == "table") then
printObj(v, hierarchyLevel+1)
else
print(v)
end
end
else
print(obj)
end
end
This is the opposite approach then the post before used.
Go through all key value pairs in the table. If the value of one index is a table, go through this table.
This solution will not get the upwards metatables like the other post did
I believe objects are just a table, so you should be able to iterate over the properties as any other table:
for i,v in ipairs(your_object) do body end