Work with data from a txt

-2

With visual I created some forms and I'm trying to do it in local html.

I have some text files as data, created by a program.

c:\MAPPERS Archivo PV (.PV).
c:\PVS Archivo PV (.PV).

Example:

IB  081930200905300250MAD 1321ECJQZ   T07        00A200905300254AKLF  continua..
V7   94229200905300315MAD 1321ECILP   P24        00A200905300323AKLI  continua..
RGN 901130200905300650TFN 1D8CECIGZ   T13          A200905300727A     continua..

and x data per line.

I need that when the page is loaded, I read the file

c:\MAPPERS Archivo PV (.PV).

and if I choose another date read the file

c:\PVS Archivo PV (.PV).

What I have at the moment in notepad ++              Web report Airportservice LPA                                                                                                   

</head>
<body>
    <div class="contenedor">
        <div class="cabecera">
        <img src="http://static.corp.iberia.es/atlas/img/logo_134x29.png" alt="Iberia">
        <script>
         $(function () {
             $.datepicker.setDefaults($.datepicker.regional["es"]);
             $("#datepicker").datepicker({
                 dateFormat: 'dd/mm/yy',
                 firstDay: 1
             }).datepicker("setDate", new Date());
         });
         </script>
        <h1>Webreport Airport Service </h1>v.1.0
        <BR>
        <BR>
        Selecciona Fecha:&nbsp;&nbsp;
        <input type="text" id="datepicker"/>
        <BR>

        <ul>
          <li>

            <input type="radio" name="group1" value="Vuelos de Llegada">Vuelos de Llegada<br>                
            </li>
            <li>
            <input type="radio" name="group1" value="Vuelos de salida" checked>Vuelos de salida<br>
            </li>             
          </ul>
            <br>                
        </div>
        <P>Hora UTC</p>
        <div class="barra">         
        <script type="text/javascript"> function startTime(){ today=new Date(); h=today.getUTCHours(); m=today.getMinutes(); s=today.getSeconds(); m=checkTime(m); s=checkTime(s); document.getElementById('reloj').innerHTML=h+":"+m+":"+s; t=setTimeout('startTime()',500);} function checkTime(i) {if (i<10) {i="0" + i;}return i;} window.onload=function(){startTime();} </script> <div id="reloj"></div>
        </div>
        <div class="marco"> 
            <div class="contenido">                    
                <br>
                <table id='miTabla' class='TablaOrden'>
                    <caption>Datos Vuelos..</caption>
                    <thead>
                    <th onclick="TablaOrden.en('miTabla',0)">CIA</th>
                    <th>VUELO</th>
                    <th>DT1</th>
                    <th>DT2</th>
                    <th onclick="TablaOrden.en('miTabla',4)">STD</th>
                    <th onclick="TablaOrden.en('miTabla',5)">ETD</th>
                    <th>Coord</th>
                    </thead>
                    <tbody>
                        <TR><TD>VY</TD><TD>3001</TD><TD>BCN</TD><TD>TXL</TD><TD>1325</TD><TD>1400</TD><TD>alco</TD><TD><a href="http://microsoft.com" style="color:red" >F.C&nbsp;&nbsp;&nbsp;</a></TD><TD><a href="http://microsoft.com" style="color:blue" >F.P&nbsp;&nbsp;&nbsp;</TD><TD><a href="http://microsoft.com" style="color:YELLOW" >F.U&nbsp;&nbsp;&nbsp;</TD></TR>
                        <TR><TD>RGN</TD><TD>9011</TD><TD>MAD</TD><TD>BCN</TD><TD>0900</TD><TD>0900</TD><TD>speL</TD><TD><a href="http://microsoft.com" style="color:red" >F.C&nbsp;&nbsp;&nbsp;</a></TD><TD><a href="http://microsoft.com" style="color:blue" >F.P&nbsp;&nbsp;&nbsp;</TD><TD><a href="http://microsoft.com" style="color:YELLOW" >F.U&nbsp;&nbsp;&nbsp;</TD></TR>
                        <TR ><TD>DE</TD><TD>1052</TD><TD>HAJ</TD><TD>DUS</TD><TD>1200</TD><TD>1158</TD><TD>anaL</TD><TD><a href="http://microsoft.com" style="color:red" >F.C&nbsp;&nbsp;&nbsp;</a></TD><TD><a href="http://microsoft.com" style="color:blue" >F.P&nbsp;&nbsp;&nbsp;</TD><TD><a href="http://microsoft.com" style="color:YELLOW" >F.U&nbsp;&nbsp;&nbsp;</TD></TR>
                        <TR><TD>MT</TD><TD>1406</TD><TD>LGW</TD><TD>MAN</TD><TD>1500</TD><TD>1505</TD><TD>ctul</TD><TD><a href="http://microsoft.com" style="color:red" >F.C&nbsp;&nbsp;&nbsp;</a></TD><TD><a href="http://microsoft.com" style="color:blue" >F.P&nbsp;&nbsp;&nbsp;</TD><TD><a href="http://microsoft.com" style="color:YELLOW" >F.U&nbsp;&nbsp;&nbsp;</TD></TR>                            
                    </tbody>
                </table>

