[VBSCRIPT] String to ascii

Résolu
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. 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 ;)
    1. Modérateur
      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. Marche toujours pas, probleme au niveau ASC... :( En tous cas marci de m'avoir repondu :)
      2. Ca marche! J'obtient ca si je tappe: my name is denstieven 10912132110971091013210511532100101110115116105101118101110

        Mais a la fin toujours type incompatible ASC
      3. Et par fois argument ou appel de procedure incompatible? Je ne sais pas pourqoui?
      4. Modérateur
        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