Android Question Add Variable to a String

MarcioCC

Member
Licensed User
Longtime User
Good night, I have the following line of code: TextWriter1.Initialize (File.OpenOutput (File.DirDefaultExternal, "catcher.txt", False))
I want to do the following, I have the following variable (Dim lbl_chamaIMEI As Label), I put in this variable the IMEI of the device, how do I play the variable in the line of code (TextWriter1.Initialize (File.OpenOutput (File.DirDefaultExternal, "lbl_chamaMEI" , False))
I need to create a .txt file with the name of the variable (lbl_chamaIMEI)
Does anyone have an example to send me ??
 

mangojack

Expert
Licensed User
Longtime User
Not tested but you could try ...
B4X:
lbl_chamaIMEI.Tag = "lbl_chamaIMEI"
TextWriter1.Initialize (File.OpenOutput (File.DirDefaultExternal,$"${lbl_chamaMEI.Tag}.txt"$ , False))

*Edit .. Would you not be doing this just once for each device ?? Why not just store it in "IMEI.txt" / "DeviceID.txt" ??
 
Last edited:
Upvote 0

MarcioCC

Member
Licensed User
Longtime User
Good night, my friend, I used your code plus this giving an error message follows the complete code, the error is giving this line: TextWriter1.Initialize (File.OpenOutput (File.DirDefaultExternal, $ "$ {lbl_chamaMEI.Tag} .txt" $ , False))
Error description: Undeclared variable 'lbl_chamamei' is used before it was assigned any value.
B4X:
Sub BtnGeraInv_Click
     
                  Dim lbl_chamaIMEI As Label
                               
         Qry="SELECT CODBARRAS,QUANTIDADE FROM PRODUTOS ORDER BY CODBARRAS"
         Cursor1=SQL.ExecQuery(Qry)
         If Cursor1.RowCount=0 Then
         Cursor1.Close
         Return
End If

            Lbl_IMEI.Text = GetDeviceId
           
            lbl_chamaIMEI = Lbl_IMEI.Text
       
            lbl_chamaIMEI.Tag = "lbl_chamaIMEI"
           
            ERROR IN THIS LINE --->TextWriter1.Initialize (File.OpenOutput (File.DirDefaultExternal,$"${lbl_chamaMEI.Tag}.txt"$ , False))
            ERROR MESSAGE ---> Undeclared variable 'lbl_chamamei' is used before it was assigned any value.

   For i = 0 To Cursor1.RowCount-1
   Cursor1.Position=i
   CODBARRAS= Cursor1.GetString("CODBARRAS") 
   QUANTIDADE = Cursor1.GetString("QUANTIDADE") 
   
   TextWriter1.Write(CODBARRAS & "," & QUANTIDADE & Chr(13) & Chr(10))
   
    
Next
TextWriter1.Flush
TextWriter1.Close
Cursor1.Close
Msgbox("Inventário Gerado com Sucesso !!","Coletor de Dados MPC®")

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