How do I write the ampScript code to this:
If the field energy_type is not empty then show the copy starting 'Until 30 March 2023...
Thanks in advance.
%%[
Set #field_energy_type = AttributeValue("energy_type")
If Empty(#field_energy_type) Or #field_energy_type = "" Then
Set #value_energy_type = "Until 30 March 2023..."
Else
Set #value_energy_type = ""
EndIf
]%%
%%=v(#value_energy_type)=%%
Other examples can be found here: https://ampscript.guide/attributevalue/
Related
I wrote an automation script that uses the following SAP GUI:
objSess.findById("wnd[0]").Maximize
objSess.findById("wnd[0]/tbar[0]/okcd").Text = "flqaf"
objSess.findById("wnd[0]").sendVKey 0
objSess.findById("wnd[0]").sendVKey 17
objSess.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").CurrentCellColumn = "TEXT"
objSess.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").SelectedRows = "0"
objSess.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").DoubleClickCurrentCell
objSess.findById("wnd[0]/usr/ctxtS_BELNR-LOW").Text = W_BPNumber
objSess.findById("wnd[0]/usr/ctxtS_BELNR-LOW").SetFocus
objSess.findById("wnd[0]/usr/ctxtS_BELNR-LOW").caretPosition = 10
objSess.findById("wnd[0]").sendVKey 8
objSess.findById("wnd[0]").sendVKey 0
objSess.findById("wnd[0]/tbar[0]/btn[3]").press
Everything works fine, however sometimes the problem aborts in SAP and exactly when that happens I want to capture it by writing the term "error" into an excel cell.
I tried adding this line in vba
objSheet.Cells(iRow, 5) = GuiStatusbar.Text
As well as
objSheet.Cells(iRow, 5) = objSessFindById("wnd[0]/sbar").Text
The code still runs fine but my cells in column 5 remain empty. Any ideas how to solve this?
It might help if you wait a little.
fo example:
...
objSess.findById("wnd[0]").sendVKey 0
waitTill = Now() + TimeValue("00:00:01")
While Now() < waitTill
DoEvents
Wend
if objSess.findById("wnd[0]/sbar").messageType = "E" then 'other types: W, I, S, A
objSheet.Cells(iRow, 5) = objSessFindById("wnd[0]/sbar").Text
end if
objSess.findById("wnd[0]/tbar[0]/btn[3]").press
...
Regards, ScriptMan
I have been looking on stackoverflow but could not get an definitive answer to my little problem. I am fairly new to coding and am still dealing with syntax sometimes.
Right now I have a little loop reading an array, inside the loop it checks for an if statement. I have been checking the loop which works fine, and the array as well. The if statement works until im starting to use "isText".
After searching a bit I noticed "isText" is not a function, is there something equivalent?
Right now my if statement goes as follows: IF A = B and C (Contains ANY value at all) then Write something somewhere in a cell
Right now the code I am using is:
Sub KnopKlik()
Dim Soorten(10)
Dim Teller As Integer
Dim Column1 As String
Column1 = Sheets(2).Range("C1").Value
MsgBox (Column1)
Sheets(1).Select
Range("E2").Select
For Teller = 0 To 10
Soorten(Teller) = ActiveCell.Offset(Teller).Value
Next Teller
For Teller = 0 To 10
If Sheets(2).Range("B9") = Soorten(Teller) And Application.IsText(Column1) Then
MsgBox ("Check")
Sheets(2).Range("E9").Value = ActiveCell.Offset(Teller, 3)
Sheets(2).Select
Range("B9").Select
Teller = 10
Else
End If
Next Teller
End Sub
Right now the last part of the if statement is the problem
And Application.IsText(Column1) Then
EDIT**
This is how I solved it now. Basically whenever there is ANYTHING at all in that cell it will pass through.
If Sheets(2).Range("B9") = Soorten(Teller) Then
'Als B9 Gelijk is aan (database) DAN!>>>
If Not Column1 = "" Then
Sheets(2).Range("E9").Value = ActiveCell.Offset(Teller, 3)
End If
Else
End If
Thanks in advance.
You can do it like this:
If Sheets(2).Range("B9") = Soorten(Teller) And Len(Trim(Column1)) > 0 Then
The len will return the length of the string. The Trim will remove the empty spaces from left and right, thus if it is an empty string it will be true.
I trying to perform a calculation on some values within a DGV that has been imported from data within an xls file. but I cant get the loop to work. what I need it to do is read the value of the cells in column 2 and column 3 of each row, put them in to a text box and then output the result of the calculation to column 4 of the DVG. I would post the code but frankly I haven't got anything real to go on. am I correct in thinking I need to be using a For each loop???
Any help or guidance is greatly appreciated.
Thanks in advance
I find it Little hard understanding your request... But how about this?
For Each Row As DataGridViewRow In DataGridView1.Rows
Dim CellValues As New List(Of String)
Dim Failed As Boolean = False
For x = 1 To 2 'This is right. It's NOT supposed to be 2 To 3.
If Row.Cells(x).Value <> Nothing Then
CellValues.Add(Row.Cells(x).Value.ToString())
ElseIf Row.Cells(x).Value = Nothing Then
Failed = True
End If
Next
If Failed = True Then
Continue For
End If
TextBox1.AppendText(CellValues(0) & " + " & CellValues(1) & Environment.NewLine)
Row.Cells(3).Value = CInt(CellValues(0)) + CInt(CellValues(1))
Next
Is there a way of looping through all of the cells and if somewhere within a certain cell that contains a certain piece of string you can possibly remove that for example look for ",master" if you find it within "Daily Spendings, master" you could remove it and make the writing bold.
I'm currently using,
For x As Integer = 0 To gridCategories.Columns.Count - 1
If gridCategories.Rows(0).Cells(x).Value.ToString = ",master" Then
gridCategories.Rows(0).Cells(x).Value.ToString.Replace(",master", "")
End If
Next
All help is massively appreciated,
Have you try like this ?
For x As Integer = 0 To gridCategories.Rows.Count - 1
If gridCategories.Rows(x).Cells(0).Value.ToString = ",master" Then
gridCategories.Rows(x).Cells(0).Value.ToString.Replace(",master", "")
End If
Next
I have a problem accessing a Stored Procedure via ASP from an SQL Database.
This is my code for the recordset:
Dim com_AntwoordenPerVraag__mem_id
com_AntwoordenPerVraag__mem_id = "0"
If Session("MM_MemberID") <> "" Then
com_AntwoordenPerVraag__mem_id = Session("MM_MemberID")
End If
Dim com_AntwoordenPerVraag__cat_id
com_AntwoordenPerVraag__cat_id = "0"
If Request.QueryString("cat_id") <> "" Then
com_AntwoordenPerVraag__cat_id = Request.QueryString("cat_id")
End If
set com_AntwoordenPerVraag = Server.CreateObject("ADODB.Command")
com_AntwoordenPerVraag.ActiveConnection = MM_modular_STRING
com_AntwoordenPerVraag.CommandText = "dbo.spAantal_antwoorden_per_vraag_per_member"
com_AntwoordenPerVraag.Parameters.Append com_AntwoordenPerVraag.CreateParameter("#RETURN_VALUE", 3, 4)
com_AntwoordenPerVraag.Parameters.Append com_AntwoordenPerVraag.CreateParameter("#mem_id", 3, 1,2,com_AntwoordenPerVraag__mem_id)
com_AntwoordenPerVraag.Parameters.Append com_AntwoordenPerVraag.CreateParameter("#cat_id", 3, 1,2,com_AntwoordenPerVraag__cat_id)
com_AntwoordenPerVraag.CommandType = 4
com_AntwoordenPerVraag.CommandTimeout = 0
com_AntwoordenPerVraag.Prepared = true
set rs_AntwoordenPerVraag = com_AntwoordenPerVraag.Execute
rs_AntwoordenPerVraag_numRows = 0
I get the following error message:
ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
I get the message here:
If rs_AntwoordenPerVraag.EOF And rs_AntwoordenPerVraag.BOF Then
EDIT
I found the solution.
After:
set rs_AntwoordenPerVraag = com_AntwoordenPerVraag.Execute
I put:
If rs_AntwoordenPerVraag.State <> 1 Then
While rs_AntwoordenPerVraag.State <> 1
Set rs_AntwoordenPerVraag = rs_AntwoordenPerVraag.NextRecordset
Wend
End If
And now it works :-)
Your command needs a connection object, and it needs to be opened, rather than just a connection string.
See http://support.microsoft.com/kb/300382
Additionally, your code will be clearer if you import the ADODB constants file, and use those (ie: https://web.archive.org/web/20210513005432/https://www.4guysfromrolla.com/webtech/faq/Beginner/faq7.shtml )
The problem that you have calling the stored procedure is the number of lines touched by each query that is returned by SQL-Server inside a closed recordset before the final resultset. You can either look for the next recordset as you have already found or you can add the following instruction at the beginning of your SP in order to eliminate the sending of the number of lines for each query.
SET NOCOUNT ON
I prefer this last solution as it make the VBScript code simpler but it's just a matter of taste.
OP itself have found the solution and it works! Really Thanks to him.
After:
set rs_AntwoordenPerVraag = com_AntwoordenPerVraag.Execute
put:
If rs_AntwoordenPerVraag.State <> 1 Then
While rs_AntwoordenPerVraag.State <> 1
Set rs_AntwoordenPerVraag = rs_AntwoordenPerVraag.NextRecordset
Wend
End If