IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Zen on January 22, 2006, 09:58:38 AM

Title: Bytes And Strings
Post by: Zen on January 22, 2006, 09:58:38 AM
Hi all. Im getting some grief with something im working on at the moment. I have an array of bytes and i want to perform certain things to these bytes then put them all back into a string. Getting them from a string to an array of bytes was a piece of cake but reversing it seemes to be somewhat difficult.

Can anyone help me out here?

Lewis
Title: Re: Bytes And Strings
Post by: Bruce Peaslee on January 22, 2006, 10:03:06 AM
It should be simple - what have you tried?
Title: Re: Bytes And Strings
Post by: Zen on January 22, 2006, 10:09:10 AM
well i want to be able to print the value of the variable sotred to the console screen so i can see whats in it, so that i can see if my code is right. Ive tried using...

string test;
test = test + byteArray
Title: Re: Bytes And Strings
Post by: Zen on January 22, 2006, 10:10:06 AM
hmm that byteArray should be byteArray[ x ] without the spaces, must the forum changing it.

Lewis
Title: Re: Bytes And Strings
Post by: Zen on January 22, 2006, 10:35:29 AM
Ok for some reason if you try to putput a byte on its own with writeln you get a compile error. If you put + "" after the variable name it works fine. Im not sure if this is intended or not. Just incase anyone was wondering.

Lewis
Title: Re: Bytes And Strings
Post by: Bruce Peaslee on January 22, 2006, 10:43:59 AM
That works. I guess WRITELN() expects a string. The compiler gives what I used to call a type mismatch.
Title: Re: Bytes And Strings
Post by: Zen on January 22, 2006, 10:46:50 AM
well i did have some problems with my code but i could not figure out where because i couldnt use writeln to putput my bytes. The code is fixed now that i figured out how to get writeln to work with bytes.

Lewis
Title: Re: Bytes And Strings
Post by: Bruce Peaslee on January 22, 2006, 11:18:53 AM
I couldn't leave the problem aloneÂÃ,  :-\

I previously bought the Aurora source code and took a look at WRITELN(). I came up with this to write one byte to the console:


// test of output of a single byte

const STD_OUTPUT_HANDLE = -11;

DECLARE IMPORT, WriteFile(
ÂÃ,  ÂÃ,  hFile AS INT,
ÂÃ,  ÂÃ,  lpBuffer AS POINTER,
ÂÃ,  ÂÃ,  nNumberOfBytesToWrite AS INT,
ÂÃ,  ÂÃ,  lpNumberOfBytesWritten AS INT BYREF,
ÂÃ,  ÂÃ,  lpOverlapped AS POINTER
ÂÃ,  ÂÃ,  ),INT;
DECLARE IMPORT, GetStdHandle(handle as INT),int;

global sub main(), int
{
ÂÃ,  ÂÃ,  byte b[10];
ÂÃ,  ÂÃ,  int i;

ÂÃ,  ÂÃ,  for (i=0; i<10; i++)
ÂÃ,  ÂÃ,  {
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  b[i] = chr$(i+65);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  WriteByte(b[i]);
ÂÃ,  ÂÃ,  }
ÂÃ,  ÂÃ,  while GetKey()="";
ÂÃ,  ÂÃ,  return 0;
}

sub WriteByte(byte out)
{
ÂÃ,  ÂÃ,  int iWritten;
ÂÃ,  ÂÃ,  hOut = GetStdHandle(STD_OUTPUT_HANDLE);
ÂÃ,  ÂÃ,  if hOut <> -1
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  WriteFile(hOut,out,1,iWritten,null);
return;
}



Thanks for the educational opportunity.

Title: Re: Bytes And Strings
Post by: Zen on January 22, 2006, 11:22:22 AM
Cool. Hopefully writeln will be fixed though to allow for outputting bytes.

Glad i could help you with you education bruce ;)

Lewis
Title: Re: Bytes And Strings
Post by: Ionic Wind Support Team on January 22, 2006, 12:34:07 PM
Writeln isn't broken.  It has one STRING parameter and expects a string variable.

You can use the function CHR$ from the string library if you want to output a single byte.

writeln(chr$(x));

Title: Re: Bytes And Strings
Post by: Bruce Peaslee on January 22, 2006, 12:43:12 PM
Quote from: Ionic Wizard on January 22, 2006, 12:34:07 PM
Writeln isn't broken.ÂÃ,  It has one STRING parameter and expects a string variable.

You can use the function CHR$ from the string library if you want to output a single byte.

writlen(chr$(x));



Not broken .. just not enhancedÂÃ,  ;)

I was sure I tried that construction when I was looking at the problem, but I guess not.ÂÃ,  ÂÃ, :-[
Title: Re: Bytes And Strings
Post by: Zen on January 22, 2006, 12:57:09 PM
For some reason i forgot all about ASC and CHR$. I both my recent problems this was the answer.

Lewis