Friend Module Program

    Public Declare Function SetConsoleTitle Lib "kernel32" Alias "SetConsoleTitleA" (ByVal lpConsoleTitle As String) As Long
    Declare Function ShellExecuteA Lib "shell32.dll" ( _
     ByVal hWnd As IntPtr, _
     ByVal lpOperation As String, _
     ByVal lpFile As String, _
     ByVal lpParameters As String, _
     ByVal lpDirectory As String, _
     ByVal nShowCmd As Integer) As IntPtr

    Dim run As String = "Run"
    Dim opstring As String
    Private Const OK As Integer = 0
    Private Const Errenous As Integer = 1

    Sub Main()
        InitConsole()

        While run = "Run"
            Console.Write(">>")
            GetLine()

        End While

    End Sub

    Sub InitConsole()
        SetConsoleTitle("Digital Console")
        opstring = String.Empty
        Console.WriteLine("Initialized")
    End Sub

    Function GetLine() As Integer
        opstring = Console.ReadLine
        CommandRun()
        Return 0
    End Function
    Private Sub CommandRun()
        If opstring = "Hello" Then
            Console.WriteLine("Hi")
        End If
        If opstring = "Scramble" Then
            opstring = ""
            Console.WriteLine("Enter string to scramble.")
            opstring = Console.ReadLine
            Console.WriteLine(ScrambleToLog(StringScramble))
            Process.Start("notepad", "./Logs/scramble.txt")
        End If
    End Sub
    Function StringScramble() As String
        Dim x As Integer = 0
        Dim output As String

        For Each character As String In opstring
            If character = "a" Then
                output = output + "cpw"
            End If
            If character = "b" Then
                output = output + "pwl"
            End If
            If character = "c" Then
                output = output + "lwb"

            End If
            If character = "d" Then
                output = output + "CV"
            End If
            If character = "e" Then
                output = output + "VC"
            End If
            If character = "g" Then
                output = output + "VnB"
            End If
            If character = "h" Then
                output = output + "Bgw"

            End If
            If character = "i" Then
                output = output + "epN"
            End If
            If character = "j" Then
                output = output + "qWt"
            End If
            If character = "k" Then
                output = output + "dlP"
            End If
            If character = "l" Then
                output = output + "poT"
            End If
            If character = "m" Then
                output = output + "erV"
            End If
            If character = "n" Then
                output = output + "poV"
            End If
            If character = "o" Then
                output = output + "zXN"
            End If
            If character = "p" Then
                output = output + "oIe"
            End If
            If character = "q" Then
                output = output + "QxG"
            End If
            If character = "r" Then
                output = output + "lDJ"
            End If
            If character = "s" Then
                output = output + "RyM"
            End If
            If character = "t" Then
                output = output + "kSf"
            End If
            If character = "u" Then
                output = output + "ioN"
            End If
            If character = "v" Then
                output = output + "xQI"
            End If
            If character = "w" Then
                output = output + "fZE"

            End If
            If character = "x" Then
                output = output + "tRe"
            End If
            If character = "y" Then
                output = output + "aAD"
            End If
            If character = "z" Then
                output = output + "jjK"
            End If

        Next

        Return output
    End Function
    Function ScrambleToLog(ByVal input As String) As Integer
        Dim fsvar As IO.FileStream
        If IO.Directory.Exists("./Logs/") Then
            Console.WriteLine("Logs Directory is there")
        Else
            IO.Directory.CreateDirectory("./Logs")
        End If
        Try
            Dim fs As IO.FileStream = IO.File.Create("./Logs/" + "scramble" + ".txt")

            fs.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(input), 0, System.Text.ASCIIEncoding.ASCII.GetBytes(input).Length)
            fs.Close()
            GC.Collect()
        Catch ex As IO.IOException
            Console.WriteLine(ex.Message & ex.InnerException.ToString)
            Return Errenous

        End Try

        Return OK
    End Function

End Module

What ya think? Type in a string and a scrambled one appears in notepad.

Are you looking for feedback on how to improve your code? If so, I have a couple of suggestions. Aside from that, what is the purpose of the program?

Sure some feedback is welcome.The purpose is to input a string and the program outputs a "scrambled" version of the string.
On the other hand you could use as a encoder and decoder. To decode would need string.contains i think. just swap around.
For example if contains "random characters" then output "a".

Just a few suggestions to start.

  1. Functions/Subs should be named to reflect their purpose. For example, GetLine should get the input and nothing more. Instead it gets the input from the user then calls CommandRun to do the scrambling. CommandRun should be named something less generic and should be called from Main instead of GetLine. GetLine could return the user input as a string. Perhaps a null string would terminate the program.
  2. Don't use the multiple If-Then-End If blocks. The way you code it each block must be evaluated for every letter. You could use a Select-Case, or even better, a dictionary, to do the mapping from single letters to their scrambled equivalents.
  3. The only prompt you provide is >>. How is the user to know to enter Hello or Scramble?
  4. Is opening a new Notepad window for each scrambled string really the best way to display output?
commented: Is that how Adam named the animals? +11

CommandRun is called in main in a loop. Well i displayed notepad so you can easily get the scrambled string.

CommandRun is called in main in a loop.

Here is your main loop. CommandRun is called from GetLine, not from "main in a loop".

Sub Main()
    InitConsole()
    While run = "Run"
        Console.Write(">>")
        GetLine()
    End While
End Sub

Two problems with displaying your output in Notepad

  1. It opens up a new Notepad window for every scrambled string
  2. The user has two switch between ypur app and Notepad to use the app

The only reason to send the output to another app is if that app is going to be used to further process the text, or if that app provides some other needed functionality not available in the console or a vb.net textbox.

Two further criticisms (one is cosmetic). You need to learn how to use whitespace to increase readability. You should also include comments. Code is for people to read/comprehend. It's only compiled code that is meant for computers.

I'm not trying to be harsh here. These are all the same types of comments that I got on my first computer science projects.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.