hi i'm new to vb. how can i write to iterate while loop till the end of the string.. can any one help please...

Dani AI

Generated

Good suggestions from and — scanning a string character-by-character is the right approach and the loop index must be advanced each pass. The error that “Len is not declared” is usually an environment/reference issue (the Len helper is part of the Visual Basic runtime), not a logic bug in the loop. (learn.microsoft.com)

When writing modern VB code (VB.NET) it is clearer and safer to use the .NET string API instead of legacy free‑functions. The runtime String exposes a Length property and strings can be enumerated directly; both avoid any dependency on legacy helpers. Example patterns:

' iterate with For Each (VB.NET)
For Each ch As Char In myString
    ' process ch
Next

' or zero-based indexed loop
For i As Integer = 0 To myString.Length - 1
    Dim ch As Char = myString(i)
    ' process ch
Next

The Length property is the documented .NET way to get a string's character count; note that Mid/legacy helpers are one‑based while String indexing and Substring are zero‑based. (learn.microsoft.com)

If the environment still reports that Len (or Mid, Left, Right) is not declared, common causes and fixes are:

  • the host does not expose the Visual Basic runtime (some UWP or restricted hosts omit those helpers); migrate to String.Length/Substring in that case. (stackoverflow.com)
  • the project/host needs an explicit reference/import of the Visual Basic runtime (Microsoft.VisualBasic.dll / Microsoft.VisualBasic namespace) to use the legacy helpers; adding that reference restores Len/Mid. (stackoverflow.com)

Useful diagnostic data when troubleshooting: the exact error text, the project type (VB.NET console/WPF/UWP/VBA/BluePrism), and whether Microsoft.VisualBasic.dll is referenced — that information makes it straightforward to recommend the correct fix.

Recommended Answers

All 6 Replies

Please explain in more detail what you want to do because I really don't understand what your saying

If you are reading the characters in a string then

    Dim aChr as String
    Dim X as Integer

    For X = 1 to len(MyString)
            aChr = mid$(MyString,1 ,1)
            'do code
    Next X

If you are reading from a file that will be different.

len function is not working...
its considering it as an array...

thank you......

make it
mid$(achr, X, 1)
that should work better

sir problem is not with mid$
but with len(string)

when i write like that, it shows an error that len not delared


Never Forget to increment the value of X. in you case it will always return the same character because start position is not incremented. so don't forget to put X=X+1 after mid$(achr, X, 1)


try this

Dim str As String
Dim i As Integer
i = 1
str = "String"
While i <= Len(str)
MsgBox Mid(str, i, 1)
i = i + 1
Wend

hope this helps you . . .

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.