Reputation: 49
I need a bit help for this exercise regarding of using Join Method String Manipulation on Visual basic (VB.Net) where it deals with a ReDim Method.
The goal is to make a program that uses an inputbox.
The inputbox must be loop and shows one word at a time until it reaches the limit by pressing an assigned command.
In short there's no fixed loop, it will depend on the user on how many loops were covered.
Once done, join method works based on how many user inputs. Example: "Hello+Hi+testing+one+two+Three+four+five"
Here's my code which I couldn't figured out until now.
Dim inputtext As String
Dim counter As Integer
Dim language() As String
Do Until inputtext = "."
inputtext = InputBox("Enter the language as many as you can")
MsgBox(inputtext)
counter = counter + 1
Loop
ReDim Preserve language(inputtext)
inputtext = String.Join("+", language)
MsgBox(inputtext.ToString)
Upvotes: 2
Views: 292
Reputation: 3962
As Per your description I think What you need is as follow: See I have updated your Do..Until code block.
Dim inputtext As String=""
Dim counter As Integer =0
Dim language(0) As String
Do Until inputtext = "."
inputtext = InputBox("Enter the language as many as you can")
ReDim Preserve language(UBound(language) + 1)
language(counter) = inputtext
MsgBox(inputtext)
counter = counter + 1
Loop
' ReDim Preserve language(inputtext)
inputtext = String.Join("+", language)
MsgBox(inputtext.ToString)
Upvotes: 0
Reputation: 170
You should redim the array and add inputtext
inside the loop, otherwise you will only add the last value. You should also test for the termination value and only add if different:
Dim inputtext As String
Dim counter As Integer
Dim language() As String
Do Until inputtext = "."
inputtext = InputBox("Enter the language as many as you can")
If inputtext <> "." Then
MsgBox(inputtext)
ReDim Preserve language(counter)
language(counter) = inputtext
counter = counter + 1
End If
Loop
inputtext = String.Join("+", language)
MsgBox(inputtext.ToString)
Upvotes: 0