Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 9th, 2005, 10:40 PM   #1
IceNeo
Newbie
 
Join Date: Nov 2005
Posts: 1
Rep Power: 0 IceNeo is on a distinguished road
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?
IceNeo is offline   Reply With Quote
Old Nov 10th, 2005, 12:13 PM   #2
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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.
Rory is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:20 PM.

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