Type-Converting

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Leonhard
User
User
Posts: 55
Joined: Fri Jun 16, 2006 7:43 am

Type-Converting

Post by Leonhard »

Wouldn't it be nice to convert types in a line with .type (.i, .c, .q, ...)?

Example:

Code: Select all

Declare var1.i
Declare var2.i

Declare result.i

result = ( (var1).f / (var2).f ).i

; --------------------------------------

Declare str1.s{12} = "Hallo, Welt!"
Declare char.c

char = (str1).c + SizeOf(Character) * 7

Debug (char).s{1}
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I use simple procedures. Following your code it would be:

Code: Select all

Procedure.f iTof(a.i)
  ProcedureReturn a
EndProcedure

var1.i 
var2.i 

result.i=(iTof(var1)/iTof(var2))

; --------------------

Procedure.c sToc(a$)
  ProcedureReturn PeekC(@a$)
EndProcedure
Procedure$ cTos(a.c,l.l=0)
  If l:ProcedureReturn PeekS(@a,l)
  Else:ProcedureReturn PeekS(@a)
  EndIf
EndProcedure

str1.s{12}="Hallo, Welt!" 
char.c=sToc(str1)+SizeOf(Character)*7
Debug cTos(char,1)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Same here, using a procedure...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Didn't notice this when I suggested...

http://www.purebasic.fr/english/viewtopic.php?t=34265
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply