- 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
Forums
Discussions
Discussions
Discussions
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
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2005 12:52 AM
12-08-2005 12:52 AM
Re: ENTER A STRING AND RETURN AN INT
Yeah well... where the heck is the VMS component in this question.
Suddenly the whole problem sounds like a middle school home work excercise.
Oh well,
Regards,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2005 06:27 AM
12-08-2005 06:27 AM
Re: ENTER A STRING AND RETURN AN INT
CONSHY» string="#F"
CONSHY» original_string="#F"
CONSHY» length=F$LENGTH(original_string)
CONSHY» if length.eq.1 then string=original_string+" "
CONSHY» if length.eq.2 string=original_string
%DCL-W-EXPSYN, invalid expression syntax - check operators and operands
CONSHY» if length.eq.2 then string=original_string
CONSHY» list="C C#D D#E F F#G G#A A#B "
CONSHY» integer_var=f$locate(string,list)/2
CONSHY» sh sym integer_var
INTEGER_VAR = 12 Hex = 0000000C Octal = 00000000014
CONSHY» if integer_var .eq. f$length(list)/2 then write sys$output "string error
on ",string
string error on #F
CONSHY»
Lawrence
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2005 06:34 AM
12-08-2005 06:34 AM
Re: ENTER A STRING AND RETURN AN INT
Let me do the honor that the previous posters omitted:
Welcome to the VMS forum.
And in case Hein is right (excuses when he and me are wrong!)
since you happened to trip on the worlds MOST stable, MOST secure (and regrettably, best kept-secret) OS, you are cordially invited to get some better aquaintance with it.
Be warned: the elegance, consistency, security, stability, & scalability of it, will forever ruin your positive view of any other OS!
Once again: Welcome.
Proost.
Have one on me.
jpe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2005 06:35 AM
12-08-2005 06:35 AM
Re: ENTER A STRING AND RETURN AN INT
Lawrence
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2005 08:34 AM
12-08-2005 08:34 AM
Re: ENTER A STRING AND RETURN AN INT
flats
C Db E Eb E...
double sharps
B+C#C+D#D+...
double flats
DbbDbEbbDbFb...
Upper casing might not be such a good idea if you use "b" for "flat".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2005 12:49 PM
12-08-2005 12:49 PM
Re: ENTER A STRING AND RETURN AN INT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2005 02:02 PM
12-08-2005 02:02 PM
Re: ENTER A STRING AND RETURN AN INT
To borrow some text from Jan...
from your Forum Profile:
I have assigned points to 0 of 13 responses to my questions.
Maybe you can find some time to do some assigning?
http://forums1.itrc.hp.com/service/forums/helptips.do?#33
It is fully up to _YOU_ to decide how many points you
assign. If you consider an answer is not deserving any
points, you can assign 0 points, and then that answer
will no longer be counted as unassigned.
Consider, that every poster took at least the trouble
of posting for you!
To easily find your streams with unassigned points,
click your own name somewhere, this will bring up your
profile. Near the bottom of that page, under the caption
"My Question(s)" you will find "questions or topics with
unassigned points", clicking that will give all, and
only, your questions that still have unassigned postings.
Thanks on behalf of your Forum colleagues.
PS. Nothing personal in this. Jan tries to post it to
everyone with this kind of assignment ratio in this forum.
If you have received a posting like this before, please do
not take offence, none is intended!
Proost.
Have one on Jan.
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2005 03:56 PM
12-08-2005 03:56 PM
Re: ENTER A STRING AND RETURN AN INT
This thread has a sign of "this question has at least one answer that has received a rating of 8 points or better" when Martin does not assign ponits to any of the answers.
Archunan
Archie