I need help with my visual basic assignment!
The program has to include an array with at least two strings.
In the layout there should be one label which explains what the user has to do, for example "Write two strings" (or x strings) and one label that shows the latest inputed string.
There should also exist a textbox which the user use for inputs of strings.
One button to add the strings in the array.
There have to be one meny with the selctions "Show" (that shows the last string from the array and displays it in one label) and "Exit" (to shut down program).

I have read my book correctly, but I doesnt seem the get it anyway!
Can some one explain to me step by step what to do, because I dont know where to start! Everything is up-side-down for the moment!

Please, help me!

Kind regards!

Recommended Answers

All 6 Replies

I don't understand exactly what u mean...
But try this code... May be it'll help you..
Add this code to command button..
TextBox1 is input text box..
Label1 is shows output you asked for...

In the text box two stings must be separated from coma(",")..
If u don't understand...
Give this text to textbox in runtime.."Sachira,Chinthana,Jayasanka"
Then click command button..
You'll see what happen..

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Label1.Text = ""
Dim x As Array
x = TextBox1.Text.Split(",")
For i As Int32 = 0 To x.Length - 1 Step 1
Label1.Text = Label1.Text & Environment.NewLine & "String " & i + 1 & " = " & x(i)
Next
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Manikyr,

Read the following announcement:
1. Homework rules
2. How to use BB code tags?

scsachira,

Use bb code tag. Source code must be surrounded with code tags.

Use ReDim statement to resize an array:
When use click on Add button, value from TextBox1 will be added to an array and a label show a recent added string

....
    Dim Ar() as String
    ...
    Sub AnyHow()
        Dim I as Integer=0
        if IsNothing(Ar) then
             Redim Ar(i)
       else
            i=Ar.Length
             ReDim Preserve Ar(i)
        End If
        ...
        ...
    End Sub

May be this code solve your problem..
In here Label2 show recently added string...
Label1 show both strings...

Dim Ar() As String
.........

    Private Sub DoIt() 

        If Ar Is Nothing Then
            ReDim Ar(0)
            Ar = New String() {TextBox1.Text}
        ElseIf Ar.Length = 2 Then
            ReDim Ar(0)
            Ar = New String() {TextBox1.Text}
        Else
            ReDim Preserve Ar(Ar.Length)
            Ar.SetValue(TextBox1.Text, 1)
        End If

        Label2.Text = TextBox1.Text

        Label1.Text = ""

        For i As Int32 = 0 To Ar.Length - 1 Step 1
            Label1.Text = Label1.Text & Environment.NewLine & "String " & i + 1 & " = " & Ar(i)
        Next

    End Sub
Dim Ar() As String
.........

Private Sub DoIt() 

If Ar Is Nothing Then
ReDim Ar(0)
Ar = New String() {TextBox1.Text}
ElseIf Ar.Length = 2 Then
ReDim Ar(0)
Ar = New String() {TextBox1.Text}
Else
ReDim Preserve Ar(Ar.Length)
Ar.SetValue(TextBox1.Text, 1)
End If

Label2.Text = TextBox1.Text

Label1.Text = ""

For i As Int32 = 0 To Ar.Length - 1 Step 1
Label1.Text = Label1.Text & Environment.NewLine & "String " & i + 1 & " = " & Ar(i)
Next

End Sub

I'm new here...
Please ignore my faults...
Is that code solve your problem...
However thanks for Advice..

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.