IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Conversion VB to C# [FileGet]


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2011
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2011
    Messages : 3
    Par défaut Conversion VB to C# [FileGet]
    Bonsoir,

    je souhaite convertir une source VB en C# mais je bloque sur l'élément FileGet() qui n'existe pas dans C# et je n'arrive pas à le reproduire...

    mon code VB.net ressemble à ceci :
    Code Visual Basic :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    Imports System.IO
    Public Class Form1
     
        Dim stub, text1 As String
        Const FileSplit = "@FileSplit@"
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            text1 = TextBox1.Text
            FileOpen(1, Application.StartupPath & "\stub.exe", OpenMode.Binary, OpenAccess.Read, OpenShare.Default)
            stub = Space(LOF(1))
            FileGet(1, stub)
            FileClose(1)
            If File.Exists("programme.exe") Then
                My.Computer.FileSystem.DeleteFile("programme.exe")
            End If
            FileOpen(1, Application.StartupPath & "\programme.exe", OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Default)
            FilePut(1, stub & FileSplit & text1)
            FileClose(1)
        End Sub
    End Class

    Et voici la "traduction" que j'ai faite en C#
    Code C# :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
     
     
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
     
            string stub;
    	    string text1;
            const string FileSplit = "@FileSplit@";
     
            private void Button1_Click(object sender, EventArgs e)
            {
                text1 = TextBox1.Text;	 	                        
                FileStream ouvreStub = File.Open(Application.StartupPath + "\\stub.exe", FileMode.Open, FileAccess.Read, FileShare.None);
                String test = new String(' ', (int)ouvreStub.Length);
                stub = test;
     
                // LE PROBLEME ...
                FileGet(1, stub);
     
     
                ouvreStub.Close();
     
    		    if (File.Exists("programme.exe")) 
                {
                    File.Delete("programme.exe");
    		    }
     
                FileStream ouvreProgramme = File.Open(Application.StartupPath + "\\programme.exe", FileMode.Open, FileAccess.ReadWrite, FileShare.None);
                BinaryWriter bw = new BinaryWriter(ouvreProgramme);
                bw.Write(stub + FileSplit + text1);
                ouvreProgramme.Close();
            }
        }
    }

    Bien entendu je ne suis pas sur que ma conversion est totalement correct et je ne le saurais que lorsque j'aurais fini...

    Mais pour l'instant c'est le "FileGet(1, stub);" qui me pose problème et je suis un peu perdu...

    J'espère que vous saurez m'aider.

    Merci

  2. #2
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut vb et fileget
    bonjour bettyblues
    fileget renvoie la chaine lue dans fileopen.
    voici une possibilite de contourner le probleme avec filestream:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
     
     
    string stub;
            string text1;
            const string FileSplit = "@FileSplit@";
     
            private void button1_Click(object sender, EventArgs e)
            {
                text1 = TextBox1.Text;
                FileStream ouvreStub = File.Open(Application.StartupPath + "\\stub.exe", FileMode.Open, FileAccess.Read, FileShare.None);
     
                String test = new String(' ', (int)ouvreStub.Length);
                // LE PROBLEME ...
                Byte[] bArray = new Byte[ouvreStub.Length];
                ouvreStub.Read( bArray, 0,   (int)bArray.Length - 1);
     
                //CONVERSION ASCII ET STOCKAGE DANS STRING TEST
                test = Encoding.ASCII.GetString( bArray,  0,  (int)bArray.Length - 1);
                textBox2.Text = test + Environment.NewLine;
     
                stub = test;
                // LE PROBLEME ...
                //FileGet(1, stub);
     
     
                ouvreStub.Close();
     
                if (File.Exists("programme.exe"))
                {
                    File.Delete("programme.exe");
                }
     
                FileStream ouvreProgramme = File.Open(Application.StartupPath + "\\programme.exe", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
                BinaryWriter bw = new BinaryWriter(ouvreProgramme);
                bw.Write(stub + FileSplit + text1);
                ouvreProgramme.Close();
            }
    bon code....

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2011
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2011
    Messages : 3
    Par défaut
    Merci de m'avoir répondu je regarde à sa et je te dis quoi.

    Mais juste une chose :

    Quand tu dis : textBox2.Text = test + Environment.NewLine;

    Se ne serais pas plutôt : stub = test + Environment.NewLine;

    Pour que tu comprennes mieux mon projet je vais te mettre l’entièreté :

    1.) Le Builder :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
     
     
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
     
            string stub;
    	    string text1;
            const string FileSplit = "@FileSplit@";
     
            private void Button1_Click(object sender, EventArgs e)
            {
                text1 = TextBox1.Text;	 	                        
                FileStream ouvreStub = File.Open(Application.StartupPath + "\\stub.exe", FileMode.Open, FileAccess.Read, FileShare.None);
     
                String test = new String(' ', (int)ouvreStub.Length);
     
                // LE PROBLEME
                Byte[] bArray = new Byte[ouvreStub.Length];
                ouvreStub.Read(bArray, 0, (int)bArray.Length - 1);
     
                //CONVERSION ASCII ET STOCKAGE DANS STRING TEST
                test = Encoding.ASCII.GetString(bArray, 0, (int)bArray.Length - 1);
                stub = test + Environment.NewLine;
     
                //stub = test;
     
                // LE PROBLEME ...
                //FileGet(1, stub);
     
     
                ouvreStub.Close();
     
    		    if (File.Exists("programme.exe")) 
                {
                    File.Delete("programme.exe");
    		    }
     
                FileStream ouvreProgramme = File.Open(Application.StartupPath + "\\programme.exe", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
                BinaryWriter bw = new BinaryWriter(ouvreProgramme);
                bw.Write(stub + FileSplit + text1);
                ouvreProgramme.Close();
            }
        }
    }
    2.) Le Stub :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
     
     
    namespace WindowsFormsApplication4
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                //Load += Form1_Load;
            }
     
            string[] options;
            string text1;
            const string FileSplit = "@FileSplit@";
     
     
     
            private void Form1_Load_1(object sender, EventArgs e)
            {
                FileStream ouvreStub = File.Open(Application.StartupPath, FileMode.Open, FileAccess.Read, FileShare.None);
     
                String test = new String(' ', (int)ouvreStub.Length);
                text1 = test;
     
     
                //FileGet(1, text1);
                Byte[] bArray = new Byte[ouvreStub.Length];
                ouvreStub.Read(bArray, 0, (int)bArray.Length - 1);
                test = Encoding.ASCII.GetString(bArray, 0, (int)bArray.Length - 1);
                text1 = test + Environment.NewLine;
     
                //options = Split(text1, FileSplit);
                options = text1.Split(FileSplit.ToCharArray());
     
                TextBox1.Text = options[1];
            }
        }
    }
    Et voici le lien Megaupload du même projet fonctionnel en VB

    http://www.megaupload.com/?d=DT0GCNT5

    Et le projet C# au cas ou ^^

    http://www.megaupload.com/?d=K4BEXZPW

Discussions similaires

  1. Conversion Assembleur Motorola 68xxx en Intel 80xxx
    Par markham dans le forum Autres architectures
    Réponses: 3
    Dernier message: 22/11/2002, 20h09
  2. [MSXML] Comment empécher la conversion des entités ?
    Par nima dans le forum XSL/XSLT/XPATH
    Réponses: 3
    Dernier message: 08/11/2002, 14h14
  3. Algorithme de conversion de RTF vers HTML
    Par youtch dans le forum Algorithmes et structures de données
    Réponses: 10
    Dernier message: 10/09/2002, 12h35
  4. [Conversions] Millisecondes...
    Par agh dans le forum Langage
    Réponses: 2
    Dernier message: 06/08/2002, 11h25
  5. Réponses: 2
    Dernier message: 05/06/2002, 12h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo