Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Assigning first character of variable into an array (http://www.programmingforums.org/showthread.php?t=6912)

IceNeo Nov 9th, 2005 10:40 PM

Assigning first character of variable into an array
 
What I am trying to do is a very simple encrypt/decrypt program. I must point out now that I am very new at this and this is my first working program.

I load a file into a text box and have the content of the textbox in a variable. I need to then assign the first 20 characters into an array, change the characters, then read the array backwards.

This is what I came up with:

:

FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
        Do While Not EOF(1)
            Dim InputArry(19) As String
            VarCount = 0
            Do While Not VarCount < 19 And Not EOF(1)
                InputArry(VarCount) = InputString(textFile, 1)
                ThisChar = Asc(InputArry(VarCount))
                Select Case ThisChar
                    Case 90
                        TempText = 65
                    Case 65 To 98
                        TempText += 1
                    Case 122
                        TempText = 97
                    Case 97 To 121
                        TempText += 1
                    Case Else
                        TempText = TempText
                End Select
                InputArry(VarCount) = Chr(TempText)
                VarCount = VarCount + 1
            Loop
            For AVar = VarCount To 0 Step -1
                StrO = StrO & InputArry(AVar)
            Next
        Loop
        FileClose(1)
        txtBox.Clear()
        txtBox.Text = StrO


Any suggestions? What am I doing wrong?

Rory Nov 10th, 2005 12:13 PM

Well your code looks like it (could) work, could you post the exact error message (I expect its an array bounds error). However, this is a distinctly VB6-ish approach: remember strings are arrays of characters, your function creates, marshals, and destroys loads of unecessary objects. Put Option Explicit and Strict on for starters to see where, and leave them on. The .NET way of doing this would be creating a stream processor, and using a stack for the reversal. However if this is your first program, I'd suggest mastering something like ROT13 first.


All times are GMT -5. The time now is 4:27 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC