Select Case in a ListView

ciginfo

Well-Known Member
Licensed User
Longtime User
Hello
Why it does not work?

Sub ListView1_ItemClick (Position As Int, Value As Object)
Dim i As Int
Dim TexteBebe, TexteBaby(12) As String
TexteBaby(0) = "bebe_1mois.txt"
TexteBaby(1) = "bebe_5sem.txt"
TexteBaby(2) = "bebe_6sem.txt"
TexteBaby(3) = "bebe_7sem.txt"
TexteBaby(4) = "bebe_8sem.txt"
TexteBaby(5) = "bebe_9sem.txt"
TexteBaby(6) = "bebe_10sem.txt"

Select Position
For Case i = 0 To 6
TexteBebe = File.ReadString(File.DirAssets, TexteBaby(i))
LblBebe.Text = TexteBebe
Next
End Select


ERROR Message:
Compiling code. 0.20
Generating R file. 0.00
Compiling generated Java code. Error
B4A line: 1576
LblBebe.Text = TexteBebe
javac 1.6.0_26

Thank you.
 

agraham

Expert
Licensed User
Longtime User
That is entirely wrong syntax for a Select and I can't see what you are trying to do with it. Why not just

B4X:
TexteBebe = File.ReadString(File.DirAssets, TexteBaby(Position))
LblBebe.Text = TexteBebe
Search for "Select" to see the correct syntax, it comes up as the first result.
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Here is the corect code. Sorry I have rectified, it works

Sub ListView1_ItemClick (Position As Int, Value As Object)
Dim i As Int
Dim TexteBaby(12) As String

TexteBaby(0) = "bebe_1mois.txt"
TexteBaby(1) = "bebe_5sem.txt"
TexteBaby(2) = "bebe_6sem.txt"
TexteBaby(3) = "bebe_7sem.txt"
TexteBaby(4) = "bebe_8sem.txt"
TexteBaby(5) = "bebe_9sem.txt"
TexteBaby(6) = "bebe_10sem.txt"

For i = 0 To 6
Select Position
Case i
TexteBebe = File.ReadString(File.DirAssets, TexteBaby(i))
LblBebe.Text = TexteBebe
End Select
Next
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Your code is quite complicated:
Why do you Dim TexteBaby(12), you dim 12 elements but you use only 7 ?
Why do you define the values for
TexteBaby(0) to TexteBaby(6) in the ListView1_ItemClick routine ?
Y
ou could define TexteBaby(i) as a Global array and define the values only once.
And your routine would look like (as agraham already suggested):
B4X:
[COLOR=Navy]Sub ListView1_ItemClick (Position As Int, Value As Object)
  [/COLOR][COLOR=Navy]TexteBebe[/COLOR][COLOR=Navy] = [/COLOR][COLOR=Navy]File.ReadString(File.DirAssets, TexteBaby([/COLOR][COLOR=Navy]Position[/COLOR][COLOR=Navy]))[/COLOR]
  [COLOR=Navy]LblBebe.Text = [/COLOR][COLOR=Navy]TexteBebe[/COLOR]
[COLOR=Navy]End Sub[/COLOR]
Best regards.

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