I'm using an editor widget to display a longchar value read from a text file. OpenEdge 11.5 ChUI on Linux.
The logic is similar to the following:
def var mytext as longchar
init "Sample Text. Sample Text. Sample Text.".
form mytext view-as editor large inner-chars 30 inner-lines 15
scrollbar-horizontal scrollbar-vertical
with frame frame1 no-labels no-box.
view frame frame1.
display mytext with frame frame1.
mytext:read-only = yes.
enable mytext with frame frame1.
wait-for end-error of mytext.
When the editor is displayed, the text in the editor widget is "highlighted" (i.e., shown in reverse video). (See screenshot below.)
Is there a way to display the text in the editor widget so that it is not "highlighted"?
I usually do something like this:
/* textedit.p
*
* a file viewer
*
*/
define variable fileName as character no-undo format "x(30)".
define variable fileBody as longchar no-undo.
fileName = "textedit.p".
file-info:file-name = fileName.
if file-info:full-pathname = ? then
do:
message "no such file:" fileName.
pause.
quit.
end.
copy-lob from file file-info:full-pathname to fileBody.
display
fileBody view-as editor inner-chars 160 inner-lines 52 large no-word-wrap
with
no-box
no-labels
color display normal prompt normal /* this changes the coloring */
.
pause.
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/color-phrase.html
You can also fiddle with frame and widget attributes if you prefer that sort of thing.
In c# i have a trackbar with range of 0-254.
I want to convert each digit to hex byte, meaning that 250 will be "32-35-30"
and display that in a text box
how can i do that?
I dont have any code for example
It is a simple task:
string s = "250";
byte[] array = System.Text.Encoding.ASCII.GetBytes(s);
string s2=BitConverter.ToString(array);
Now s2 has the desired output.
i have a text input box in flex. i wanted to call a function if the text of text input box is >0. i have parsed the text into integer ,parseInt(str.text) where str.text is 0.03(something like this) then it becomes zero, as i am parsing into integer.
any help is appreciated.
Just do Number(str.text), that will give you a float. Use isNaN() to check if it's actually a number that was parsed.
var n:Number = Number(textInput.text);
if (!isNaN(n)) {
// do whatever
}
i have done it like below
parseFloat(str.text)>0
{
// statements;
}
so thts if user enters 0.00 or 00.00 or 00000.0 or 000.000 it will not allow , if he enters 0.01 or 0.89 or anything greater than zero will be allowed.
Anyway thanks for the response.
Is there anything wrong with following snippet of code?
var d:Date = DateField.dateToString(myDateField.text,"DD/MM/YYYY");
testTextArea.text = d.getSeconds().toString();
Error: Implicit coercion of a value of
type String to an unrelated type Date.
Here is your problem: DateField.dateToString's first parameter is supposed to be a date. It then takes that date and returns a string using the second parameter as a format string.
It looks like you're trying to convert the string to a date (the other way around) so you can get the seconds from it and put it in the text area. The DateField control has a selectedDate parameter that will give you the date you need. Then you just run this code to put it in the text area:
testTextArea.text = myDateField.selectedDate.getSeconds().toString();
I would like to know the easiest way to format a string as accounting style. I know how to format as currency using {0:c} but there are some differences in accounting style, for example, all the dollar signs will line up as well as all the decimal points, and negatives are expressed in parenthesis rather than with a "-" minus sign. You can find a good example of the way i would like it in excel if you format the cells as "accounting" with 2 decimal places.
Ignoring your alignment requirements, you could use
number.ToString("€#,##0.00;(€#,##0.00);Zero")
to bracket negative numbers.
To align your numbers, you'd have to format without the currency symbol, and pad the formatted numbers yourself with spaces, using a fixed width font would make this job easier for you.
EDIT:
It seems String.Format is your friend:
String.Format("{0,15:#,##0.00 ;(#,##0.00);- }", number)
where 15 is the total width of the output, and you need to append this text to your currency symbol. (Again, this aligns in fixed width only)
There's no format string shortcut (the single-character ones with default rules) for handling accounting style formats (here's a cheat sheet with the available format strings) so you'll have to write a more specific one (like Patrick's answer) or your own parsing method.
The alignment requirements would be specific to how you're displaying them. I'm assuming you are using a table, in which case you're limited by what HTML supports, and it doesn't support accounting style alignments like Excel.
In this blog there were some various formats outlined and this one seemed to be close to what you were looking for:
int neg = -10;
int pos = 10;
// C or c (Currency): It represent how many decimal place of zeros to show.
String.Format("{0:C4}", pos); //"$10.0000"
String.Format("{0:C4}", neg); //"($10.0000)"
It doesn't handle the padding (you may have to fix that yourself), but it does have the proper parenthesis.
You could do something using a variation of Patricks method. This will handle formating and alignment assuming you know the upper bound of how large a value you are dealing with:
private static string OutputAsCur(decimal val)
{
string format = " #,##0.00 ; (#,##0.00);Zero";
string frmt = val.ToString(format);
return CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol + frmt.PadLeft(15, ' ');
}
Here's a simple example app to see it format:
static void Main(string[] args)
{
decimal d = 155.55m;
Console.WriteLine(OutputAsCur(d));
Console.WriteLine(OutputAsCur(d * -1));
Console.WriteLine(OutputAsCur(1002.32m));
Console.WriteLine(OutputAsCur(1002.32m * -1));
Console.ReadLine();
}
You can use a format string for String.Format to get what you're trying to accomplish. The only trick is that positive numbers, since they will not have a closing parenthesis mark, will have to incorporate a space at the end if they will be aligned with any negative numbers that will be in the column. The trick is to get that space into the string in a way that HTML will not ignore. I simply use the HTML entity which indicates a non-breaking space in HTML.
Here's sample code. First, in the aspx.
<table>
...
<tr>
<th scope="row" colspan="2">Total Revenue</th>
<td class="numeric total"><asp:Label runat="server" ID="TotalRevenueLabel" /></td>
</tr>
...
</table>
Now, the codebehind.
public const string kMoneyFormat = "#,#.00' ';(#,#.00);'-.-- '";
public void DataBind()
{
using (FinancialDataContext sql = new FinancialDataContext())
{
var periodQuery = from m in sql.Forecasts()
select m;
ForecastsResult periodData = periodQuery.Single();
decimal totalRevenue = period.Data.income_actual.Value + periodData.other_income.Value;
TotalRevenueLabel.Text = totalRevenue.ToString(kMoneyFormat);
}
}
I followed these steps for apply the "Accounting" format.
In a new Book on Excel, select a cell.
Insert data (i.e any number; for this example, add 80000).
Select (Accounting) NumberFormat as is shown in the screenshot #1:
Screenshot #1:
Select "More Number Formats".
Select "Custom".
Select any of the pre-defined formulas (see screenshot #2).
Screenshot #2:
In my case, this is the desired format for this number.
The negative side of this is that when you select the cell with the format applied on it, you wont see selected (Accounting) "in the DropDownList" Number Format.