May 01, 2024, 01:46:01 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


problem with OPENFILE ??

Started by ExMember001, November 15, 2006, 12:22:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ExMember001

i'm getting wrong number of parameters on the openfile line...
well, maybe i'm too tire because i dont see anything wrong ;)


AmpKC::SavePlaylist()
{
int count = PlaylistV->GetCount();
int t;
if count > 0
{
for(t = 0 ; t < count-1 ; t++)
{
string PlaylistFilename = FILEREQUEST("OÃÆ'Ã,¹ Voulez-vous sauvegarder votre playlist?",0, 0,"Fichier Playlist (*.m3u)|*.m3u||");
        if PlaylistFilename <> ""
        {
    string Filen = PlaylistV->GetItemText(t,0);
    string fpath = PlaylistV->GetItemText(t,1);
    UNSIGNED INT PlaylistFile = OPENFILE(PlaylistFilename, MODE_CREATE | MODE_APPEND);
if PlaylistFile <> 0
{
WRITE(PlaylistFile, fpath+Filen, len(fpath+Filen));
}
    closefile(PlaylistFile);
}
}
}
return;
}

John Syl.

Hi Krypt,

works ok for me.

To test I declared classes and methods that you use and it compiled fine.

here is the code:

class AmpKC
{
declare SavePlayList();
}

Class CPlayListV
{
Declare GetCount(),int;
Declare GetItemText(int t,int n),STRING;
}

CPLayListV::GetCount(),INT
{
int n;
return n;
}

CPLayListV::GetItemText(int t, int n),string
{
string str;
return str;
}


CPlayListV *PlayListV;

AmpKC::SavePlaylist()
{
int count = PlaylistV->GetCount();
int t;
if count > 0
{
for(t = 0 ; t < count-1 ; t++)
{
string PlaylistFilename = FILEREQUEST("OÃÆ'Ã,¹ Voulez-vous sauvegarder votre playlist?",0, 0,"Fichier Playlist (*.m3u)|*.m3u||");
        if PlaylistFilename <> ""
        {
    string Filen = PlaylistV->GetItemText(t,0);
    string fpath = PlaylistV->GetItemText(t,1);
    UNSIGNED INT PlaylistFile = OPENFILE(PlaylistFilename, MODE_CREATE | MODE_APPEND);
if PlaylistFile <> 0
{
WRITE(PlaylistFile, fpath+Filen, len(fpath+Filen));
}
    closefile(PlaylistFile);
}
}
}
return;
}

sub main()
{
return;

}


maybe the problem is further back than you think.

regards
John
Intel 3.6 p4 ht, XP home,2 gb mem, 400 gb hd 20gb raid 0, Nvidia 6600le.
AMD k6-2 500, 40gb.

Started on PDP11 Assembler, BASIC, GWBASIC, 6502, Z80, 80x86, Java, Pascal, C, C++, 
IBasic (std & pro), Aurora, EBasic.  (Master of none, but it's been fun!)

ExMember001

humm... thanx john ;)

if i comment the above part the program compile but if i uncomment i still get the error...

ExMember001

here is the source, its a bass 2.3 Audio Player that support bass formats addons ;)
not much for the moment...

the compiled exe was compiled with the saveplaylist method commented...
in the source code the method is not commented.

J B Wood (Zumwalt)

Open file = 1, save = 0, anyway, I tried to write up something fast, but... My while statement doesn't loop for some odd reason and no error.


declare cdecl import, debug alias OutputDebugStringA(string str);
global sub main()
{
unsigned int fResult=0;
string Filter = "Text files|*.txt|All Files|*.*||";
int posf=0;
fResult=0;
#break;
string filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
posf = instr(filename,"|");
pointer p1 = filename;
int i=0;
string myList[10];
while (posf)
{
filename[posf-1] = null;
filetemp = *(string)p1;
filename[posf-1] = 32;
p1 = &filename+posf;
myList[i]=filetemp;
posf = instr(filename,"|",posf+1);
debug(myList[i]);
i=i+1;
}
}

John Syl.

HI Krypt,

