How can write" If for all I>=2 a(I) =b(I) then x=x+3 " in GAMS? - gams-math

How can I write this if statement :(I is a set , and a,b are parameter and x is variable)
If for all I>=2 we have , a(I) =b(I) then x=x+3 .
Thanks

Use loop as follow:
Loop (i$(i.val>2 and a(I)=b(I) ),
X=x+3;
);

Related

Using IF Statement inside a Where Clause in SQL Server

I have two params that are passed in a function which passed down to the SQL string. Variables can be null or has a value (int). If x is not null, use "this" column else use "that" column. I'm using SQL Server.
// Inside a function with two variables passed, x and y
$sql = "
SELECT
[...]
FROM
[...]
WHERE
[...]
AND [...]
-- This is the tricky part
AND
--- if $x is not null, use foo column else use bar column
IF (x, R.column = 2, R.another_column = 3)
[...]
";
Is this possible to select a column based on the value of the variable passed in?
AND
(
($x is not null and R.column = 2) OR
($x is null and R.another_column = 3)
)
Unless I'm misunderstanding, you just need logic, or a case statement would work.
$sql = "
SELECT
[...]
FROM
[...]
WHERE
[...]
AND
[...]
-- This is the tricky part
AND
--- if $x is not null, use foo column else use bar column
-- IF (x, R.column = 2, R.another_column = 3)
(
(X IS NULL AND R.column = 2)
OR
(X IS NOT NULL AND R.another_column = 3)
)
";
AND
--- if $x is not null, use foo column else use bar column
case
when x is NULL then R.another_column = 3
else R.column = 2
end
--in SQL Server...
DECLARE #x INT = 3;
SELECT *
FROM sys.schemas
WHERE (#x IS NULL AND schema_id = 2)
OR (#x IS NOT NULL and schema_id = 3)
--optional depending on how much you execute this query, it may help
OPTION(RECOMPILE)

How to insert an index in string.format?

I'm trying to add an index to string.format string, for example:
For i = 1 To Dataset.Tables(0).Columns.Count - 1
query_builder.Append(String.Format("#parameter{i}", i))
Next
What I'm trying to achieve is get in a similar result:
#parameter1
#parameter2
#parameter3 etc....
But I get this error:
Input string format not correct
why?
query_builder.Append(String.Format("#parameter{i}", i))
Should be
query_builder.Append(String.Format("#parameter{0}", i))
or
query_builder.AppendFormat("#parameter{0}", i)
You must specify a numeric value between brackets:
For i = 1 To Dataset.Tables(0).Columns.Count - 1
query_builder.Append(String.Format("#parameter{0}", i))
Next
{0} corresponds to the item at index 0 (first item) in the list of parameters to String.Format, which is variable i in your case.

VBA Extracting data from textbox

I am trying to extract partial information from a list, for which the information comes in a specific format (this list doesn't come in a spreadsheet):
A BUYS: PRODUCT # 85 / B SELLS
B BUYS: PRODUCT # 500 / C SELLS
B BUYS: PRODUCT # 200 / A SELLS
If I paste the entire list into a textbox, is it possible to extract only part of the data from the textbox?
For the first line of the list "A BUYS: PRODUCT # 85 / B SELLS", I would like to separate: "A" ; "Product" ; "85" ; "B", and put them into different cells in the same row.
Any help would be really appreciated. Or maybe you have a simpler method to achieve this?
Something like below? either that or you could try text to columns
temp = split("A BUYS: PRODUCT # 85 / B SELLS"," ")
A = temp(0)
Product = temp(2)
qty = temp(4)
B = temp(6)
If you would like to iterate through the list, perhaps something like the below?
Sub splitMyList()
Dim iRow As Integer
iRow = 1
Do While Cells( iRow, 1) <> ""
temp = Split( Cells( iRow, 1 ), " ")
Cells( iRow, 2 ) = temp(0)
Cells( iRow, 3 ) = temp(2)
Cells( iRow, 4 ) = temp(4)
Cells( iRow, 5 ) = temp(6)
iRow = iRow + 1
Loop
End Sub
This assumes you pasted your list in column A starting on row 1. Just change the figures if needed. Hope this helps

read comma separated integers in INI file

I have a INI file that looks like this !
[columnNumber]
Number1=2,4
this is my code
the ini file is read using function defined here
the columberNumber is taken as string "2,4" i want to split this and pass it into my select case object mytmp looping for all values in Number1 pass it to mytmp in select
columnNum = ReadIni(file, "columnNumber", "Number1")
mytmp = columnNum
x = Split(mytmp, ",")
For k = 0 To UBound(x)
'mytmp1 = Split(array_colnum, ",")
'mytmp2 = Search(array_col)
'mytmp1 = x(k)
'mytmp2 = x(k)
Next k
this is my select case
select case i...<does something>
select case mytmp
Could somebody guide me in doing this!
Updated : I want to put in select case i the values got from [columnNumber] my ReadIni function reads from [columnNumber section] the number1={2,4} i want to split this and store in a variable, the variable is read from select case variable
It's not completly clear what exactly you trying to do...
what is "I" variable? what it should contain?
mytmp = "2,4"
x = Split(mytmp, ",")
For k = LBound (x) To UBound (x)
'## Get value and store in variable "I".
i = x (k)
Select Case i
Case "2"
Response.Write "yep, it's 2"
Case "4"
Response.Write "yep, it's 4"
End Select
Next

VBA: Increase row number for my code

Below is my vba code,
For x = 0 To EleXML.ChildNodes.Length - 1
Range("A10" & x) = EleXML.ChildNodes.Item(x).getAttribute("aa")
Range("A10" & x) = EleXML.ChildNodes.Item(x).getAttribute("bb")
Range("A10" & x) = EleXML.ChildNodes.Item(x).getAttribute("cc")
Next x
My cell will begin from "A10", how can I auto increase it using "x" in my code? So,it should be "A11" in next loop.
Thanks in advance.
For x = 0 To EleXML.ChildNodes.Length - 1
Range("A10").offset(x,0) = EleXML.ChildNodes.Item(x).getAttribute("aa")
Range("A10").offset(x,0) = EleXML.ChildNodes.Item(x).getAttribute("bb")
Range("A10").offset(x,0) = EleXML.ChildNodes.Item(x).getAttribute("cc")
Next x
I almost always use Offset in these situations (documentation) because it is much, much, MUCH more clear than trying to manually create a string range.
It makes things much more clear when you are iterating and have something like
myRange.offset(rowOffset, colOffset)
than nearly all alternatives (such as the other answer or those posted in comments).
You could also look into using Cells(row, col) syntax.
Very simple:
For x = 0 To EleXML.ChildNodes.Length - 1
Range("A" & (10 + x)) = EleXML.ChildNodes.Item(x).getAttribute("aa")
Range("B" & (10 + x)) = EleXML.ChildNodes.Item(x).getAttribute("bb")
Range("C" & (10 + x)) = EleXML.ChildNodes.Item(x).getAttribute("cc")
Next x