Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing letters
#11
Well. I do understand you toonski with the mod and stuff but i have absolutly no idea about peek, poke, and sadd. I'll get into that later, but thanks all of you for helping.

and the new version of my 2nd code is up^ there

now to find some other project :humm:
Reply
#12
well, to break down the peek/poke/varseg/sadd method:

a string, like it infers, is a string of bytes. each character in a string is 1 byte (value - 0 to 255). now those strings are stored at an address segment, and an offset. actually, it's just memory (which qb allocates for strings), but each address segment is a marker of 16 bytes, and each offset can go from zero to 65536. think of it like a football field, where you have markers for 10 yards and individual yards. so in essence you get access to a span of 1,048,576 in which your 640k of dos memory is stored, your bios (dont mess with it), your video memory, your text screen buffer, etc, essentially all the near memory you can play with without going to ems, xms or protected mode.

got it? great. now forget everything i just said, that's just background info ramble. pretty much, every variable in qb has a segment and an offset that you can mess with directly. to access these, you use:

def seg = segment
poke offset, byte_value
byte_value = peek (offset)

to find the segment and address of a qb variable, you say:

segment = varseg(variable)

and to find the offset (of the first point):

offset = varptr (numeric_variable)
offset = sadd(string_variable$)

so let's say i want to edit the first character of a string:

$mystring = "b guy walks into a bar"
def seg = varseg(mystring$)
poke sadd(mystring$) + 0, asc("A") 'zero is the character position - 1
print mystring$

should print, since you changed the first character to "A", "A guy walks into a bar"

to edit the second character, change the zero to 1, to edit the third, 2, etc.

to sum it up, this just pokes directly into your memory instead of using qb's string statements. i hope i didnt confuse you by all that :lol:
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#13
never mind Smile it was just another possible way to do it lol
Reply
#14
Well I don't think I'm going to get into peek and stuff for a while so i made a very user friendly version of the encoder and decoder which changes "aaaaaaaaaa" into "bcdefghijk" and asks you if you want it decoded so here
Code:
start: CLS
INPUT "Encode or decode"; f$
g = 0
CLS
INPUT "Input sentence"; a$
code: CLS
PRINT a$
FOR letter = 1 TO LEN(a$)
IF f$ = "decode" THEN number = (26 - (letter MOD 26))
IF f$ = "encode" THEN number = (letter MOD 26)
b = ASC(MID$(a$, letter, 1))
SELECT CASE b
    CASE 65 TO 90
        b = (((b - 65) + number) MOD 26) + 65
    CASE 97 TO 122
        b = (((b - 97) + number) MOD 26) + 97
END SELECT
MID$(a$, letter, 1) = CHR$(b)
NEXT letter
PRINT a$
PRINT
IF f$ = "encode" THEN INPUT "Do you want to decode? y / n "; f$
IF f$ = "y" THEN
    f$ = "decode"
    GOTO code
END IF
PRINT
INPUT "Again? y / n "; f$
IF f$ = "y" THEN GOTO start
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)