maybe a stupid question,but...

Cableguy

Expert
Licensed User
Longtime User
Hi,

Maybe is because I haven't been using b4ppc for the past 2 weeks or so but, how do I reference a string variable in this case?

file1="myfile.txt"
file2="second.png"
file.........
file20="lastfile.doc"
for x = 1 to 20
if file exist(???)=false then message the user......
Next x

How do I reference the file & x in this case?

I've tryed If fileexist(file & x) but it doesn't compute....
 

Cableguy

Expert
Licensed User
Longtime User
OK I've got it to work..using an array, as I problably should have done to start of..But at the end of the for next loop i keep getting a " out of boudaries" error...

Here's the entire code...

B4X:
Sub Globals
dim file(6)
End Sub

Sub App_Start
   Main.Show
   CheckFiles
   SIP(False)
End Sub

Sub CheckFiles
File(0)="Pairs v2.ini"
File(1)="1.png"
File(2)="2.png"
File(3)="3.png"
File(4)="4.png"
File(5)="5.png"
For x = 0 to arraylen(File())
   If FileExist(File(x))= true Then
      MsgBox(File(x))
   else
      Msgbox(file(x) & " is missing")
   end if
Next x 
End sub


EDIT:

I found my error...forgot to ad the "-1" in the "for x = 0 to arraylen(file())" line...

As i said, This could and was a "stupid" question....:sign0013::sign0137:

BTW: I plan to use these subs to check the integrety of my app, so that if some file is missing, the app will not run at all...Not a piracy protection but more of a "error free" thing...I also plan to generate a log if the app does not start to list the missing file... this way will be easyer to debug.
 
Last edited:

specci48

Well-Known Member
Licensed User
Longtime User
Hi Cableguy,

the length of the file array is 6 because there are 6 entries.
To access all of them your loop should go form zero to 5

B4X:
For x = 0 to arraylen(File()) - 1


specci48


Sorry but I just missed your own correction...
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I've tryed If fileexist(file & x) but it doesn't compute....

Sorry mate but I wasn't around earlier other wise I would have said that you probably needed to enclose the word file with quotation marks.

If fileexist("file" & x)

But I see that you and Specci48 have sorted it now ;)

Regards,
RandomCoder
 

Rioven

Active Member
Licensed User
Longtime User
Hi Guys! since I'm still learning...can we use imagelist.Item(i)="1.jpg" ?
 

Rioven

Active Member
Licensed User
Longtime User
sorry guys, i'm off topic here, this is can only be use for images...
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
can we use imagelist.Item(i)="1.jpg"

You can indeed use the above statement.

Regards,
RandomCoder
 

Peter

Member
Licensed User
There are no stupid questions, CableGuy, only stupid persons :D (who fail to ask questions)
 
Top