- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Re: ENTER A STRING AND RETURN AN INT
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2005 10:34 AM
тАО12-07-2005 10:34 AM
ENTER A STRING AND RETURN AN INT
1.- "C"
2.- "C#"
3.- "D"
4.- "D#"
5.- "E"
6.- "F"
7.- "F#"
8.- "G"
9.- "G#"
10.- "A"
11.- "A#"
12.- "B"
And return a number for each one:
if it is "C" returns 0.
If it is "C#" returns 1.
If it is "D" returns 2.
and so on...
Could you help me?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2005 11:51 AM
тАО12-07-2005 11:51 AM
Re: ENTER A STRING AND RETURN AN INT
if you want it to be done inside DCL,
You can use f$element lexical function
I have pasted one example of using f$element lexical ...., you can go thru this and modify as per your rek.
months="JAN/FEB/MAR/APR/MAY/JUN/JUL/AUG/SEP/OCT/NOV/DEC"
$ i=0
$LOOP:
$ IF F$ELEMENT(I, months) .EQS. mm THEN GOTO ENDLOOP
$ IF I .LE. 11 THEN
$ I = I+1
$ GOTO LOOP
$ ELSE
$ WRITE SYS$OUTPUT "Invalid month"
$ GOTO ENDLOOP
$ ENDIF
$ ENDLOOP
Archunan
Archie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2005 11:56 AM
тАО12-07-2005 11:56 AM
Re: ENTER A STRING AND RETURN AN INT
If you make all the list strings the same number of characters you can use lexical F$LOCATE.
length=F$LENGTH(original_string)
IF length .eq. 1
THEN
string=original_string+" "
ELSE
string=original_string
ENDIF
list="C C#D D#E F F# G G# A A#B "
integer_var=f$locate(string,list)/2)
Lawrence
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2005 12:04 PM
тАО12-07-2005 12:04 PM
Re: ENTER A STRING AND RETURN AN INT
$!
$ If integer_var .eq. 24
$ THEN
$! Process error
.
.
.
$ ENDIF
Lawrence
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2005 12:39 PM
тАО12-07-2005 12:39 PM
Re: ENTER A STRING AND RETURN AN INT
You may get more relevant responses if you specify
what platform you are using and what language you
are trying to use...
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2005 02:54 PM
тАО12-07-2005 02:54 PM
Re: ENTER A STRING AND RETURN AN INT
----------- keys.com -----------
$ keys = ",C ,C#,D ,D#,E ,F ,F#,G ,G#,A ,A#,B "
$ if p1.eqs."" then exit
$ key = f$loc(","+p1, keys)/3
$ if key .lt. 12
$ then write sys$output "key ''p1' = ''key'"
$ else write sys$output "key ''p1' is invalid"
$endif
----- keys.p ----------
%keys = qw (C 0 C# 1 D 2 D# 3 E 4 F 5 F# 6 G 7 G# 8 A 9 A# 10 B 11);
# foreach (keys %keys) { print $i++, " $_ $keys{$_}\n"};
$key_name = uc (shift @ARGV);
$key = $keys{$key_name};
if (defined $key) {
print "key $key_name = $key\n";
} else {
print "key $key_name = invalid\n";
}
Solution example with DCL:
$ @keys c
key C = 0
$ @keys D#
key D# = 3
$ @tmp x
key X is invalid
Solution example with PERL
$ perl keys.p A#
key A# = 10
$ perl keys.p d
key D = 2
$ perl keys.p x
key X = invalid
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2005 03:09 PM
тАО12-07-2005 03:09 PM
Re: ENTER A STRING AND RETURN AN INT
btw Lawrence was on a right track (imho), again I prefer to calculate rather then decide. For example:
$original_string = p1
$string = f$extr(0,2, original_string+" ")
$list = "C C#D D#E F F# G G# A A#B "
$integer_var=f$locate(string,list)/2
$show symb integer_var
of course this solution suffers from 'false positive's.
Looking for a bad string like #E will result in the value for D#.
The pre and/or post-pending of a known string will solve that. For further robustness add an F$EDIT with UPCASE and/or TRIM
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2005 10:54 PM
тАО12-07-2005 10:54 PM
Re: ENTER A STRING AND RETURN AN INT
I am using C.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2005 11:39 PM
тАО12-07-2005 11:39 PM
Re: ENTER A STRING AND RETURN AN INT
Have a look at the C-function "strstr" or the RTL STR$POSITION.
Regards,
Kris (aka Qkcl)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-08-2005 12:44 AM
тАО12-08-2005 12:44 AM
Re: ENTER A STRING AND RETURN AN INT
everyone was still assuming that he wanted a
DCL solution. Then DS spoiled everything.