Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Count the letters, then generates a number.  (Read 5053 times)

0 Members and 1 Guest are viewing this topic.

BatchRocks

    Topic Starter


    Hopeful
  • Thanked: 3
    Count the letters, then generates a number.
    « on: January 19, 2009, 04:15:34 PM »
    Does anyone know a code that can count the letters that were enter from a
    Code: [Select]
    set /p and then generates each letter into a number, but the number can be converted into the word/phrase again?

    BR

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Count the letters, then generates a number.
    « Reply #1 on: January 19, 2009, 04:43:00 PM »
    Many of the posts from the last few days in both the DOS and Programming boards, have information which would be helpful your solution.

    What have you got so far? 8)

    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    BatchRocks

      Topic Starter


      Hopeful
    • Thanked: 3
      Re: Count the letters, then generates a number.
      « Reply #2 on: January 19, 2009, 05:04:15 PM »
      Well, nevermind I guess. I can't find the file I originally made, LOL.

      BR

      Dias de verano

      • Guest
      Re: Count the letters, then generates a number.
      « Reply #3 on: January 20, 2009, 03:46:42 AM »
      Well, nevermind I guess. I can't find the file I originally made, LOL.

      BR

       ::)

      DaveLembke



        Sage
      • Thanked: 662
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Count the letters, then generates a number.
      « Reply #4 on: January 20, 2009, 07:48:19 AM »
      BatchRocks .... If you come asking for knowledge on something, please dont just give up on it like that, as for dont you think you might be back later when you still dont know how to do this and may need to.

      I personaly would have followed through and given an example even if you dont have the exact file you originally wanted to use to figure out how to make it work for your application, then save a copy of the help you received for a later point when you decide you need it again.

      This forum is not just for shared solutions that we can code up for you to save you from having to do all the work, but also hopefully you see this as a learning area.

      Giving up like this frustrates many members. In the future maybe express that it may be of lesser importance because the batch application requirement is gone at this time, but you would still like to figure out how to do this by example so you may learn how it works, and others may learn from your example batch application needs as well.

      Dias de verano

      • Guest
      Re: Count the letters, then generates a number.
      « Reply #5 on: January 20, 2009, 09:16:34 AM »
      Very wise words, Dave.

      Dias de verano

      • Guest
      Re: Count the letters, then generates a number.
      « Reply #6 on: January 20, 2009, 11:47:03 AM »
      Batch is so the wrong language for this kind of thing! If you want to stay with the console, with QBasic or any of its clones, it's a "piece of piss" as we say in England. I know the code wizards will say the more modern languages like C or its children are better, but hey!

      Code: [Select]
      LINE INPUT "Type a sentence:"; sentence$
      Slen=LEN(sentence$)
      Enc$=""
      FOR J=1 to Slen
          Char$=MID$(sentence$,j,1)
          NUM=ASC(Char$)
          HS$=HEX$(NUM)
          Enc$=Enc$+HS$
      NEXT J
      PRINT Enc$

      In fact, you could put the loop and everything that is inside it on one line. Like this

      Code: [Select]
      FOR J=1 to Slen:Enc$=Enc$+HEX$(ASC(MID$(sentence$,j,1))):NEXT J
      Isn't that great?

      Code: [Select]
      Type a sentence:? Hello world
      48656C6C6F20776F726C64

      I used FreeBasic, which is, as its name implies, free, and it compiles to .exe files! What more could a budding nerd ask for?

      http://www.freebasic.net/

      I hope I haven't started something... Or do I?




         

      « Last Edit: January 20, 2009, 11:59:48 AM by Dias de verano »

      macdad-



        Expert

        Thanked: 40
        Re: Count the letters, then generates a number.
        « Reply #7 on: January 20, 2009, 12:10:22 PM »
        VB saves the day!
         ;D


        Code: [Select]
        Dim strInput As String
            Dim intLetters As Integer = -1


            Sub Main()
                strInput = Console.ReadLine()
                For i = 0 To strInput.Length
                    intLetters += 1
                Next
                Console.WriteLine("------------------")
                Console.WriteLine("Number of Letters:")
                Console.WriteLine(intLetters)
                Console.ReadKey()

            End Sub
        If you dont know DOS, you dont know Windows...

        Thats why Bill Gates created the Windows NT Family.

        Dias de verano

        • Guest
        Re: Count the letters, then generates a number.
        « Reply #8 on: January 20, 2009, 12:27:09 PM »
        Very good, macdad, but it doesn't do this part

        Quote
        and then generates each letter into a number, but the number can be converted into the word/phrase again

        BatchRocks

          Topic Starter


          Hopeful
        • Thanked: 3
          Re: Count the letters, then generates a number.
          « Reply #9 on: January 20, 2009, 12:38:21 PM »
          Sorry Dave. Thanks for the help. I actually only do Batch Files, and, I passed the project. Thanks for your help, Dias and Mac.

          Dylan

          macdad-



            Expert

            Thanked: 40
            Re: Count the letters, then generates a number.
            « Reply #10 on: January 20, 2009, 02:32:53 PM »
            Very good, macdad, but it doesn't do this part

            Quote
            and then generates each letter into a number, but the number can be converted into the word/phrase again

            ok i see what he wants, its kinda like Word to ASCII code and back to Word
            If you dont know DOS, you dont know Windows...

            Thats why Bill Gates created the Windows NT Family.

            Dias de verano

            • Guest
            Re: Count the letters, then generates a number.
            « Reply #11 on: January 20, 2009, 02:42:59 PM »
            ok i see what he wants, its kinda like Word to ASCII code and back to Word

            Well, he just said "numbers", and I just used ASCII because it seemed simpler, but once you have the text converted to numbers then some kind of simple cypher scheme could be arranged (I think that's what he was after) I converted to hex because then every letter of the alphabet converts to a 2 digit hex code which would make conversion back again easier.

            In fact if you then convert the hex digits say 0>A, 1>B, 2>C etc you'd have a message which would look pretty incomprehensible. If you used a one-time code scheme you'd be fairly secure from amateurs as well.



            DaveLembke



              Sage
            • Thanked: 662
            • Certifications: List
            • Computer: Specs
            • Experience: Expert
            • OS: Windows 10
            Re: Count the letters, then generates a number.
            « Reply #12 on: January 20, 2009, 04:12:59 PM »
            Thanks Dias and Mac for following through with this one. Also thanks for link to FreeBasic. Going to have to try that out. That conversion of text to hex was neat, and I added it to my personal geek archive.  8)

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            Re: Count the letters, then generates a number.
            « Reply #13 on: January 20, 2009, 04:16:18 PM »
            Batch is so the wrong language for this kind of thing! If you want to stay with the console, with QBasic or any of its clones, it's a "piece of piss" as we say in England. I know the code wizards will say the more modern languages like C or its children are better, but hey!

            Code: [Select]
            LINE INPUT "Type a sentence:"; sentence$
            Slen=LEN(sentence$)
            Enc$=""
            FOR J=1 to Slen
                Char$=MID$(sentence$,j,1)
                NUM=ASC(Char$)
                HS$=HEX$(NUM)
                Enc$=Enc$+HS$
            NEXT J
            PRINT Enc$

            In fact, you could put the loop and everything that is inside it on one line. Like this

            Code: [Select]
            FOR J=1 to Slen:Enc$=Enc$+HEX$(ASC(MID$(sentence$,j,1))):NEXT J
            Isn't that great?

            Code: [Select]
            Type a sentence:? Hello world
            48656C6C6F20776F726C64

            I used FreeBasic, which is, as its name implies, free, and it compiles to .exe files! What more could a budding nerd ask for?

            http://www.freebasic.net/

            I hope I haven't started something... Or do I?




               



            Why don't you use Visual Basic 2008 Express. 100% free, and can compile to .exe s as well.

            I was browsing through this section and I found a script that counts the amount of letters and characters, but only that.
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: Count the letters, then generates a number.
            « Reply #14 on: January 21, 2009, 02:14:04 AM »
            Why don't you use Visual Basic 2008 Express. 100% free, and can compile to .exe s as well.

            I was browsing through this section and I found a script that counts the amount of letters and characters, but only that.


            probably because it requires the .NET framework. Visual Basic .NET is a good language- but it's not Visual Basic(which itself isn't BASIC). if I ever move to .NET I will likely go to C#.

            I prefer to have direct access to API methods that I need, and wrap them in my own classes. Not some half-assed Microsoft version of a class that covers the API routines in a thin wrapper, like MFC.


            That Victor, still whittling away at FreeBASIC. It's excellent stuff, too. Once he  adds classes, I'll be writing a lot more code in and for it.


            I know the code wizards will say the more modern languages like C or its children are better, but hey!

            That actually strikes a much reverberated chord- C and C++ and so forth are  terrific languages, but- they are a huge pain in the but to debug and test and so forth. QBasic and QuickBASIC make it a lot easier to pumpt out quick chunks of code- especially for string manipulation. String manipulation in C/C++ should require a Surgeon's license.

            In fact, you could put the loop and everything that is inside it on one line. Like this
            Code: [Select]
            FOR J=1 to Slen:Enc$=Enc$+HEX$(ASC(MID$(sentence$,j,1))):NEXT J
            Now your just showing off ;)
               


            I was trying to dereference Null Pointers before it was cool.