?
Solved

String Characters

Posted on 2005-03-06
3
Medium Priority
?
196 Views
Last Modified: 2010-05-02
Team,

I am trying to devise some code that will enable me to do some simple encoding and decoding.

I have a text box and when the user enters Characters, words or number's I would like to allow the user to click an encode button so that 'each' character is encoded (ASCII Code - 1) and is displayed in the text box as characters.

Then the user is able to hit another command button and Decode the characters back to there original state (Encoded ASCII + 1).

I am finidng it difficult to get each individual character and applying the Encode method on it, any help wold be greatly appreciated.

Thanks in advance,
Akkas

0
Comment
Question by:Akkas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 13471537
Try this:

   Create a form with one textbox (txtValue) and two command buttons (cmdEncode and cmdDecode), then add the following code to it:

Private Sub cmdEncode_Click()

    txtValue.Text = Encode(txtValue.Text, True)

End Sub

Private Sub cmdDecode_Click()

    txtValue.Text = Encode(txtValue.Text, False)

End Sub

Private Function Encode(ByVal pString As String, ByVal pEncodeFlag As Boolean) As String

    Dim sEncoded As String
    Dim iDir As Integer
    Dim i As Integer
   
    If pEncodeFlag = True Then
        iDir = 1
    Else
        iDir = -1
    End If
   
    For i = 1 To Len(pString)
        sEncoded = sEncoded & Chr(Asc(Mid(pString, i, 1)) + iDir)
    Next i
   
    Encode = sEncoded

End Function


Hope this helps.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 13471542
Ooops, just reread the question, change:

        If pEncodeFlag = True Then
            iDir = 1
        Else
            iDir = -1
        End If

To:

        If pEncodeFlag = True Then
            iDir = -1
        Else
            iDir = 1
        End If
0
 

Author Comment

by:Akkas
ID: 13471708
Quality!!!! You've done this before, no doubt!!!!

I came up with the code below whilst I was waiting for a repsonse,

Private Sub cmdEncode_Click()
Dim Encoded As Variant
 Word = txtValue.Text
'Add Characters to variable
 For Ascii = 1 To Len(Word)
    Encode = Asc(Mid(Word, Ascii, 1)) - 1
    Encoded = Encoded & Chr(Encode)
  Next Ascii
   txtValue.Text = Encoded
End If
End Sub

You have used a function which requires minimal code for each command button, Im new to VB6.

Thanks and its a great help!
Akkas

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question