forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Integer to Character type casting

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Anonymous
Guest





PostPosted: Tue Jun 06, 2006 5:04 am    Post subject: Integer to Character type casting Reply with quote

Hello,

I am attempting to convert a set of integers into their equivalent characters and append these characters to the end of some other text:

mycharvar='text'//char(J)

where J is an integer. When I print this i get a small rectangle (looks like an end of line character) instead of the converted integer I want.
I find this a bit bizarre- can anyone help?

Thanks

DM
Back to top
brucebowler
Guest





PostPosted: Tue Jun 06, 2006 7:15 am    Post subject: Integer to Character type casting Reply with quote

char(1) is equivalent to "Ctrl/A", not "1". char(49 [31 hex]) is equivalent to "1"
Back to top
Anonymous
Guest





PostPosted: Tue Jun 06, 2006 8:30 am    Post subject: Integer to Character type casting Reply with quote

Thanks for the reply-

In that case, how do I convert

integer e.g. 1

to character e.g. '1'

DM
Back to top
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Tue Jun 06, 2006 9:50 am    Post subject: Integer to Character type casting Reply with quote

Add ICHAR('0') which is 48.

For J in the range 0 to 9 you can use


CHAR(ICHAR('0')+J)

Alternatively you can use an "internal" WRITE statement in which you write to a character variable.
Back to top
View user's profile Send private message AIM Address
Anonymous
Guest





PostPosted: Wed Jun 07, 2006 4:26 am    Post subject: Integer to Character type casting Reply with quote

Hello again,

Attempting to use internal write to resolve the problem:

CHARACTER*10 BUSY1,BUSY2
INTEGER VALUE,IO_STAT,T

T=1
WRITE (FMT=*,UNIT=BUSY1,IOSTAT=IO_STAT) T
WRITE (FMT=*,UNIT=BUSY2,IOSTAT=IO_STAT) UPTIME(T)
WRITE(2,*) 'TURBINE'//BUSY1, BUSY2

The output comes out blank after TURBINE is displayed.

Also, I understood that the only necessary parameter for internal write is the 'UNIT=Variable' part - when I remove the other parameters the compiler says:'You may not write to a file that is read-only'

In a similar vein, is it possible to format output of mixed type?
Back to top
JohnH



Joined: 26 Sep 2005
Posts: 13

PostPosted: Wed Jun 07, 2006 5:47 am    Post subject: Integer to Character type casting Reply with quote

After filling in the "missing" bits like the definition of UPTIME and specifying a format for the internal write statements, does the following help you?


PROGRAM INTERNAL_WRITE

CHARACTER*10 BUSY1,BUSY2,UPTIME(2)

INTEGER VALUE,IO_STAT,T

UPTIME(1)=' hello'

T=1
WRITE (FMT='(I10)',UNIT=BUSY1,IOSTAT=IO_STAT) T
WRITE (FMT='(A10)',UNIT=BUSY2,IOSTAT=IO_STAT) UPTIME(T)
WRITE(2,*) 'TURBINE'//BUSY1, BUSY2

STOP
END


which produces this output:-

TURBINE 1 hello

Smile
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Wed Jun 07, 2006 5:48 am    Post subject: Integer to Character type casting Reply with quote

The initial problem is that you need more than 10 characters for the first list-directed output (FMT=*).
Maybe you will need to use formatted output.
Back to top
View user's profile Send private message AIM Address
Anonymous
Guest





PostPosted: Wed Jun 07, 2006 7:10 am    Post subject: Integer to Character type casting Reply with quote

Problem solved, thank you so much for your help.
Back to top
Anonymous
Guest





PostPosted: Fri Jun 09, 2006 3:02 pm    Post subject: Integer to Character type casting Reply with quote

Try this...

mycharvar='text'//char(J+32)

Dan Rhea
Back to top
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group