I am new to AS400 and i want to know how can i give input at the run time in rpgle? - rpgle

I want to convert temperature from Fahrenheit to Celsius. At run time it should ask the temperature in Fahrenheit and then show the the equivalent temperature in celsius.

Unlike other languages, RPG is built specifically for business programs. Thus it has no built in console IO like C or Java. Instead user interaction is traditionally via an object called a device file which mimics database IO. However, there is one op code that can be used to access the external message queue and can send a message and receive a reply. This op code is DSPLY. It is quite limited, you can only display a 52 character message, but will work for this purpose. A real solution where you want user IO would involve a display file. But to get something like what you are asking for in a way similar to other languages, you could write the following:
ctl-opt Option(*SrcStmt : *NoDebugIo: *NoUnref)
DftActGrp(*No) ActGrp(*New)
Main(temprature);
dcl-proc temprature;
dcl-s degreesC Char(15) Inz('');
dcl-s degreesF Char(15) Inz('');
dsply 'Enter temprature in degrees F' '*EXT' degreesF;
degreesC = %char(
(%dec(degreesF:15:0) - 32) * 5 / 9
);
dsply ('Temprature in degrees C is: ' + degreesC);
return;
end-proc;
The first dsply has three parameters, the message, the message queue, and a variable for the reply (which must be a character variable). The second dsply just has the message which can be an expression if it is enclosed in parenthesis. There is no reply, and it sends to the *EXT message queue by default for interactive jobs.
NOTE: DSPLY is really useful only for testing and debug, and has only limited utility for that. A program that will face users would use a display file or some other way to interact with the user such as through a browser using the CGIDEV2 library.

A good start is to look at the RPG Manual then start researching DDS. There is TONS of documentation out there. Just search for "iseries" then your topic.

Related

Discord.py send dynamic time string

I'm currently working on a Bot where users can ask to play a game and set when to play it:
.play Valorant #30 -> "#anyone_who_is_playing_valorant, up for a round in 30 minutes?"
Currently, I'm editing the message every minute to display the correct time left, which unfortunately makes implementing other commands and functions way more difficult as it should be (while loop etc).
My only solution would be to display the time at which 30 minutes would be passed:
Message written at 17:00 -> "#anyone_who_is_playing_valorant, up for a round at 17:30?"
but due to timezones the displayed timestring has to be different for each user.
Actually, Discord supports such a function for embeds, but I haven't found a standart support for sending dynamic timestrings. I would imagine it to be like Pings, where there is no function but a syntax for it: <#!authorid>
Is there a way to send dynamic timestrings?
There is no dynamic time syntax in Discord messaging, the only such functionality is the timestamp in embeds as you mentioned.
Actually there is a way to have a dynamic string in your message but it does not work for the footer in the embed.
You only need to make a unix code,
from datetime import datetime
import calendar
date = datetime.utcnow()
utc_time = calendar.timegm(date.utctimetuple())
print(utc_time)
your output looks something like this: 1657723929
You format the code to this: <t:unixcode:R>
and it gives you
7 minutes ago
You can also make a timestamp which leads to the future with just adding the secconds to the unix code you just made e.g.:
this code <t:2665824929:R> represents
in 32 years
depends on when you see this because its dynamic

Get numbers of all screens in Xlib

I've been googling for quite a long time and I just can't find any information on how to get screen_number for every screen connected to computer. Here I found a list of macros and some of them (like for example ScreenOfDisplay(display, screen_number) ) use argument screen_number. However there is no such macro that could give me a list of those numbers (one for every connected screen). I know how to get number of default screen (DefaultScreen() ) and count of all screens ( ScreenCount() ) but what about other screens? I noticed that screen_number of default screen is 0, although I have only one screen connected to my computer so I can't really test what happens when there are more of them. I think that screen_number could be assigned in a very simple way which is screen_number=0 for first screen,screen_number=1 for second,screen_number=2 for third and so on but as I said... I can't test wheather it's true and even if I had multiple screens how could I be sure that it works like this for all computers .Please ,if anyone of you has more experience with X11 and knows all details about how it works,tell me if I am right.
The ScreenCount(dpy) macro and int XScreenCount(Display*) function both return the number of screens connected to the display. Valid screen numbers are 0 to ScreenCount(dpy)-1. Macros in Xlib.h confirm:
#define ScreenCount(dpy) (((_XPrivDisplay)dpy)->nscreens)
#define ScreenOfDisplay(dpy, scr) (&((_XPrivDisplay)dpy)->screens[scr])
Your source (2.2.1. Display Macros) provides enough information. Normally the default screen-number is 0, e.g., when connecting to the local host you could use :0.0 as indicated in the documentation for XOpenDisplay.
That is "normally". If you run VNC, normally that runs on a different display (the first 0 in the simple connection string shown).
But (reading the documentation), when an application calls XOpenDisplay, it asks for the given screen-number (which the X server may/may not honor):
screen_number
Specifies the screen to be used on that server. Multiple screens can be controlled by a single X server. The screen_number sets an internal variable that can be accessed by using the DefaultScreen() macro or the XDefaultScreen() function if you are using languages other than C (see "Display Macros").

How to create TI-BASIC (TI-84+) input forms?

