Filling string array question

basil99

Active Member
Licensed User
Longtime User
Hi and please help with this problem

1) I have several text files, each one is containing a known number of strings

2) I declare some arrays as

Dim Elements1 as int: Elements1 = value1
Dim MyStringArray1( Elements1 ) As String

Dim Elements2 as int: Elements2 = value2
Dim MyStringArray2( Elements2 ) As String

......


Dim ElementsN as int: ElementsN = valueN
Dim MyStringArrayN( ElementsN ) As String


3) I want to have a single sub for reading text files and filling the corresponding string array. So i tried this and this don't work:

B4X:
Sub UniversalReader( MyArray() As String, Myfile as String)

   Dim counter As Int
   counter = 0

   Dim TextReader1 As TextReader

   TextReader1.Initialize( File.OpenInput( File.DirAssets, MyFile ) )
   Dim line As String    

   line = TextReader1.ReadLine     
   MyArray( counter ) = line
   counter = counter + 1

   Do While line <> Null        

      line = TextReader1.ReadLine    
      MyArray( counter ) = line
      counter = counter + 1

   Loop    
   TextReader1.Close


End Sub

When I try to use this SUB

UniversalReader( MenuImages(), "menu.txt" )
I got the compiler error:

Error compiling program.
Error description: Missing parameter.
Occurred on line: 646
UniversalReader( MenuImages(), "menu.txt" )
Word: (


What I'm doing wrong ?
 

basil99

Active Member
Licensed User
Longtime User

Okay, well, how i can get MenuImages() Array if i read "menu.txt" into Mylist ? Really, don't understand (
 
Upvote 0

basil99

Active Member
Licensed User
Longtime User
Can't you work with a list instead of an array?

Well, actually just familiar with arrays rather then lists )
Problem is easy. I have a txt file like that:

background.jpg
background.-front.jpg
tile1.png

etc

I need to load it into smth, so later i can walk over and load this image files as bitmaps within GameView :

B4X:
MenuButtons( i ).Bitmap = LoadBitmap( File.DirAssets, MenuImages( i ) )

TextReader was used to get MenuImages( i ) form menu.txt, so if Lists, how to do the same ?

Thank you
 
Upvote 0

basil99

Active Member
Licensed User
Longtime User
B4X:
MenuButtons( i ).Bitmap = LoadBitmap( File.DirAssets, MenuImages.Get(i) )

looks cool, but what is MenuImages.Get(i) ? ) One of the member function of List, correct ?

and gathering it all together one can get this code


B4X:
MenuImages = UniversalReader( "menu.txt" )
for i = 1 to MenuItems - 1
MenuButtons( i ).Bitmap = LoadBitmap( File.DirAssets, MenuImages.Get(i) )
next 


Sub UniversalReader(Myfile as String) As List 

   Return File.ReadList(File.DirAssets, MyFile)

End Sub

right ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…