Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 18th, 2007, 07:14 PM
Registered User
 
Join Date: May 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to loop a command for a string length?

I know this is probably quite basic, but I'm trying to create a code that will take a string of text from a text box and then convert it into a string of ASCII codes.

The idea is that I'm trying to create a password within a spreadsheet and that unless Textbox1.Text = Converted Value X, the code will skip straight to the end.

All I'm missing is the ability to loop the code so that it will move on to the next letter of the string and add it to a saved value. (Is that at all possible? To merge a value for d say, so d of first letter then d of second etc.. I'm sorry if I don't make much sense right now, my brain's fried trying to figure this one out.

I'll try to lay it out..
Code:
dim crypt as string
crypt = Textbox1.Text
'Asc(1st letter or crypt)
'Repeat with next letter until end of string
'password = entire ASCII conversion of crypt for as long as the value of crypt may be
If anyone can tell me how to do this, it'd be greatly appreciated, I've been working on it for a while now and I can't get my head round it. Everything else has clicked into place for me now, just not how to make it move onto the next character and to link them up.

Thanks in advance.

 
Old May 20th, 2007, 07:29 PM
Registered User
 
Join Date: May 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi LordJaffa,

I wrote the code with a seperator ("_") to seperate the Ascii codes. You can remove this if you like:

Code:
Public Sub AsciiCode(ByRef sTextBox As String)
    Dim lLen As Long, i As Long
    Dim sTEMP As String

    lLen = Len(sTextBox)

    ' Loop through sTextBox and store Ascii code in sTEMP
    For i = 1 To lLen
        sTEMP = sTEMP & Asc(Mid(sTextBox, i, 1)) & "_" ' Leave out the "_" if you prefer
    Next

    ' Remove extra "_"
    sTEMP = Left(sTEMP, Len(sTEMP) - 1)

    sTextBox = sTEMP
End Sub

Public Sub TEST()
    Dim sTEST As String
    sTEST = "This is a TEST"
    Call AsciiCode(sTEST)
    Debug.Print sTEST
End Sub
Hope this helps
-Joseph

 
Old May 25th, 2007, 06:36 PM
Registered User
 
Join Date: May 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Right, I couldn't use what you put directly, because to be frank, I'm not very good at understanding what other people have put (no offence, it happens all the time) but I used your code and it works!

The only problem I have now is I want my value for the textbox conversion to be stored permenantly.

However, as I don't understand most of your code there, I don't know if any of it does in fact store the string I'm using.

Here's what I've got so far, please could someone tell me what I would need to add to store it, and what to use to recall it for verification.

Code:
Public Sub CommandButton3_Click()
Dim crypt As Variant
Dim L As Integer
Dim tpp As String
L = Len(TextBox1)
crypt = TextBox1.Text

Dim i As Integer
For i = 1 To L
tpp = tpp & (Asc(Mid(crypt, i, L)))
Next
End Sub

So I want Textbox1 to be able to be cleared without losing "tpp" and for "tpp" to be able to be recalled in another command.

Thanks in advance, and many thanks to Malik641 for being a big help with this so far.

Edit: Would it be possible to export my resulting string (tpp) into a module and recall it from there? Just a wild though..
 
Old May 31st, 2007, 01:56 PM
Registered User
 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You would probably be able to store it for the life of the application using a Global variable. It will not store it permanently. To store it permanently you would need to have a separate routine to write the password, encrypted, to a textfile and a routine to call that textfile and decrypt the password.

 
Old May 31st, 2007, 04:28 PM
Registered User
 
Join Date: May 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, I went with a new option, put it into a label on the worksheet and removed it's visibility. Problem solved and all my macros are working properly. Thanks for the help!

 
Old June 5th, 2007, 10:20 PM
Registered User
 
Join Date: May 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

LordJaffa,

Sorry to come back so late!

I'm glad to see you have what you are looking for! Good luck with the rest of the project.






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fix string length Ivanchan Excel VBA 2 July 26th, 2007 08:55 AM
string-length problem alapati.sasi XSLT 3 July 4th, 2007 10:08 AM
Chap 3, "Length of String" richajos BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 February 25th, 2006 08:38 PM
Changing length of string automatically ryanvdm2 Classic ASP Basics 5 September 4th, 2005 06:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.