found your problem, you have redefined Openfile() in the AmpKC class, therefore this is where it is looking.


regards
John
Intel 3.6 p4 ht, XP home,2 gb mem, 400 gb hd 20gb raid 0, Nvidia 6600le.
AMD k6-2 500, 40gb.

Started on PDP11 Assembler, BASIC, GWBASIC, 6502, Z80, 80x86, Java, Pascal, C, C++, 
IBasic (std & pro), Aurora, EBasic.  (Master of none, but it's been fun!)

ExMember001

November 15, 2006, 02:43:21 PM #6 Last Edit: November 15, 2006, 02:46:22 PM by KrYpT
hehe your right ;)
thanx John !

John Syl.

No problem, it's easy to do.  Get fixed on a train of thought and you ignore all else.
Still finding these probs is what makes it it fun!! ;D
Intel 3.6 p4 ht, XP home,2 gb mem, 400 gb hd 20gb raid 0, Nvidia 6600le.
AMD k6-2 500, 40gb.

Started on PDP11 Assembler, BASIC, GWBASIC, 6502, Z80, 80x86, Java, Pascal, C, C++, 
IBasic (std & pro), Aurora, EBasic.  (Master of none, but it's been fun!)

J B Wood (Zumwalt)

lol, glad you two figured it out, I never got my code to loop again.

Ionic Wind Support Team

Aurora supports scope resolution.  If you have a class member that is named the same as an external function, or import, you can tell Aurora which one to use.  For example if you have a class named CFile and that class has a method named OpenFile you have to specify which function to call.

CFile::OpenFile(string name, int mode),int
{
      m_hFile = ::OpenFile(name,mode);
      return (m_hFile != NULL);
}

The :: prepended to an identifier instructs the compiler to not resolve to class scope.  If you did not have that then the method would be stuck in an endless loop as it would call itself.

Ionic Wind Support Team

ExMember001

interresting, thanx Paul :)
i didnt know that!

J B Wood (Zumwalt)

This is the only way I could get it to work.

declare cdecl import, debug alias OutputDebugStringA(string str);
global sub main()
{
unsigned int fResult=0;
string Filter = "Text files|*.txt|All Files|*.*||";
int posf=0;
fResult=0;
#break;
string filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
posf = instr(filename,"|");
pointer p1 = filename;
int i=0;
string myList[10];
int isvalid=1;
while (isvalid)
{
filename[posf-1] = null;
filetemp = *(string)p1;
filename[posf-1] = 32;
p1 = &filename+posf;
myList[i]=filetemp;
posf = instr(filename,"|",posf+1);
debug(myList[i]);
if (myList[i]=="")
{
isvalid=0;
}
else
{
i=i+1;
}
}
}


I took Pauls example from the help system and modified it a bit, the example would never show a debug of more than 1 file.
This alteration of the example shows all of the files in debug.
Paul, you might want to snag this code and compile in debug and step through it, there is some interesting step over going on.

J B Wood (Zumwalt)

Can anyone explain this behavior?

declare cdecl import, debug alias OutputDebugStringA(string str);
global sub main()
{
unsigned int fResult=0;
string Filter = "Text files|*.txt|All Files|*.*||";
int posf=0;
fResult=0;
#break;
string filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
posf = instr(filename,"|");
pointer p1 = filename;
int i=0;
string myList[10];
for (int clean=0;clean<10;clean++)
{
myList[clean]="";
}
int isvalid=1;
int msg=0;
string tmpStr="";

while (isvalid)
{
filename[posf-1] = null;
filetemp = *(string)p1;
filename[posf-1] = 32;
p1 = &filename+posf;
tmpStr=TRIMRIGHT(filetemp);

if (tmpStr != "")
{
myList[i]=filetemp;
posf = instr(filename,"|",posf+1);
debug(myList[i]);
i++;
}
else
{
isvalid=0;
}
}

for (int k=0;k<10;k++)
{
tmpStr=TRIMRIGHT(myList[k]);
if (tmpStr == "")
{
k=10;
}
else
{
msg=MessageBox(NULL,myList[k],"Current File",MB_OK);
}
}
}


