Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String value to Integer ?? 1

Status
Not open for further replies.

allyeric

Programmer
Mar 14, 2000
104
CA
This is a pretty simple question, but I just can't get it to work!&nbsp;&nbsp;I have a string value,as in a password such as A2nf45RS and I would like to convert that value to an integer.&nbsp;&nbsp;I need that integer value in order to do a randomize on another field.&nbsp;&nbsp;This is what I have, but it always returns a value of &quot;0&quot; <br><br><br>sFrmPass = Val(frmPassword.txtPassword.Text)<br><br><br>Its Monday and my brain is just not functioning I guess&nbsp;&nbsp;:eek:)<br><br>I thank you in advance for any help.<br>
 
Aa long as the first character in the provided string is a number Val() will return a number. It will not be anything meaningfull as applied above. It will <b>not</b> create <i> (numerically) encoded</i> values from a character string.<br><br><u>You'll need (much) more code to accomplish this in a reliable way.</u><br> <p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href= > </a><br>
 
You will probably get a an overflow if you try to convert a long string to an integer. This snippet doesn't return a number that can be re-translated to a string but, since you just want to randomize with it, try something like:<br><br>Pass$ = frmPassword.txtPassword.Text<br>For C = 1 to Len(Pass$)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R = R + Asc(Mid$(Pass$, C))<br>Next<br><br>R will hold the sum of the Ascii values contained in the password.<br><br>Hope this helps.<br> <p> <br><a href=mailto: > </a><br><a href= temporary Vorpalcom home page</a><br>Send me suggestions or comments on my current software project.
 
Alt225 ;<br><br>What I am reading above is probably a better response than my response using the questions' narrowest interpretation. However, in real life, if a user were to enter a <i>different</i> string containing the same characters in a different order, ie. <i>S</i>A2nf45<i>R</i>, then the return value for 'R' would be the same as that for A2nf45RS. The whole scheme goes out the window !&nbsp;&nbsp;This will not a workable solution! <p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href= > </a><br>
 
That's right. He just wanted a number to seed the RND.<br>Try:<br><br>Dim R as Currency<br>Pass$ = frmPassword.txtPassword.Text<br>For C = 1 to Len(Pass$)<br>&nbsp;&nbsp;&nbsp;&nbsp;Ra$ = Str$(Asc(Mid$(Pass$, C)))<br>&nbsp;&nbsp;&nbsp;&nbsp;If Len(Ra$) &lt; 3 then Ra$ = &quot;0&quot; + Ra$<br>&nbsp;&nbsp;&nbsp;&nbsp;'assuming the user hasn't entered Chr$(1-9)<br>&nbsp;&nbsp;&nbsp;&nbsp;Ran$ = Ran$ + Ra$<br>Next<br>R = Val(Ran$)<br><br>I can think of at least two other ways to perform a conversion without adding much more code.<br><br>Keep it simple.<br> <p> <br><a href=mailto: > </a><br><a href= temporary Vorpalcom home page</a><br>Send me suggestions or comments on my current software project.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top