i have an easy question but i m stack at the moment and i was wondering if anyone can help me out,
i want to display from the messagebox in powerbuilder inside the box static text and then the value of a variable,
ok i can show easily the value like that,
Messagebox( 'Message', NbrRows)
But i want to show inside the box before the value of the variable NbrRows the text,
'Total events so far' and then the variable value.
I know that the syndax of the messagebox is like that for example with an exclamation icon
MessageBox("Result", Abs(NbrRows), Exclamation!, OKCancel!, 2)
please any help would be really appreciated,
thank you in advance
The MessageBox() built-in function can take different datatypes for its second parameter (message) but if you need to mix different types at once, pbscript does not support to concatenate a string with another type like a long or a boolean e.g "foo" + 42. To do so, you need to convert other types to text with the string() function:
MessageBox( 'Message', 'Total events so far' + string(NbrRows))
//or if some other processing needed with the value
MessageBox( 'Message', 'Total events so far' + string(Abs(NbrRows)))
Beware that a null value will propagate to the whole expression in the case where NbrRows could be null, resulting in no message at all. Using the [general] format with string() is a useful trick that will replace a null value with an empty string:
MessageBox( 'Message', 'Total events so far' + string(Abs(NbrRows), '[general]'))
Related
private long START_TIME_IN_MILLIS;
private long TimeLeftInMillis = START_TIME_IN_MILLIS;
i have declared these variables, which is meant to store an input from an EditText, but in my OnCreateView i have this line
START_TIME_IN_MILLIS = edtInsertTime.getText();
but it gives me an error, how do I get the input of time in milliseconds and store it in START_TIME_IN_MILLIS?
You didn't post the error you received, and that would be helpful since it can be of hundred reasons..
Just looking at this code, you have variable of type long, ( which is a numeric type ), and what you get from edtInsetTime.getText()? , a type "Editable" according to the documentation, and you can't store Editable object in a long variable.
https://developer.android.com/reference/android/widget/EditText
public Editable getText ()
Returns Editable - The text displayed by the text view.
To get a long value from it, you first need to get a String from this EditText, then convert it to a long format, and then assign it to the variable.
Examplary code would be.
START_TIME_IN_MILLIS = Long.valueOf(edtInsertTime.getText().toString());
Breaking it down.
String text = edtInsertTime.getText().toString()
returns the String value of an edittext
That value then can be converted to a long value by parsing the String to long, with methods like
Long.parseLong(text)
or
Long.valueOf(text)
Asking this question means you don't have basic understanding of how types works in java, so feel free to read about it https://www.baeldung.com/java-primitives
Despite of checking many questions relating error 13, I could not find answers to my problem, so I am giving a shot here:
I am building my code to save information from a userform, but first I am testing to see if mandatory textboxes are empty. Since I am using a 64 bits machine I have used Trevor Eyre´s CalendarForm.
However while testing the code I hit a problem with the empty textboxes that receives the dates from CalendarForms:
In this line:
Dim dteCompraDataOps As Date: dteCompraDataOps = Me.txtTesouro_Compra_DataOps.value
This part is highlighted and returns Runtime Error 13:
dteCompraDataOps = Me.txtTesouro_Compra_DataOps.value
When I check the values coming from empty TextBoxes I get:
dteCompraDataOps = "00:00:00"`
Which is correct since it should be treated as Date, but this:
Me.txtTesouro_Compra_DataOps.value = ""
Is coming as a string.
I did a little search and noticed that Date data types are tricky when the textbox they come from are empty.
I could find a solution: creating a Select Case to test the mandatory fields before declaring the variables but I would like o learn how to deal with the empty textboxes that are supposed to be empty.
Any chance you can shed some light into my conundrum?
Thanks in advance.
Cub4_RJ
There are two ways to handle this.
a) Check for Null:
With Me.txtTesouro_Compra_DataOps
If Not IsNull(.Value) Then
If IsDate(.Value) Then dteCompraDataOps = . Value
End if
End With
b) Introduce a new variable of Variant type which accepts everything (including nulls) and check it's value.
Dim rawData As variant
rawData = Me.txtTesouro_Compra_DataOps.Value
If Not IsNull(rawData) Then
If IsDate(rawData) Then dteCompraDataOps = rawData
End If
The problem with approach A, is that the value 123 is treated as a date, however option B will catch it.
I'm a bit of a noob. When I try to build my solution I get this single error and I don't know what to do to fix it.
'Calculate and display cost estimate
decCostEstimate = decFeet * decCostPerFoot
**lblCostEstimate = decCostEstimate.ToString("C")**
I'm not sure what to do. Please help me.
You want to set the Text property of the label, not the label itself
lblCostEstimate.Text = decCostEstimate.ToString("C")
Your code tries to assign a string value to an object of type Label, thus causing the error.
The label is an object from the type Label.
It is not possible to write an object from Type int or string, etc. into an label-object.
To make the label show your result just put the result into the text-property of the label:
lblCostEstimate.Text = decCostEstimate.ToString("C")
I've been tasked with an ExactTarget task, which uses Ampscript. Trying to learn on the go here. See code snippet below:
%%[
Var #testString, #testOutput
Set #testString = Qwerty
Set #testOutput = BuildRowsetFromString(#testString,"~")
]%%
TestOutput:%%= v(#testOutput) =%%
The code works if the testString contains a ~, but when there is no ~ character in the string, the ouput is blank. Is this correct by design? Do I need to add a conditional to check for the presence of the ~ character?
That's the expected behavior. The BuildRowsetFromString() function alone isn't going to return any value when displayed, you're going to need to use Row() and Field() in order to pull the value out.
Using your example:
%%[
Var #testString, #testOutput
Set #testString = "Qwerty"
Set #testOutput = BuildRowsetFromString(#testString,"~")
]%%
RowCount: %%=RowCount(#testOutput)=%%
TestOutput: %%=v(#testOutput)=%%
The RowCount() function returns a value of 1, essentially saying it knows there's at least one 'row' in there. To display that one value, you'll need to wrap that value with Field() and Row():
TestOutput: %%=Field(Row(#testOutput,1),1)=%%
If you want to display other values in the string, say you were passing "Qwerty~Second~Third", you'll need to either change the number at the Row() function or perform a loop.
References
Using Loops
BuildRowsetFromString() Function
The program asks for input in gui editbox as a value, then it takes this value and applies the equation to get the pressure. I haven't been able to do so and I heard from some classmates that matlab takes the input as a string and doesn't operate strings.
get(handles.spl,'String') this is how I get the value, I tried get(handles.spl,'Double') instead but it didn't work, also tried str2double.
I don't know what else to try, I'm also pretty new in programming.
I'd appreciate the help, thanks.
You are correct that the uicontrol String property returns...a string. So you'll need to convert it to a number using str2double.
u = uicontrol('style', 'edit', 'String', '42');
strvalue = get(u, 'String');
numvalue = str2double(strvalue);
% 42