![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Nov 2005
Posts: 1
Rep Power: 0
![]() |
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 = StrOAny suggestions? What am I doing wrong? |
|
|
|
|
|
#2 |
|
Expert Programmer
|
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|