I can at most get 3 files to show in messagebox result.
If I select more than 3, I get :

AppName: fileexample.exe    AppVer: 0.0.0.0    ModName: unknown
ModVer: 0.0.0.0    Offset: 445c3a43

Now, I know what you might say, which is to increase the string length.
filename[posf-1] = 32;

I tried to modify that and didn't make any difference, I changed it to upwards around 1024 to see if that helped, but still the same problem.
What am I missing?

Ionic Wind Support Team

>>>>string filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);

A string type is only 255 characters long.  The maximum path length in windows is 260 characters.  So you need a bigger buffer.

dstring filename[260 * 100]; //allow up to 100 files to be selected
filename = FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);

Better yet allocate the buffer with NEW.
Ionic Wind Support Team

J B Wood (Zumwalt)

How do you mean use NEW?
Sorry, I don't typically work with buffers.
NEW doesn't work on variables I thought.
The above mentioned changed in my code doesn't work for 10 files, so I will look it over tonight to see if I can comprehend this.

Ionic Wind Support Team

NEW allocates memory.  It returns a pointer to that memory.  It doesn't care what the memory is used for. 

string *buffer = new(byte, 10000);  //a 10K string

*buffer = "hello";
*buffer = FileRequest....

etc.

The change I gave you was just because you would be overwritting the buffer after 255 characters and it was the most glaring error.  I haven't looked at the rest of your code, you may have other errors.

Ionic Wind Support Team

Ionic Wind Support Team

Is this what you're looking for?  Simplified it a bit.


declare import,ZeroMemory alias RtlZeroMemory(void *mem,int count),int;
global sub main()
{
openconsole();
unsigned int fResult=0;
string Filter = "Text files|*.txt|All Files|*.*||";
dstring filename[260*10]=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
int posf = instr(filename,"|");
pointer p1 = filename;
int i=0;
string myList[10];
ZeroMemory(mylist,10*255);
int isvalid = (posf != 0);
int msg=0;
string tmpStr="";

while (isvalid)
{
filename[posf-1] = null;
filetemp = *(string)p1;
filename[posf-1] = 32;
p1 = &filename+posf;
if (filetemp != "")
{
myList[i]=filetemp;
posf = instr(filename,"|",posf+1);
print(myList[i]);
if(i < 9) i++ else break;
}
else
{
isvalid=false;
}
}

for (int k=0;k<10;k++)
{
if (myList[k] == "")
{
k=10;
}
else
{
msg=MessageBox(NULL,myList[k],"Current File",MB_OK);
}
}
while GetKey() = "";
}
Ionic Wind Support Team

Ionic Wind Support Team

And this one shows the same code allocating the buffer with NEW


declare import,ZeroMemory alias RtlZeroMemory(void *mem,int count),int;
global sub main()
{
openconsole();
unsigned int fResult=0;
string Filter = "Text files|*.txt|All Files|*.*||";
string *filename = new(byte,260*100);
*filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
int posf = instr(*filename,"|");
pointer p1 = filename;
int i=0;
string myList[10];
ZeroMemory(mylist,10*255);
int isvalid = (posf != 0);
int msg=0;
string tmpStr="";

while (isvalid)
{
*filename[posf-1] = null;
filetemp = *(string)p1;
*filename[posf-1] = 32;
p1 = filename+posf;
if (filetemp != "")
{
myList[i]=filetemp;
posf = instr(*filename,"|",posf+1);
print(myList[i]);
if(i < 9) i++ else break;
}
else
{
isvalid=false;
}
}

for (int k=0;k<10;k++)
{
if (myList[k] == "")
{
k=10;
}
else
{
msg=MessageBox(NULL,myList[k],"Current File",MB_OK);
}
}
delete filename;
while GetKey() = "";
}
Ionic Wind Support Team

Ionic Wind Support Team

And since I am an advocate of simplifcation.  This final example of your code uses a CStringList to store the filenames and allows selecting up to a 100 files.


