[VBSCRIPT] String to ascii

Résolu
denstieven Messages postés 717 Statut Membre -  
denstieven Messages postés 717 Statut Membre -
Bonjour,

Je creer un petit programme qui permet de convertir un mot en ascii. mais il y a un petit probleme. Il me dit que type de mid est incompatible.

Mon code:

Set objShell = WScript.CreateObject("WScript.Shell")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("nameinascii.txt", ForAppending, True)
namsplit = 0
namsplit2 = 1
nam = Inputbox ("Enter your name:", "name to ascii")
f.Write nam & "  "
namlenght = Len(nam)
do 
namchars = Mid(nam, namsplit, namsplit2)
namascii = Asc(namchars)
f.Write namascii
namsplit = namsplit + 1
namsplit2 = nampslit2 + 1  
loop until namsplit2 = namlenght
Msgbox "end " 


J'espere que vous comprenez ce que je veux dire :D

Merci pour toutes corrections et explications :)

Denstieven



--
"Pour poster une réponse, appuyez sur la touche 'F13' " !!!
Non ne le cherchez pas...

2 réponses

  1. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773
     
    Bonjour,
    Il me semble bien que votre erreur est ici :
    namsplit = 0

    namsplit est le n° du caractère de début de Mid, "Start As Long". Or le caractère 0 n'existe pas. Un String débute par son 1er caractère non?
    Remplacez donc par :
    namsplit = 1

    1
    1. denstieven Messages postés 717 Statut Membre 42
       
      Marche toujours pas, probleme au niveau ASC... :( En tous cas marci de m'avoir repondu :)
      0
    2. denstieven Messages postés 717 Statut Membre 42
       
      Ca marche! J'obtient ca si je tappe: my name is denstieven 10912132110971091013210511532100101110115116105101118101110

      Mais a la fin toujours type incompatible ASC
      0
    3. denstieven Messages postés 717 Statut Membre 42
       
      Et par fois argument ou appel de procedure incompatible? Je ne sais pas pourqoui?
      0
    4. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773
       
      Je ne connais pas suffisamment le VBSCRIPT pour t'aider mais essaye quelque chose comme ça :
      namsplit = 1
      'namsplit2 = 1
      nam = Inputbox ("Enter your name:", "name to ascii")
      f.Write nam & "  "
      namlenght = Len(nam)
      do 
      namchars = Mid(nam, namsplit, 1)
      namascii = namascii & Asc(namchars)
      'f.Write namascii 'je ne connais pas cette instruction. Elle sert à quoi?
      namsplit = namsplit + 1
      'namsplit2 = nampslit2 + 1  
      loop until namsplit <= namlenght
      0
  2. denstieven Messages postés 717 Statut Membre 42
     
    Merci ca marche!!!

    Le code complet

    Set objShell = WScript.CreateObject("WScript.Shell")
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile("nameinascii.txt", ForAppending, True)
    namsplit = 1
    'namsplit2 = 2
    nam = Inputbox ("Enter your name:", "name to ascii")
    f.Write nam & " "
    namlenght = Len(nam)
    do
    namchars = Mid(nam, namsplit, 1)
    namascii = Asc(namchars)
    f.Write namascii
    namsplit = namsplit + 1
    'namsplit2 = nampslit2 + 1
    loop until namsplit = namlenght
    Msgbox "end "

    Le f.write sert a ecrire dans le fichier nameinascii.txt

    regarde: (Grand Merci Gord21 pour ce bout de code ^^)
    Set objShell = WScript.CreateObject("WScript.Shell")
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile("nomdufichier.txt", ForAppending, True)
    f.Write "Qu'est ce que tu veux"

    Et grand merci a toi aussi pour m'avoir aidé et c'est resolu :D

    Bonne journée encore ;)
    0