Depending on the <input type="text" id="datepicker"/> I want you to search me on each line for the date value in dd/yyyy/mm format.

In the row it reads from the character 9 and is 8 characters.

Once you have that data as proven, read the first 3 characters of that line and dump them and create the first td and then take the value pos 23 and read the 3 characters and copy them in the following td . So several values.

<TR><TD>IB </TD><TD>MAD</TD><TD>

Once you have finished the first line, read the following lines and create your tables and values.

At the time, perform in visual basic.

Dim Fso As New FileSystemObject
    Dim ts As TextStream
    Dim strCodigo As String
    Dim strLinea As String
    Fso.CopyFile "P:\mapperS.pv", "C:\gonzalez\temporal\MAPPERS.PV"
    Set ts = Fso.OpenTextFile("C:\gonzalez\temporal\MAPPERS.PV")
    strCodigo = UCase(text1.Text) & Format(DTPFecha, "ddYYYYMM")
Do While Not (ts.AtEndOfStream)
    strLinea = ts.ReadLine
    If strCodigo = Left(strLinea, Len(strCodigo)) Then
    SVALOR1 = Mid(strLinea, 1, 8)
        Dim datFecha As Date
        Dim sCodigo As String
        sCodigo = Mid(strLinea, 9, 8)
        datFecha = DateSerial(Mid(sCodigo, 3, 4), Mid(sCodigo, 7, 2), Mid(sCodigo, 1, 2))
    SVALOR3 = Mid(strLinea, 19, 4)
    SVALOR4 = Mid(strLinea, 61, 4)
    SVALOR5 = Mid(strLinea, 23, 3)
    SVALOR6 = Mid(strLinea, 42, 3)
    SVALOR7 = Mid(strLinea, 31, 5)
    SVALOR8 = Mid(strLinea, 38, 4)
    SVALOR9 = Mid(strLinea, 301, 3)
    SVALOR10 = Mid(strLinea, 985, 4)
    SVALOR11 = Mid(strLinea, 528, 2)
    SVALOR11A = Mid(strLinea, 530, 2)
    SVALOR11B = Mid(strLinea, 532, 3)
    SVALOR12 = Mid(strLinea, 536, 2)
    SVALOR12A = Mid(strLinea, 538, 2)
    SVALOR12B = Mid(strLinea, 540, 3)
    SVALOR13 = Mid(strLinea, 543, 2)
    SVALOR13A = Mid(strLinea, 545, 3)
    SVALOR13B = Mid(strLinea, 548, 3)
    SVALOR13C = Mid(strLinea, 551, 2)
    sValor14 = Mid(strLinea, 240, 3)
    SVALOR15 = Mid(strLinea, 243, 3)
    SVALOR16 = Mid(strLinea, 553, 3)
    sValor17 = Mid(strLinea, 1074, 20)
    SVALOR18 = Mid(strLinea, 1002, 15)
    SVALOR19 = Mid(strLinea, 225, 14)
    svalor20 = Mid(strLinea, 391, 2)
    SVALOR21 = Mid(strLinea, 352, 6)
    SVALOR22 = Mid(strLinea, 358, 6)
    svalor23 = Mid(strLinea, 1, 3)
    Exit Do
    End If
Loop
FichaEmbForm.lblvuelosalida.Caption = SVALOR1
FichaEmbForm.lblfecha_salida.Caption = Format(datFecha, "dd/mm/yyyy")
FichaEmbForm.lblhora_std.Caption = SVALOR3
FichaEmbForm.txthora_cetd.Text = SVALOR4
FichaEmbForm.txtdest1.Text = SVALOR5
FichaEmbForm.txtdest2.Text = SVALOR6
FichaEmbForm.txtreg.Text = SVALOR7
FichaEmbForm.txtpkn_s.Text = SVALOR8
FichaEmbForm.txtgate.Text = SVALOR9
FichaEmbForm.txtslot.Text = SVALOR10
FichaEmbForm.txtversion.Text = SVALOR11 & "/" & SVALOR11A & "/" & SVALOR11B
FichaEmbForm.txtprevision.Text = SVALOR12 & "/" & SVALOR12A & "/" & SVALOR12B
FichaEmbForm.txtfacturados.Text = SVALOR13 & "/" & SVALOR13A & "/" & SVALOR13B & "+" & SVALOR13C
FichaEmbForm.txtpax_dest1.Text = sValor14
FichaEmbForm.txtpax_dest2.Text = SVALOR15
FichaEmbForm.txttto_s.Text = SVALOR16
FichaEmbForm.txtnotaS_cic.Text = sValor17
FichaEmbForm.Textcrewinfos_cic.Text = SVALOR18
FichaEmbForm.txtosi_s.Text = SVALOR19
FichaEmbForm.Textmo_fact.Text = svalor20
FichaEmbForm.TextNombre_emb1.Text = SVALOR21
FichaEmbForm.TextNombre_emb2.Text = SVALOR22

I do not know if there is any way to do this.

An example that I found:

<input type="file" id="file-input" />
<h3>Contents of the file:</h3>
<pre id="file-content"></pre>
<script>
  function readSingleFile(e) {
  var file = e.target.files[0];
  if (!file) {
    return;
  }
  var reader = new FileReader();
  reader.onload = function(e) {
    var contents = e.target.result;
    displayContents(contents);
  };
  reader.readAsText(file);
}

function displayContents(contents) {
  var element = document.getElementById('file-content');
  element.innerHTML = contents;
}

document.getElementById('file-input')
  .addEventListener('change', readSingleFile, false);
</script> 
    
asked by EGR33 15.04.2016 в 21:54
source

2 answers

1

One option is to use regular expressions.

An example is something like this: / (. {3}). {5} (29200905). {6} (. {3}) /

$.get( "https://58ffbf16d8f8f36928e82fc965d7f39867697f38-www.googledrive.com/host/0Bxs17r_AjwPEMkpYMkpNOHJucXc/ejemplo.txt", function( data ) {
  
    data;
  	var fecha = '29200905';

	//var re =  /(.{3}).{5}(29200905).{6}(.{3})/;

	var regex = new RegExp("(.{3}).{5}(" + fecha + ").{6}(.{3})");

	var myArray = data.match(regex);
	document.write(myArray[1]+"-");
	document.write(myArray[2]+"-");
	document.write(myArray[3]);

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

If you have any questions, I remain attentive

Response to "How do I look for the file depending on the value? If the date is today or higher I look for c: \ MAPPERS.pv and if it is smaller c: \ date (format ddmmyy) S.SV"

	var fechaInput = "2016/04/24"; // valore del input;	

	var fecha = new Date(fechaInput);
	var hoy = new Date();
	hoy.setHours(0, 0, 0, 0);

	var archivo = '';
	if (fecha < hoy ) {	
		var dia = fecha.getDate();
		var mes = fecha.getMonth() + 1;
		if (mes <= 9){
		   mes = '0'+mes;
		}
		var anio = fecha.getFullYear().toString().substring(2,4);
		archivo = dia+''+mes+''+anio+'S.SV';
	} else {
		archivo = 'MAPPERS.pv';
	}
	document.write(archivo);
    
answered by 21.04.2016 в 22:49
0

I suggest you use a framework to use Javascript and for lists with options how to order, filter by fields etc ... look at the List.js You can load the data in a textarea and with JQuery or Javascript extract line by line.

var lines = $('textarea').val().split('\n');
for(var i = 0;i < lines.length;i++){
    //leer cada linea, separar por campos etc...
}
    
answered by 19.04.2016 в 10:20