global sub main()
{
OpenConsole();
string Filter = "Text files|*.txt|All Files|*.*||";
//select up to 100 files.
string *filename = new(byte,260*100);
*filename=FILEREQUEST("Get Files",0,1,Filter,"",OFN_ALLOWMULTISELECT);
int posf = StrFind(*filename,"|");
string *p1 = filename;
CStringList myList;
myList.Create();

while (posf)
{
*filename[posf-1] = NULL;
filetemp = *p1;
*filename[posf-1] = ' ';
p1 = filename+posf;
if (filetemp[0] != NULL)
{
myList.Add(filetemp);
posf = StrFind(*filename,"|",posf+1);
print(filetemp);

}
else
break;
}
int count = 0;
for (pointer k=myList.GetFirst(); k; k = myList.GetNext(k))
{
MessageBox(NULL,myList.GetData(k),"Current File",MB_OK);
count++;
}
print("You Selected: ",count," file(s)");
delete filename;
myList.RemoveAll(true);
while GetKey() = "";
}
Ionic Wind Support Team

Kale

November 16, 2006, 04:58:51 PM #19 Last Edit: November 16, 2006, 05:02:40 PM by Kale
It's just occured to me that instead of doing this:


for (pointer k=myList.GetFirst(); k; k = myList.GetNext(k))
{
    MessageBox(NULL,myList.GetData(k),"Current File",MB_OK);
    count++;
}


it would be nice to do something along these lines:


foreach(myList, myItem)
{
    MessageBox(NULL,myList.GetData(myItem),"Current File",MB_OK);
    count++;
}


or


foreach(*myList, *myItem)
{
    MessageBox(NULL,myList->GetData(*myItem),"Current File",MB_OK);
    count++;
}


any chance of that? ;D

ExMember001

Quote from: Kale on November 16, 2006, 04:58:51 PM
It's just occured to me that instead of doing this:


for (pointer k=myList.GetFirst(); k; k = myList.GetNext(k))
{
    MessageBox(NULL,myList.GetData(k),"Current File",MB_OK);
    count++;
}


it would be nice to do something along these lines:


foreach(myList, myItem)
{
    MessageBox(NULL,myList.GetData(myItem),"Current File",MB_OK);
    count++;
}


or


foreach(*myList, *myItem)
{
    MessageBox(NULL,myList->GetData(*myItem),"Current File",MB_OK);
    count++;
}


any chance of that? ;D

In term of Simplification i think it's a good one ;)

Steven Picard

I agree with you guys.  That looks like nice, simple syntax. :)

Ionic Wind Support Team

Except it wouldn't work with OOP list classes,  'foreach' is a BASIC keyword anyway and I am not going to overly alter the syntax of Aurora before the 1.0 release. 

The FOR statement was used here as an example, because FOR in Aurora is much more than a counter.  You can also use other methods such as a WHILE loop, or even a dynamic array class, and it wasn't even related to the original problem ;)

Ionic Wind Support Team

Kale

Quote from: Paul Turley on November 16, 2006, 09:35:09 PM
Except it wouldn't work with OOP list classes,  'foreach' is a BASIC keyword anyway and I am not going to overly alter the syntax of Aurora before the 1.0 release. 
The FOR statement was used here as an example, because FOR in Aurora is much more than a counter.  You can also use other methods such as a WHILE loop, or even a dynamic array class, and it wasn't even related to the original problem ;)

Yeah it was a bit off topic ;) but i was just thinking about simplifying iterating through linked lists. ;D

J B Wood (Zumwalt)

What I was asking was related to the original problem in an indirect way, it had to do with the Method that was being used.
I'll start a new thread next time then if you want, even if it relates to the same method.
All I was trying to do was take the docs example and elaborate to show how to fix his original problem, and ran into a problem of my own, and didn't think I should have started a new thread.

A string value in Windows ironiaclly is 2 gig in size not 255 characters. 255 characters is a limitation for Aurora, and rightly so, because a string at 255 is optimized, a string in Microsoft .Net for example is an array of unicode characters, this array is dynically created. A string as I understand it in Aurora is a fixed length of unicode characters at 255. That was my first understanding when reading this topic that we are working on.

What I did not know for sure until now, is that Aurora had a fixed length for a string, now I know.
Sorry for confusing the topic.