Death12652
2010-05-11 09:39:13
So I have a script that creates randomly generated usernames. Then uses that username to sign up. Is there a way to log those usernames into some type of file like another scar or the debug or something like that?
2010-05-11 09:39:13
2010-05-11 09:40:11
2010-05-11 14:59:09
function RandStr(Len: Integer): string;
var
I, cLen: Integer;
Chars: string;
begin
Chars := 'abcdefghijklmnopqrstuvwxyz0123456789';
cLen := length(chars);
for i := 1 to Len do
if (Random(2) = 1) then
Result := Result + uppercase(Chars[Random(cLen) + 1])
else
Result := Result + Chars[Random(cLen) + 1];
end;
2010-05-11 18:41:17
procedure saveToFile(str: String);
var
theFile: Integer;
tempStr: String;
begin
if (FileExists(appPath + 'fileName.txt')) then
begin
theFile := OpenFile(appPath + 'fileName.txt', false); //will open the file if it exists
ReadFileString(theFile, tempStr, FileSize(theFile)); //copies the text that's already there
CloseFile(theFile);
end;
theFile := RewriteFile(appPath + 'fileName.txt', false) //will create a new file if it doesn't already exist
WriteFileString(theFile, tempStr + str + #10); //writes what was already there + str to file ~ the #10 will go to the next line
CloseFile(theFile);
end;
var
i: Integer;
begin
for i := 1 to 10 do
saveToFile(intToStr(i));
end.
This should work like you want it to. :)2010-05-11 23:45:00
2010-05-11 23:49:01
From: death12652
Thanks so much you helped a lot.
2010-05-12 20:22:07
1234567891012345678910123456789102010-05-12 22:16:24
From: death12652
Sorry I don't get how this works. It just keeps putting a FileNme.txt Which I get but All it does is put 1-10 on the first line and then does that over and over. I wanted it to put in there what my random name function put. Also it doesn't put it on a new line? just keeps putting it on the same line no spaces.
here I will show you what it looks like?123456789101234567891012345678910
over and over and over again.
function RandStr(Len: Integer): string;
var
I, cLen: Integer;
Chars: string;
begin
Chars := 'abcdefghijklmnopqrstuvwxyz0123456789';
cLen := length(chars);
for i := 1 to Len do
if (Random(2) = 1) then
Result := Result + uppercase(Chars[Random(cLen) + 1])
else
Result := Result + Chars[Random(cLen) + 1];
end;
procedure saveToFile(str: String);
var
theFile: Integer;
tempStr: String;
begin
if (FileExists(appPath + 'fileName.txt')) then
begin
theFile := OpenFile(appPath + 'fileName.txt', false); //will open the file if it exists
ReadFileString(theFile, tempStr, FileSize(theFile)); //copies the text that's already there
CloseFile(theFile);
end;
theFile := RewriteFile(appPath + 'fileName.txt', false) //will create a new file if it doesn't already exist
WriteFileString(theFile, tempStr + str + #13); //writes what was already there + str to file ~ the #13 will go to the next line
CloseFile(theFile);
end;
begin
saveToFile(RandStr(8));
end.
2010-05-13 00:06:15
2010-05-13 00:12:29
From: death12652
It Still Doesn't Save to a new line. Where are you going to get these numbers?
2010-05-13 00:46:01