I'm a bit new in plsql, so could you tell me it exists a way to negate a case?
I mean, this way:
select CASE DENOM_CURRENCY_CODE
WHEN != 'MXN' THEN 'convert to USD'
ELSE TO_CHAR(QUANTITY) --keep the quantity
END
I received this messaage "ORA-00936: missing expression" I´ve tried too with "<>" and "not".
Thanks for reading
The structure for this type of expression is
Case when "expression" then
//do something
Else
//do something else
End
In your case it should be
select CASE when DENOM_CURRENCY_CODE
!= 'MXN' THEN 'convert to USD'
ELSE TO_CHAR(QUANTITY) --keep the quantity
END
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have list of items in a weblist and which has both parent and child. Child is indented to the right, I need to retrieve values of child and parent in two different columns in a datatable.
My code goes like this:
list = qtp_getroproperty(page.weblist(), "items count", itemsCount
For n = 1 To itemsCount
items = page.weblist(), getitem(n)
In VBScript it's Left():
>> For Each s In Array("x", " x", " x")
>> WScript.Echo s, CStr(" " = Left(s, 1))
>> Next
>>
x Falsch
x Wahr
x Wahr
>>
Try this
if strSurname.StartsWith(" ")
There are several ways to go about this:
Extract the first character with the Left function, as Ekkehard Horner suggested:
If Left(str, 1) = " " Then
...
End If
Check the first character with the InStrRev function:
If InStrRev(str, " ", 1) > 0 Then
...
End If
LTrim the string and compare it to the original string:
If LTrim(str) <> str Then
...
End If
Use a regular expression:
Set re = New RegExp
re.Pattern = "^ "
If re.Test(str) Then
...
End If
Note that this last approach is the most versatile, but also the most expensive. Usually it won't make sense to use this to check for something as simple as "does the string begin with a space". It becomes more useful if for instance you want to check "does the string begin with any kind of whitespace" ("^\s").
This question is related to a previous one I just asked here, so forgive me if much of the language seems similar.
I have a string that has multiple lines. What I am doing is checking each line for specific characteristics and then treating them accordingly.
One characteristic is if the line begins with a + or a -. That works just fine.
Another characteristic is if it contains nothing but a \n, and Ilya helped me figure out how to detect those lines, so that's good.
The last type of string I am trying to detect is those that don't match any of the above criteria, but come AFTER a line that begins with either a - or +.
Taken out of context, this is an example of a valid string I would like to find: " end\n",
However, here is a more complete example within the context of being after a line that begins with + or -.
"+ Reflection.add_reflection self, name, reflection\n",
" end\n",
" \n",
"- habtm_reflection = ActiveRecord::Reflection::HasAndBelongsToManyReflection.new(name, scope, options, self)\n",
In this particular instance, I am trying to pick out the second line.
Here is an instance where strings that match the pure string matching parameter would be disqualified because they come BEFORE a string that starts with a - or a +.
" #\n",
" # All of the association macros can be specialized through options. This makes cases\n",
" # more complex than the simple and guessable ones possible.\n",
"- module ClassMethods\n",
I hope that's clear.
Edit 1
To provide more clarity on what I am looking for. Basically I have broken the string into a bunch of lines and then I am iterating over each line.
So this is what I have done:
<% diff.body.lines.each do |dl| %>
<% if dl.start_with?("-") %>
<% elsif dl.start_with?("+") %>
<% elsif dl.strip.empty? %>
<% end %>
<% end %>
So what I want to do is to either modify the above set of if statements to accommodate this latest line check, or find some way to check it by adding another elsif condition....although considering that I need to know what happened to the line above I am not seeing how to do that without modifying this if statement.
str = [
"+ Reflection ...\n",
" end\n",
" \n",
"- habtm_reflection = ...\n"].join
str[/(^[+-].*$)\n(?!\n)(^[^+-].*$)/, 2]
#⇒ " end"
The regular expression basically looks up the line that is started with either + ot - (with (^[+-].*$)), skips the \n and then matches the line that is not started with one of + or - (with (^[^+-].*$).)
I am getting an "expected end of statement" error at line 26, the third to last line. If you look at the code, it is a simple game that has one person enter a word, the script replaces all consonants with underscores, and the second player has to guess the word. Line 26 is, I think, the only thing wrong with this program.
phrase=inputbox("Player 1: Enter a phrase","Guessing Game")
phrase=answer
phrase=Replace(phrase,"A","_")
phrase=Replace(phrase,"B","_")
phrase=Replace(phrase,"C","_")
phrase=Replace(phrase,"D","_")
phrase=Replace(phrase,"F","_")
phrase=Replace(phrase,"G","_")
phrase=Replace(phrase,"H","_")
phrase=Replace(phrase,"J","_")
phrase=Replace(phrase,"K","_")
phrase=Replace(phrase,"L","_")
phrase=Replace(phrase,"M","_")
phrase=Replace(phrase,"N","_")
phrase=Replace(phrase,"P","_")
phrase=Replace(phrase,"Q","_")
phrase=Replace(phrase,"R","_")
phrase=Replace(phrase,"S","_")
phrase=Replace(phrase,"T","_")
phrase=Replace(phrase,"V","_")
phrase=Replace(phrase,"W","_")
phrase=Replace(phrase,"X","_")
phrase=Replace(phrase,"Y","_")
phrase=Replace(phrase,"Z","_")
Do
result=InputBox "Player 2 enter your guess for" & phrase , "Guessing Game"
Loop until result==answer
msgbox "You got it!",vbokonly,"Guessing Game"
In VBScript, the 'equal' comparison operator is =. So change
Loop until result==answer
==>
Loop until result = answer
You're getting that error, because you used a function in an assignment without putting its parameter list in parentheses. Change this line:
result=InputBox "Player 2 enter your guess for" & phrase , "Guessing Game"
into this:
result=InputBox("Player 2 enter your guess for" & phrase , "Guessing Game")
This is one of VBScript's gotchas: depending on where/how you call a procedure or function, you must or mustn't put the parameter list in parentheses.
>>> String 3, "*" 'must not use parentheses here
>>> String(3, "*")
Cannot use parentheses when calling a Sub (0x414)
>>> Call String(3, "*") 'must use parentheses here
>>> Call String 3, "*"
Expected end of statement (0x401)
>>> v = String(3, "*") 'must use parentheses here either
>>> v = String 3, "*"
Expected end of statement (0x401)
To make matters worse, there are situations where parentheses can be used anyway, because they have a different meaning in that context:
>>> Hour(Now)
This actually works, because here the parentheses do not mean "parameter list", but "pass this argument by value". Take a look this article about the many interesting situations parentheses can create in VBScript.
The other mistake in your script, as Ekkehard.Horner already pointed out, is that you use == instead of = for comparing values.
As a side note: you seem to assume that the input will always consist of uppercase letters only, but you never enforce that anywhere. You may want to UCase your input or add a check to validate the input.
Seeing jmvp do such a good job optimizing your program made me want to do the same! :)
Here's my version. I added a constant to specify the application name (since it's used a few times) and also allow player 2 to quit playing by clicking Cancel (or entering nothing).
Const APP_TITLE = "Guessing Game"
strPhrase = InputBox("Player 1: Enter a phrase", APP_TITLE)
With New RegExp
.Pattern = "[^AEIOU]"
.Global = True
strDisplay = .Replace(strPhrase, "_")
End With
Do
strResult = InputBox("Player 2: Enter your guess for " & strDisplay, APP_TITLE)
Loop Until StrComp(strPhrase, strResult, vbBinaryCompare) = 0 Or Len(strResult) = 0
If Len(strResult) > 0 Then MsgBox "You got it!", vbOkOnly, APP_TITLE
Dim phrase As String = InputBox("Player 1: Enter a phrase", "Guessing Game")
Dim charCount As Integer = phrase.Length
Dim strMask As String = vbEmpty
For x = 1 To charCount
strMask &= "_"
Next
Dim guess As String = vbEmpty
Do
guess = InputBox("Player 2 enter your guess for " & strMask, "Guessing Game")
Loop Until phrase = guess
MsgBox("You got it!", vbOKOnly, "Guessing Game")
I have the following code:
Dim todaysDate
todaysDate = Day(Now)
Select Case todaysDate
Case 1 to 5
Msgbox("1 to 5")
Case 23 to 31
Msgbox("23 to 31")
End Select
When I put it in a VBS file and run it, i get "Expected Statement" for Line 9 Char 10.
If i copy and paste the code into Excel's VBA editor, it runs fine with no errors.
Any ideas why it isnt working in a VBS file?
In VBScript, the Case statement doesn't allow the x To y syntax. You're only allowed to use a single value or a comma-delimited list of values. You'll have to use an If/ElseIf statement instead.
Try the following:
Select Case TRUE 'this is important, HT to Cheran
Case todaysDate >= 1 And todaysDate <=5
Msgbox("1 to 5")
Case todaysDate >=23 And todaysDate <=31
Msgbox("23 to 31")
Case else
'However you want to handle this
End Select