Page 1 of 1
Posted: Sat Jul 13, 2002 10:03 pm
by BackupUser
Restored from previous forum. Originally posted by cor.
I have the following values:
tmp.s="30"
message.l= $007f2890
How could I easily replace the value 28 in the 'message' with the value 30 from 'tmp' string
Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
Posted: Sat Jul 13, 2002 10:16 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> tmp.s="30"
> message.l= $007f2890
>
> How could I easily replace the value 28 in the 'message' with the value 30
> from 'tmp' string
It depends on several things:
(1) Is message.l always going to be a six-character number (ie, the last six
characters "7f2890"), or will the first two zeros sometimes have numbers?
(2) Does the position of the digits to be swapped changed, or is it only the
two digits currently in the "28" position changing?
Anyway, this works for your specific example above:
Code: Select all
tmp.s="30"
message.l=$007f2890
a$="$00"+Hex(message) ; Create a 9-character string based on message.l
a$=Left(a$,5)+tmp+Right(a$,2) ; Replace positions 6 and 7 with tmp
Debug a$
PB - Registered PureBasic Coder
Posted: Sat Jul 13, 2002 10:26 pm
by BackupUser
Restored from previous forum. Originally posted by cor.
Thanks Paul,
But how to get a$ into the original value message.l, that is my problem
Code: Select all
tmp.s="30"
message.l=$007f2890
a$="$00"+Hex(message) ; Create a 9-character string based on message.l
a$=Left(a$,5)+tmp+Right(a$,2) ; Replace positions 6 and 7 with tmp
Debug a$
PB - Registered PureBasic Coder
Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
Posted: Sat Jul 13, 2002 11:00 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> But how to get a$ into the original value message.l, that is my problem
Do you mean like this?
Code: Select all
Procedure.l hex2dec(h$)
; h$ can be 0-FFFFFFF.
h$=UCase(h$)
For r=1 To Len(h$)
d60
d+Asc(a$)-55
Else
d+Asc(a$)-48
EndIf
Next
ProcedureReturn d
EndProcedure
;
tmp.s="30"
message.l=$007f2890
Debug "Old = "+Str(message)
a$="$00"+Hex(message)
message=hex2dec(Left(a$,5)+tmp+Right(a$,2))
Debug "New = "+Str(message)
PB - Registered PureBasic Coder
Posted: Sat Jul 13, 2002 11:39 pm
by BackupUser
Restored from previous forum. Originally posted by cor.
> But how to get a$ into the original value message.l, that is my problem
Do you mean like this?
Code: Select all
Procedure.l hex2dec(h$)
; h$ can be 0-FFFFFFF.
h$=UCase(h$)
For r=1 To Len(h$)
d60
d+Asc(a$)-55
Else
d+Asc(a$)-48
EndIf
Next
ProcedureReturn d
EndProcedure
;
tmp.s="30"
message.l=$007f2890
Debug "Old = "+Str(message)
a$="$00"+Hex(message)
message=hex2dec(Left(a$,5)+tmp+Right(a$,2))
Debug "New = "+Str(message)
PB - Registered PureBasic Coder
Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
Posted: Sat Jul 13, 2002 11:40 pm
by BackupUser
Restored from previous forum. Originally posted by cor.
Paul,
Thanks for your quick response, it works jippieeeeee
> But how to get a$ into the original value message.l, that is my problem
Do you mean like this?
Code: Select all
Procedure.l hex2dec(h$)
; h$ can be 0-FFFFFFF.
h$=UCase(h$)
For r=1 To Len(h$)
d60
d+Asc(a$)-55
Else
d+Asc(a$)-48
EndIf
Next
ProcedureReturn d
EndProcedure
;
tmp.s="30"
message.l=$007f2890
Debug "Old = "+Str(message)
a$="$00"+Hex(message)
message=hex2dec(Left(a$,5)+tmp+Right(a$,2))
Debug "New = "+Str(message)
PB - Registered PureBasic Coder
Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com