DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   Help with my program! (http://www.daniweb.com/forums/thread201309.html)

Manikyr Jul 2nd, 2009 3:42 pm
Help with my program!
 
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!

scsachira Jul 3rd, 2009 2:09 am
Re: Help with my program!
 
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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

adatapost Jul 3rd, 2009 2:20 am
Re: Help with my program!
 
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

scsachira Jul 3rd, 2009 9:23 am
Re: Help with my program!
 
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

adatapost Jul 3rd, 2009 9:36 am
Re: Help with my program!
 
scsachira,

Use bb code tags. Read this http://www.daniweb.com/forums/announcement118-3.html

scsachira Jul 3rd, 2009 9:45 am
Re: Help with my program!
 

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

scsachira Jul 3rd, 2009 9:57 am
Re: Help with my program!
 
I'm new here...
Please ignore my faults...
Is that code solve your problem...
However thanks for Advice..


All times are GMT -4. The time now is 6:21 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC