Hello im trying to create my first software :)

this is what im wanting to do

There is a text box with 1 command button

and inside the text box will store arrays

0-25

for example

cypher(0) = "0"
cypher(1) = "1"
cypher(2) = "2"
cypher(3) = "3"
cypher(4) = "4"
cypher(5) = "5"
cypher(6) = "6"
cypher(7) = "7"
cypher(8) = "8"
cypher(9) = "9"
cypher(10) = "10"
cypher(11) = "11"
cypher(12) = "12"
cypher(13) = "13"
cypher(14) = "14"
cypher(15) = "15"
cypher(16) = "16"
cypher(17) = "17"
cypher(18) = "18"
cypher(19) = "19"
cypher(20) = "20"
cypher(21) = "21"
cypher(22) = "22"
cypher(23) = "23"
cypher(24) = "24"
cypher(25) = "25"

Now each number represents a letter for example

0=A
1=B
2=C

and so forth

How would i get it to where whatever the person types in the submit button it will calculate there text and convert it from numbers to the specified letter

now indeed im very VERY VERY new to vb as tho im trying to learn it

But making it say

if cypher(0) = "0" then
msgbox("A")
endif

Would be rather annoying so if im correct to add all of the strings together wouldnt i type?

If cypher(0 - cypher(25)) Then

Now the question is how would i make it understand where cypher 0 is actually A?


Any help would be much appreciated

Dani AI

Generated

asked how to turn a textbox string like 01234 into abcde. correctly flagged that ambiguity arises when tokens can be one or two digits (0..25). Three practical parsing choices follow, with short VB examples and tradeoffs so the thread has ready options.

Single-character tokens (easy; only 0..9 supported)

Dim s As String, i As Long, out As String, ch As String, n As Integer
s = Trim$(Text1.Text)
out = ""
For i = 1 To Len(s)
  ch = Mid$(s, i, 1)
  If ch >= "0" And ch <= "9" Then
    n = Val(ch)
    out = out & LCase$(Chr$(65 + n))   '0 -> "a"
  End If
Next i
Text2.Text = out

Fixed-width two-digit tokens (unambiguous; every number must be 00..25)

Dim s As String, i As Long, token As String, n As Integer, out As String
s = Replace(Trim$(Text1.Text), " ", "")
out = ""
i = 1
Do While i <= Len(s)
  token = Mid$(s, i, 2)
  If Len(token) < 2 Then Exit Do
  n = Val(token)
  If n >= 0 And n <= 25 Then out = out & LCase$(Chr$(65 + n)) Else Exit Do
  i = i + 2
Loop
Text2.Text = out

Greedy variable-length parsing (no delimiters but can be ambiguous)

Dim s As String, i As Long, token2 As String, n As Integer, out As String
s = Replace(Trim$(Text1.Text), " ", "")
i = 1: out = ""
Do While i <= Len(s)
  If i < Len(s) Then
    token2 = Mid$(s, i, 2)
    n = Val(token2)
    If n >= 10 And n <= 25 Then out = out & LCase$(Chr$(65 + n)): i = i + 2 Else out = out & LCase$(Chr$(65 + Val(Mid$(s, i, 1)))): i = i + 1
  Else
    out = out & LCase$(Chr$(65 + Val(Mid$(s, i, 1))))
    i = i + 1
  End If
Loop
Text2.Text = out

Notes: validate tokens (0..25), strip separators/spaces, and choose the rule that matches the expected input. The delimiter/Split approach that mentioned is the simplest way to avoid ambiguities; fixed-width or greedy parsing are useful when delimiters are not desired but come with the tradeoffs shown above.

Recommended Answers

All 3 Replies

Okay, I think you are over thinking this...

Now, if I understand you correctly you want the numbers (0 to 25) to represent A to Z. So when the user enters any number from 0 to 25, clicks the button, you show the letter from A to Z.

Private Sub Command1_Click()
If IsNumeric(Text1.Text) = False Then
  MsgBox "You must enter a number from 0 to 25.", vbOkOnly + vbInformation, "Incorrect Input"
  Exit Sub
End If
If CInt(Text1.Text) >= 0 And CInt(Text1.Text) <= 25 Then
  MsgBox "The letter is " & CypherArray(CInt(Text1.Text)), vbOkOnly, "Good Input"
Else
  MsgBox "You must enter a number from 0 to 25.", vbOkOnly + vbInformation, "Incorrect Input"
End If
Exit Sub

Where

Option Explicit

Dim CypherArray(0 To 25) As String

Private Sub Form_Load()

CypherArray(0) = "A"
CypherArray(1) = "B"
'...
End Sub

Good Luck

Hi thankyou now it is what i need but the problem is

if i type 01234 it will only calculate 4 and not the rest if it did it would display

abcde

Do u have any idea on how i go about this

Problem with the logic you are trying to implement...

You do not have a delimeter to tell the difference between characters so if I entered 252423... do you see...

You need to have a delimeter like a comma 0,1,2,3,4 or 25,24,23 or a space or dash or something because any type of loop that iterates from the first character to the last character will always give you the representations of 0 through 9. Or you can just have the user enter one character at a time and then output what they enter into another textbox.

So, if you use a delimeter then you will need to look at...

Arrays (Dim MyStringArray() As String)
Split Function (MyStringArray = Split(Text1.Text, ",")
UBound
LBound
For Loop
Concatination (Text2.Text = Text2.Text & ...)


Good Luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.