In the TI-BASIC programming language (Specifically TI-84+), how do you create input forms, such as the ones included in the default apps on the TI-84+.
The image included here shows an example of what I'm trying to create: A menu that you can scroll through and input multiple variables freely before executing a function
Additionally, is it possible to make this menu dynamically-updating as variables are entered?
You've set a rather tall order for TI-Basic to fill. user3932000 is correct; there is no built in function to create an input form of the type you request.
However, there is nothing stopping you from creating an interactive interface yourself. Creating it from scratch will be a time consuming and, it will consume a significant amount of memory on your calculator. There is no boilerplate code you plug your variables into to get the results you want, but you might have some luck modeling it after this quadratic solver I wrote.
ClrHome
a+bi
Output(1,1," QUADRATIC
Output(2,1," AX²+BX+C
Output(3,1,"ZEROS:
Output(6,1,"A=
Output(7,1,"B=
Output(8,1,"C=
DelVar YDelVar D
" →Str1
While Y≠105
getKey→Y
If Ans
Then
Output(X,4,Str1
Output(3,7,Str1+Str1+Str1+"
End
X+(Ans=34)-(Ans=25
If Ans<6:8
If Ans>8:6
Ans→X
Output(Ans,16,"◄
D(Y≠45→D
If Y=25 or Y=34
sum({A,B,C}(X={6,7,8→D
If Y=104:⁻D→D
10not(Y)+Y(102≠Y)-13int(Y/13(2>abs(5-abs(5-abs(Y-83
If Ans≤9
D10+Ans-2Ans(D<0→D
If X=6:D→A
If X=7:D→B
If X=8:D→C
If A
Then
2ˉ¹Aˉ¹(⁻B+{1,⁻1}√(B²-4AC
Else
If B
Then
⁻C/B
Else
If C
Then
"No Zeros
Else
"All Numbers
End
End
End
Output(3,7,Ans
Output(6,3,A
Output(7,3,B
Output(8,3,C
End
ClrHome
Ans
Here's a GIF of what it does for you.
With a little more work. This code could be used on the Graph screen instead of the home screen, giving more option in terms of layout and design.
In the TI-BASIC programming language (Specifically TI-84+), how do you create input forms, such as the ones included in the default apps on the TI-84+.
There are many ways to ask for input in your program:
Prompt: Asks for input and stores it in a variable. For example, Prompt A. Simplest way to ask for input, but not very visually appealing.
Input: Similar to the Prompt command, except that now you can include text within the input. For example, Input "What is your name?",A.
Menu(: Multiple choice input, and each choice is connected to a Lbl marker somewhere else in the script. Much like the error screen with the quit/goto choices that you've probably seen. For example, Menu("Are you a boy or a girl?","Boy",B,"Girl",G).
getKey: Checks if a certain key is pressed, and will output True (1) if that key is pressed. For example, getKey 105. See here for which numbers each key corresponds to.
The image included here shows an example of what I'm trying to create: A menu that you can scroll through and input multiple variables freely before executing a function http://imgur.com/ulthDRV
I'm afraid that's not possible in programs. You can either put in multiple inputs, or you might be interested in looking into making apps instead.
Additionally, is it possible to make this menu dynamically-updating as variables are entered?
If you're talking about the text on top of the screenshot, yes you can; just put a Disp command or something after each line of Input, so that it continuously overwrites the text above with new text after you input a variable.

Reading emails with groovy (Java Mail)

I am using groovy in order to access gmail and read the Inbox. It is regular JavaMail and will not describe it here.
So for simplicity, after I connect to the store, I use this:
folder.open(Folder.READ_ONLY)
folder.messages.each { msg ->
...
doSomething with msg
...
}
this is working fine.
However I have a performance issue. Sometimes messages[] could be big. Some folders contain more than 1000 messages, and checking them all takes time.
I am looking for a quicker way to get only those emails that are the most recent (for example messages from the last 5 days or something like that)
of course I have the date information in each msg and I could do my comparison, but this is not efficient since it will loop through the entire collection.
Is there a better way to get those messages?
If you have JavaMail issue a SEARCH command with the criterion SINCE 04-JAN-2011, you'll get back the set messages in the currently-selected folder delivered since January 4th. (SENTSINCE 04-JAN-2011 will do the same thing, only based on the "Date" message header.)
Something along the lines of this:
folder.search(new ReceivedDateTerm(ComparisonTerm.GE, sinceDate));

how 2 use logmath twice in same form(sphinx4)

i have configured sphinx with netbeans and its wroking fine. but im using a button to do the process. but after it recognisers. i want to do the process again. but then it gives a error saying the "logmath instance is already present" and saying cannot open the microphone.
can someone give me a solution. what i want to do is use speech recogntion in several times in the same form. till it gives the correct answer.
please help me
this is the error i get
"Creating new instance of LogMath while another instance is already present
10:53:27.833 SEVERE microphone Can't open microphone line with format PCM_SIGNED 16000.0 Hz, 16 bit, mono, 2 bytes/frame, big-endian not supported."
you are using the Recognizer again and again each time you done the speech recognition.
make sure to "
//Get the spoken text
Result result = recognizer.recognize();
"
call this above result only one time. if you call again and again in the same event. it will give a error. so make it public to call only once and do the process. then it should work

Resources