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
byte and string question?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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:
PB - Registered PureBasic Coder
> 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$
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
Thanks Paul,
But how to get a$ into the original value message.l, that is my problem
Using Windows 98 SEPB - Registered PureBasic CoderCode: 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$
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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?
PB - Registered PureBasic Coder
> 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
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by cor.
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
Using Windows 98 SE> 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
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by cor.
Paul,
Thanks for your quick response, it works jippieeeeee
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
Paul,
Thanks for your quick response, it works jippieeeeee
Using Windows 98 SE> 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
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com