Hello,
In a fairly large application I have three calls to SaveAs, as per Erel's example.
Two of the calls work fine, but one of them which is in a code module does not give an error but the file is created empty, without the data in the SaveAs, however the file in the android folder is correct and with all the data inside.
The files are CSV files of a size of approximately 50kB each.
It is also curious that the lines after the
"Wait For (B4XPages.MainPage.SaveAs(File.OpenInput(Path,File), "application/octet-stream", File)) Complete (Success As Boolean)"
do not execute.
I am quite confused with this behavior so any help is of great value.
I leave you part of the code, where the call that does not work is to see if you can help me.
Thank you very much
In a fairly large application I have three calls to SaveAs, as per Erel's example.
Two of the calls work fine, but one of them which is in a code module does not give an error but the file is created empty, without the data in the SaveAs, however the file in the android folder is correct and with all the data inside.
The files are CSV files of a size of approximately 50kB each.
It is also curious that the lines after the
"Wait For (B4XPages.MainPage.SaveAs(File.OpenInput(Path,File), "application/octet-stream", File)) Complete (Success As Boolean)"
do not execute.
I am quite confused with this behavior so any help is of great value.
I leave you part of the code, where the call that does not work is to see if you can help me.
B4X:
Sub BT_Exportar_Click
Dim C As Int = 0
Dim D As Int = 0
Dim Ayuda As String = ""
Dim Fichero As String = ""
Dim Ruta As String = ""
Dim Ay As String = ""
' Impide Pulsar el Boton Antes de Terminas
Bt_Exportar.Enabled = False
' Nombre del Fichero.
Fichero = "ICDoor_Exp01_" & NumberFormat(DateTime.GetDayOfMonth(DateTime.Now) ,2,0)
Fichero = Fichero & NumberFormat(DateTime.GetMonth(DateTime.Now),2,0)
Fichero = Fichero & NumberFormat(DateTime.GETYEAR(DateTime.Now)-2000,2,0)
Fichero = Fichero & "_"
Fichero = Fichero & NumberFormat(DateTime.GetHour(DateTime.Now),2,0)
Fichero = Fichero & NumberFormat(DateTime.GetMinute(DateTime.Now),2,0)
Fichero = Fichero & NumberFormat(DateTime.GetSecond(DateTime.Now),2,0)
Fichero = Fichero & ".CSV"
' Ruta del Fichero
Ruta = File.DirDefaultExternal ' File.DirInternal o File.DirDefaultExternal
Log("Inicia Exportacion ")
Log("Fichero =" & Fichero)
Log("Directorio=" & Ruta)
LB_Exportando.Visible = True
B_Exporta.Visible = True
ToastMessageShow("Exportando Datos ...",True)
' Cabecera del Fichero CVS
Ayuda = "Gráfica de IC-DOOR" & Chr(10) & Chr(13)
If B4XPages.MainPage.A_T_Logger = 0 Then
Ayuda = Ayuda & "Muestreo por Cambio de Valor. [BY G.T.V]" & Chr(10) & Chr(13)
Else
Ayuda = Ayuda & "Intervalo entre muestras"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.A_T_Logger ,3,1)
Ayuda = Ayuda & " ms. [BY G.T.V]" & Chr(10) & Chr(13)
End If
' Cabecera del Fichero
Ayuda = Ayuda & "Registro;"
Ayuda = Ayuda & "Posición Encoder;"
Ayuda = Ayuda & "Posición Encoder Filtrada;"
Ayuda = Ayuda & "Posición Puerta;"
Ayuda = Ayuda & "Consigna Velocidad;"
Ayuda = Ayuda & "Intensidad Motor;"
Ayuda = Ayuda & "Calidad Total;"
Ayuda = Ayuda & "Calidad Parcial;"
Ayuda = Ayuda & "Secuencia;"
Ayuda = Ayuda & "Modo Maniobra;"
Ayuda = Ayuda & "Puerta Abierta;"
Ayuda = Ayuda & "Puerta Cerrada;"
Ayuda = Ayuda & "Puerta Abriendo;"
Ayuda = Ayuda & "Puerta Cerrando;"
Ayuda = Ayuda & "Puerta Parada;"
Ayuda = Ayuda & "Orden Freno;"
Ayuda = Ayuda & "Orden Abrir;"
Ayuda = Ayuda & "Orden Cerrar;"
Ayuda = Ayuda & "Foto Célula;"
Ayuda = Ayuda & "PRG Pide Abrir;"
Ayuda = Ayuda & "PRG Pide Cerrar;"
Ayuda = Ayuda & "Alguna Orden M;"
Ayuda = Ayuda & "Contactor A;"
Ayuda = Ayuda & "Contactor C;"
Ayuda = Ayuda & "Emergencia Ok;"
Ayuda = Ayuda & "E00;"
Ayuda = Ayuda & "E01;"
Ayuda = Ayuda & "PLC Run;"
Ayuda = Ayuda & "PE Encoder;"
Ayuda = Ayuda & "Fallo Test FotoCelula;"
Ayuda = Ayuda & "Fallo Comunica Encoder;"
Ayuda = Ayuda & "Encoder No se Mueve;"
Ayuda = Ayuda & "PE_Ext;"
Ayuda = Ayuda & "Fallo VF;"
Ayuda = Ayuda & "FC.A;"
Ayuda = Ayuda & "FC.C;"
Ayuda = Ayuda & "DB.1;"
Ayuda = Ayuda & "DB.2;"
Ayuda = Ayuda & "P.Radio 1;"
Ayuda = Ayuda & "P.Radio 2;"
Ayuda = Ayuda & "Ent.Bloqueo A;"
Ayuda = Ayuda & "Fallo Vf"
Ayuda = Ayuda & Chr(10) & Chr(13)
D = 0 ' Inicializa
For C = 0 To Posicion
LB_Exportando.Text = "Exp." & C & " de " & Posicion
B_Exporta.Progress = (C*100) / Posicion
D = D + 1
Ayuda = Ayuda & C & ";" ' Registro
Ayuda = Ayuda & NumberFormat2(Main.Logger(C).P_Encoder, 5,0,0,False) & ";" ' Posicion Encoder
Ayuda = Ayuda & NumberFormat2(Main.Logger(C).P_Encoder_F,5,0,0,False) & ";" ' Posicion Encoder filtrada
Ay = NumberFormat2(Main.Logger(C).P_Puerta, 3,2,2,False) & ";" ' Posicion Puerta
If Ay.Contains(".") Then
Ay = Ay.Replace(".",",") ' Cambia "." por ","
End If
Ayuda = Ayuda & Ay
Ay = NumberFormat2(Main.Logger(C).C_Velocidad,3,2,2,False) & ";" ' Consigna Velocidad
If Ay.Contains(".") Then
Ay = Ay.Replace(".",",") ' Cambia "." por ","
End If
Ayuda = Ayuda & Ay
Ay = NumberFormat2(Main.Logger(C).Intensidad_M,2,3,3,False) & ";" ' Intensidad Motor
If Ay.Contains(".") Then
Ay = Ay.Replace(".",",") ' Cambia "." por ","
End If
Ayuda = Ayuda & Ay
Ayuda = Ayuda & NumberFormat2(Main.Logger(C).CT_Encoder, 4,0,0,False) & ";" ' Calidad Total encoder
Ayuda = Ayuda & NumberFormat2(Main.Logger(C).CP_Encoder, 4,0,0,False) & ";" ' Calidad Parcial encoder
Ayuda = Ayuda & NumberFormat2(Main.Logger(C).Secuencia, 3,0,0,False) & ";" ' Numero de Secuencia
Ayuda = Ayuda & NumberFormat2(Main.Logger(C).Modo_M, 3,0,0,False) & ";" ' Modo Maniobra
' Digitales 1
If Main.Logger(C).P_Abierta = True Then ' Puerta Abierta 1.0
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).P_Cerrada = True Then ' Puerta Cerrada 1.1
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).P_Abriendo = True Then ' Puerta Abriendo 1.2
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).P_Cerrando = True Then ' Puerta Cerrando 1.3
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).P_Parada = True Then ' Puerta Parada 1.4
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).O_Freno = True Then ' Orden Freno Puerta 1.5
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).O_Abrir = True Then ' Orden Abrir 1.6
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).O_Cerrar = True Then ' Orden Cerrar 1.7
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
' Digitales 2
If Main.Logger(C).Foto_Celula = True Then ' Estado Foto Celula 2.0
Ayuda = Ayuda & "1;"
Else
Ayuda = Ayuda & "0;"
End If
If Main.Logger(C).PRG_Pide_A = True Then ' PRG Pide Abrir 2.1
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).PRG_Pide_C = True Then ' PRG Pide Cerrar 2.2
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).Alguna_Orden_M = True Then ' Alguna Orden Movimiento 2.3
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).Contactor_A = True Then ' Contactor Abrir 2.4
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).Contactor_C = True Then ' Contactor Cerrar 2.5
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).Emergencia_OK = True Then ' Parada de Emergencia 2.6
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).E00 = True Then ' E00 2.7
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
' Digital 3
If Main.Logger(C).E01 = True Then ' E01 3.0
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).PLC_Run = True Then ' PLC en RUN 3.1
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
' Digitales 3
If Main.Logger(C).Pe_Encoder = True Then ' Parada Emergencia Encoder 3.2
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).Fallo_T_FT = True Then ' Fallo Test de Fotocelula 3.3
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).F_C_E = True Then ' Fallo Comunicacion Encoder 3.4
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).Memo_E_NM = True Then ' Fallo Encoder No se Mueve 3.5
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).PE_Ext = True Then ' Pulsadores PE Parametrizables.3.6
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).VF_Fallo = True Then ' Fallo del VF 3.7
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
' Digital 4
If Main.Logger(C).E11 = True Then ' Final de Carrera Abierta 4.0
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).E12 = True Then ' Final de Carrera Cerrada 4.1
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).E13 = True Then ' Detector de Banda 1 4.2
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).E14 = True Then ' Detector de Banda 2 4.3
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).E15 = True Then ' Pulsador de Radio 1 4.4
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).E16 = True Then ' Pulsador de Radio 2 4.5
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).E06 = True Then ' Entrada Bloqueo de Apertura 4.6
Ayuda = Ayuda & "1" & ";"
Else
Ayuda = Ayuda & "0" & ";"
End If
If Main.Logger(C).E10 = True Then ' Entrada Fallo del VF 4.7
Ayuda = Ayuda & "1"
Else
Ayuda = Ayuda & "0"
End If
Ayuda = Ayuda & Chr(10) & Chr(13)
Sleep(0)
Next
' Incluir Datos de Estadistica
Ayuda = Ayuda & Chr(10) & Chr(13)
Ayuda = Ayuda & "ESTADISTICA" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Horas de Uso =;;;;;;" & NumberFormat(B4XPages.MainPage.ES_Horas_Uso,8,0) & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Arranques =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_N_Arranques,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Tecla ENTER =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_P_Tecla_Enter,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Tecla Mas =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_P_Tecla_Mas,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Tecla Menos =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_P_Tecla_Menos,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Abrir =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_Abrir,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Cerrar =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_Cerrar,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt PE =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_PE,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Fallos VF =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_Fallos_VF,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Orden A VF =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_O_A_VF,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Orden C VF =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_O_C_VF,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Fallos VF =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_Fallos_VF,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Rele 1 =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_RELE_1,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Rele 2 =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_RELE_2,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Rele 3 =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_RELE_3,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Rele 4 =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_RELE_4,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Reserva 1 =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_Reserva_1,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Reserva 2 =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_Reserva_2,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Reserva 3 =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_Reserva_3,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Freno =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_Freno,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt Fallos Encoder =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_Fallos_C_Encoder,8,0) & ";" & Chr(10) & Chr(13)
Ayuda = Ayuda & "Cnt PE Encoder =;;;;;;"
Ayuda = Ayuda & NumberFormat(B4XPages.MainPage.ES_CNT_Fallos_seg_Encoder,8,0) & Chr(10) & Chr(13)
' Guarda en Fichero Android\data\
File.WriteString(Ruta, Fichero, Ayuda)
' Presenta Informacion
Log("Final Exportacion")
Log("Ruta =" & Ruta )
Log("Fichero =" & Fichero)
Log("Largo Fichero =" & File.Size(Ruta,Fichero))
' Activa Boton Exportar
Bt_Exportar.Enabled = True
LB_Exportando.Visible = False
B_Exporta.Visible = False
Log("Abre Ventana para Guardar el Fichero")
Wait For (B4XPages.MainPage.SaveAs(File.OpenInput(Ruta,Fichero), "application/octet-stream", Fichero)) Complete (Success As Boolean)
If Success = True Then
Control.LogMessage("* ","Fichero Guardado Correctamente")
ToastMessageShow("Fichero Creado correctamente",True)
Else
Control.LogMessage("* ","Error al Guardar el Fichero")
ToastMessageShow("Error al crear el fichero de parametros",True)
End If
End Sub
Thank you very much