thanx

What I'm trying to do is have a text box for a user to enter a name into, then extract each letter from that box in order, turn letters into numbers, then screw with that to come up with an apparently random number for later verification (see if the name matches the number). My question is- how can I get each number into a seperate variable, then change it into a number (and all letters be pre-defined, so it's always the same number for each letter)  Thx in advance.

 

 

P.S., don't be too technical, I've only been using this for about 2 months

P.P.S, I have Visual Basic 6 version 6.0.8169 Enterprise Edition




Answer this question

thanx

  • Ryno1234

    Module Module1

    Sub Main()

    Dim a As String = "this is a test"

    Dim count As Integer = a.Length

    Dim Contents(count) As Char

    Dim iindex As Integer = 0

    For Each c As Char In a

    Contents(iindex) = c

    iindex += 1

    Next

    '//Confirm The contents of the array

    For i As Integer = 0 To count - 1

    Console.WriteLine(Contents(i))

    Next

    End Sub

    End Module


  • Kent_8848

    mike1942f wrote:

    There is no need to put the letters or numbers in an array (but you can if you want, just DIM to len(w$) with a local array. You can just take the letters out one at a time and add them up.

    That's exactly what I want to do! Extract each letter one at a time and put it into a varaible. R u able to post the code to do that please Then, how can you recall the variable/ how do you chose the variables name Thanx so much guys!



  • Marius Bancila

    I'm glad that mid$ serves your purposes.

    This will make a single variable that can refer to any character in a string.

    However the approach above will give you an array of variables - each of which can refer to an individual character.

    So they are slightly different.

    Also in .net you can use Letter1 = Textname.substring(x,y) method

    But either way, I'm glad your resolved.


  • Rosen

    Just more simply, what would be the code to a) put those letters under a variable                         and b) puth each letter under seperate variables to manipulate later. Not so worried about the encoding right now. Just want to put each letter in the text box under seperate variables. Thx

  • Brian MCSD

    Found exactly what I needed the other day. Using

    letter1 = mid$(txtname, x, y)

    x is the number of characters from the beginning you start at

    y is the number of characters after the first (x)

    then used if statements to turn each letter into a number

    thanx for your help!



  • Mahmood Salamah

    Oh - OK. These forums are not for VB6 questions. Try www.codeproject.com. I'm not trying to be difficult, I actually don't know the answer for VB6, otherwise I would tell you and THEN point out that you should find a VB6 forum.



  • Justdeserves

    I have been programming in BASIC for 40 years, but it wouldn't surprise me if MS changed what I am about to suggest.

    Every letter has a code assigned to it - ASCII or other.

    for c= 1 to len(w$): code=ASC(mid$(w$,c,1)

    This will give numbers like 32 for a space, 65 for A, and 97 for a. This code number is what you use to look up your numbers loaded as below. There is no need to put the letters or numbers in an array (but you can if you want, just DIM to len(w$) with a local array. You can just take the letters out one at a time and add them up.

    Put your collection of numbers in a data statement, with or without the letters.

    Data a, 10,b ,11,c , 16, d , 24,e , 21, f, 3 etc.
    Data 10,11, 16, 24, 21, 3 etc.

    If you put in the letters, you will read them a pair at a time READ A$,A and use the code of the letter to assign to a static array. Easier to keep track of which letter is which each number. If you use just the numbers, then you have to count or use a REM to keep track.

    For c=1 to 26 : READ convert(c) : next


  • George Clingerman

    I actually gave you enough information to code it. To learn more type in the following (with added DIM statements as your version of VB requires)

    A$="Hello world. HELLO WORLD! This is a TEST."
    FOR C = 1 TO LEN(A$) : ASCII = ASC(MID$(A$,C,1)) : AC$=MID$(A$,C,1)): PRINT ASCII; AC$ : NEXT

    Which will produce a column of letters and numbers starting like this:
    72 H
    100 e

    Study these to see how the functions work. Your version of VB will have similar if not identical String functions (the ones with the dollar sign)


  • SoccerSarah

    You can iterate over the string one letter at a time, foreach will probably support this, array notation certainly will. You can use the length of the string to create an int array before you start, and move the values in there in a loop. If you want to have your own lookup, create a letter to number dictionary in your code.



  • juliam

    Thanx. Sounds good, but since the help files for my VB6 are corrupted (or something), do you have the actual code, since I can't look it up Thx again!!

    This is the code I have so far. How can I change it to make each letter typed into txtregname be held in a variable seperately Thanks so much!

    Private Sub cmdcalculate_Click()
    lblnewcode = regname
    End Sub

    Private Sub cmdexit_Click()
    End
    End Sub

    Private Sub txtregname_Click()
    regname = Val(txtname.Text)
    a = 10
    b = 11
    c = 16
    d = 24
    e = 21
    f = 3
    g = 15
    h = 1
    i = 14
    j = 7
    k = 13
    l = 23
    m = 22
    n = 26
    o = 16
    p = 2
    q = 25
    r = 12
    s = 17
    t = 18
    u = 8
    v = 4
    w = 20
    x = 5
    y = 19
    z = 9

    End Sub



  • thanx