Can anyone make sense of this?

This is a discussion on Can anyone make sense of this? within the C++ Programming forums, part of the General Programming Boards category; Resolved Function That works:
Code:
// Prints out per-line at speed of delay in milliseconds for "int lines" amount of ...

I was working on a function that would display a message on one line, then print it on the next line while erasing it on the previous line, and keep doing that until it had printed it on the "int lines" line. IE:

Thanks, I should have been more specific though, the only part I was confused about was the tabs erasing the text, not sure why that works. But thanks for pointing out the return true; -- originally it was a bool function but I was debugging it and needed to find out error codes so I went ahead and changed it.

However if you say the tabs erase it that makes more sense, I was wondering what exactly happens when I output the tabs on the line, because if I set 0 tabs in the function parameters and then I only put 1 tab per line it acts odd, but two seems to clear the line.

I'm worried I'm going to want to later on sometime scroll text behind pre-existing text so I don't want this to over-write the pre-exisiting text, though maybe I should just say tab is 4 spaces, (I think, I'll test it in a minute) and then say "strlen(Msg) / 4 = x amount of times I will tab" then maybe % to see if anything is left-over, and whatever is left over I just add a \0 to or something, hm...

Ah, so it's 8 not 4, ok. Printing spaces for the entire string length seems to be a better idea too, thanks

--Combining below post so I don't double post my bad :x

Hmm, this is what I have managed to come up with then. It should work perfectly fine with any length string and any amount of tabs and it only affects the text on the lines that have text being scrolled to, but not past the last character displayed in the string. It'd be cool to be able to not over-write what was on the left-side of the scrolling text that has been tab'd but I'm not sure if that's possible, any ideas?

Code:

// Prints out per-line at speed of delay in milliseconds for "int lines" amount of lines
bool ScrollText(char Msg[MAX_LENGTH], int lines, int delay, int tabs)
{
using namespace std;
string scroll = "\n";
CONSOLE_SCREEN_BUFFER_INFO consoleSBI;
// Get our cursor position
if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleSBI))
return false;
for (int i=0;i<lines;++i)
{
// Progress down another line and pause for int delay
scroll.append("\n");
Sleep(delay);
// Set our cursor position back to the original cursor position
if(!SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), consoleSBI.dwCursorPosition))
return false;
// Create a blank space per character in Msg on every line up to the current line
// Effectively "erasing" the trail by overwriting the characters
cout << "\n";
// Progress line-by-line
for (int k=i;k>0;--k)
{
cout << "\n";
// Display any tabs the user wishes to use
for (int n=tabs;n>0;--n)
cout << "\t";
// Overwrite the previous data to make it look invisible
for (int j=strlen(Msg);j>0;--j)
{
cout << " ";
}
}
// Set our cursor position back to the original cursor position
if(!SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), consoleSBI.dwCursorPosition))
return false;
// Display the message on the new line
cout << scroll;
for (k=tabs;k>0;--k)
cout << "\t";
cout << Msg;
}
// Clean out cout
cout.flush();
return true;
}

EDIT:

Wait I know, I could just modify the x value of the cursorposition and set that to be +8 per tab, making sure it starts at the leftmost side of the screen of course, and then I would ONLY over-write the text I wrote, yay!