Im suppose to make an application that tracks electric motors in a manufacturing plant. It needs to have
MotorID: Five-digit string, such as "02340"
Description: String
RPM: Integer, values in the range of 10 to 10000
Voltage: Integer, values in the range of 1 to 500
Status: String, three characters

Also

The status values are
ON: Motor is online and running
OFF: Motor is online, but not running
MNT: Motor is undergoing maintenance and cleaning
NA: Motor is not available

I was thinking about doing this part in radiobuttons

The application should be able to store at least 10 motor class objects in an array, create an input form in the application that allow users to input new motor records to be added to the array and create another form that displays all the motors in the array in a list box. This is what I got so far, I know its not much, but whats really puzzling me is how am I suppose to show all the data in the listbox in the second form.
This is whatI got for the first form

Public Class Form1
    Dim range As Integer = 0
    Dim voltage As Integer = 0
    Dim motor As String
    Dim Description As String
    Dim Status As String
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtrange.TextChanged

        If range > 10000 AndAlso range < 10 Then

        End If
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtvoltage.TextChanged


        If voltage > 500 AndAlso voltage < 1 Then

        End If
    End Sub

    Private Sub btnmotor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmotor.Click
        ' the button that allows you to go to the other form to see the listbox
        Form2.Show()


    End Sub

    Private Sub Bbtnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtrange.Click
        ' add the items to the listbox
        lb1.Items.Add(tb1.Text)
        lb1.Selectedindex = lb1.SelectedIndex + 1

    End Sub
End Class
Private Sub myCoolRadioButtons_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                                                                        Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged, RadioButton4.CheckedChanged
    ' the radio buttons for the status value
    If RadioButton1.Checked Then
        If RadioButton2.Checked Then
            If RadioButton3.Checked Then
                If RadioButton4.Checked Then
End Sub

and the second form I really dont know where to even start on that one. I know theres a lot of code missing, but if someone could help me out on a direction, that would help out a lot, thanks

Maybe this can help you out, lets say you have form1 and form2 and a timer in form2

So in form1 you have Textbox1 with any value lets say the text "VB .Net is Great"

So you want to show that text from that textbox1, so in form2 you do the following(btw you have textbox2 in form2)

On FormLoad
textbox2.Text =  form1.Textbox1.Text

That will copy the text from form1 to form2, but lets say that you need to refresh every 5 seconds

Add the timer component and set its properties to Enabled and Interval to 5000, every 1000 = 1Second

And double click the "Timer1" component on the form and add the following code

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        textbox2.Text =  form1.Textbox1.Text
End Sub

That will refresh the textbox2 every 5 seconds if there was a change in TextBox1 from form1

Was that any help?

>>...if someone could help me out on a direction...
See if this helps.

Public Class Form1
    Private myList As New ArrayList '// ArrayList to store info.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '// this is how you would add values to your ArrayList.
        myList.Add("abc 123 xyz")
        myList.Add("xyz 321 cba")
        '// Load ListBox with the values from ArrayList.
        ListBox1.Items.AddRange(myList.ToArray)
    End Sub
End Class

An ArrayList is basically a ListBox.

Ok I tried to use crankymeros code but I have no idea where to put it do I put it before the form1 code or in it? Also I put codeoreders code in and it works, but what im trying to do there is the user types info into 5 different textboxes, then clicks saves and them it saves, but does an array just sore info from what the person adds or is it permanent code? Basically what I am asking is, is there a way the user can add data in their 5 textboxes and then they hit save and it saves in the listbox or is the code right and im just over thinking everything and haven’t put in the rest of the code thatll make it work

>>but does an array just sore info from what the person adds or is it permanent code?
Hmm.. Good question.. Does an Array "sore"?:-/
.Will get back to you on that one, like never.:D

If you are referring to the ArrayList, it will not save when the app. closes unless you save the items in the ArrayList to a file and reload them back when loading the app..

To clear the ArrayList at any time, use myList.Clear() since the ArrayList is declared as "myList".

If you need to add values from your 5 TextBoxes, when adding items to the ArrayList, simply add the values of those TextBoxes.

Dim sTemp As String = TextBox1.Text & ":" & TextBox2.Text & ":" & TextBox3.Text & ":" & TextBox4.Text & ":" & TextBox5.Text
        myList.Add(sTemp) '// add to ArrayList.
        ListBox1.Items.Add(sTemp) '// add to ListBox.

Ok but where do I put that exactly because it keeps coming up with errors and also if you look at my code, you can see that my textbox 1 and 2 are to keep the values between a preset area, did I do this right or does there needs to be a lil more after the then statement and also how do I make a string only so big, like the motoredID is only suppose to be 5 digits long and nothing more or less, how can I do that?

Ok but where do I put that exactly because it keeps coming up with errors and also if you look at my code, you can see that my textbox 1 and 2 are to keep the values between a preset area, did I do this right or does there needs to be a lil more after the then statement and also how do I make a string only so big, like the motoredID is only suppose to be 5 digits long and nothing more or less, how can I do that?

Can you post your entire code for both forms with the code you currently have?

Never mind about the error code part lol, I figured out why it kept coming up with errors.
But Im still having trouble allowing the listbox to go to form 2 and load from there, crankymero has a code, but like I said I have no idea where that goes and I still don’t know about the set strings and integers, because the status one, has only four specific ones it can us and nothing else and I don’t know if the way I was setting up my integers where right or not. Heres what I got
Form1

Public Class Form1
    Dim range As Integer = 0
    Dim voltage As Integer = 0
    Dim motor As String
    Dim Description As String
    Dim Status As String
    Dim sTemp As String = TextBox1.Text & ":" & TextBox2.Text & ":" & TextBox3.Text & ":" & TextBox4.Text & ":" & TextBox5.Text
    Private myList As New ArrayList '// ArrayList to store info.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '// this is how you would add values to your ArrayList.
        myList.Add(sTemp) '// add to ArrayList.
        listbox1.Items.Add(sTemp) '// add to ListBox.
        '// Load ListBox with the values from ArrayList.
        ListBox1.Items.AddRange(myList.ToArray)
    End Sub
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

        If range > 10000 AndAlso range < 10 Then

        End If
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)


        If voltage > 500 AndAlso voltage < 1 Then

        End If
      
    End Sub

  

    Private Sub btnmotor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmotor.Click
        ' the button that allows you to go to the other form to see the listbox
        Form2.Show()


    End Sub

    Private Sub Bbtnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ' add the items to the listbox
        listbox1.Items.Add(listbox1.Text)
        listbox1.SelectedIndex = listbox1.SelectedIndex + 1

    End Sub
 
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()
        TextBox5.Clear()

    End Sub
End Class

and I dont really have any code for form 2, is that the reason why it wont go to form 2, because nothing there, except for a listbox

I believe your btnAdd should be the Button that adds Items to your ListBox.

Private Sub Bbtnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
      Dim sTemp As String = TextBox1.Text & ":" & TextBox2.Text & ":" & TextBox3.Text & ":" & TextBox4.Text & ":" & TextBox5.Text
      ListBox1.Items.Add(sTemp) '// add to ListBox.
    End Sub

Ok im still having problems with it working right, my code has changed a lot since my original post, so ill upload what I have now.

For the button 2, its only saying the message, I need it to be able to go into textbox1 and see if there is a 5 values there or not, if not an error message comes up. Heres what I got, all the code that I have changed and theres still nothing for form 2, all this is, is for form1. I still don’t know what to put in form2, besides a listbox, to allow it to show all the motors in it.

Public Class Form1

    Dim motorID As String
    Dim desripition As String
    Dim iMyCoolInteger As Integer
    Dim voltage As Integer
    Dim Status As String

    ' This is for my motor ID
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        btnrpm.Enabled = False
        With textbox3
            If .Text = "" Then
                Label1.Text = ""
                Exit Sub
            End If
            If IsNumeric(.Text) Then ' if .Text is Numeric and does not contain letters.
                If .TextLength = 5 Then ' check if length is 5.
                    If CInt(.Text) >= 10000 AndAlso CInt(.Text) <= 99999 Then ' check for value, if greater/less than...
                        Label1.Text = "This is a five digit code "
                        btnrpm.Enabled = True
                    Else
                        Label1.Text = "Value must be between 10,000 and 99,999"
                    End If
                Else
                    Label1.Text = "Not a 5 digit code, please renter a new one"
                End If
            Else ' if not Numeric.
                Label1.Text = "Only Numeric values will be accepted"
            End If
        End With
    End Sub

    ' This is to actually see if the values are in the range
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        MsgBox("Valid value in TextBox, proceed with code here...")

    End Sub

    ' my rpm text (textbox3) and button to see if it is between the values
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnrpm.Click
        If CInt(textbox3.Text) >= 10 AndAlso CInt(textbox3.Text) <= 10000 Then
            MsgBox("Sucess: Integer is within bounds")
        Else ' if not within bounds.
            MsgBox("Fail: Integer is less than or greater than preset bounds", MsgBoxStyle.Critical)
        End If
    End Sub

    ' my voltage text (textbox4) and button to see if it is between the values 
    Private Sub btnvoltage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvoltage.Click
        If CInt(textbox4.Text) >= 10 AndAlso CInt(textbox4.Text) <= 500 Then
            MsgBox("Sucess: Integer is within bounds")
        Else '// if not within bounds.
            MsgBox("Fail: Integer is less than or greater than preset bounds", MsgBoxStyle.Critical)
        End If
    End Sub

    ' My add button to the listbox
    Private Sub Bbtnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim sTemp As String = TextBox1.Text & ":" & textbox2.Text & ":" & textbox3.Text & ":" & textbox4.Text & ":" & textbox5.Text
        ListBox1.Items.Add(sTemp) '// add to ListBox.
    End Sub

    ' this is for the string to use as a desprition of the motor
    Private Sub textbox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textbox2.TextChanged
        ' dont know how to do the code for this
    End Sub
    ' this is for the status to see if characters are the correct ones to use or not
    Private Sub textbox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textbox5.TextChanged
        ' Validation for string containing: On Off Mnt Na
        If Not TextBox1.Text = "ON" Then ' If textbox doesnt contain ON then
            If Not TextBox1.Text = "OFF" Then ' If textbox doesnt contain OFF then
                If Not TextBox1.Text = "MNT" Then ' If textbox doesnt contain MNT then
                    If Not TextBox1.Text = "NA" Then ' If textbox doesnt contain NA then
                        MsgBox("Must be either: ON/OFF/MNT/NA, MsgBoxStyle.Exclamation") ' Error message displayed
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub btnstatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstatus.Click
        ' The textbox 5 is for this button, the set codes are already in the textbox 5, but everytime I try to type in one of the preset codes, example ON, it comes up with an error,
        ' when I try to start typing it, I would like to be able to put whats the 3 character code in, and check to see if it matches with one thats already be provided, if
        ' not an error message comes up
    End Sub
    'this is my listbox, dont know if any code is suppose to be here
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub
    ' this is to show form2
    
    Private Sub btnform2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnform2.Click
        Form2.Show()
    End Sub
End Class

And the application needs to be able to store atleast 10 different motors, but I haven’t got that far yet

>>For the button 2, its only saying the message, I need it to be able to go into textbox1 and see if there is a 5 values there or not
Check line 18 of your posted code, the code is there.

About adding items to a ListBox on another Form, use something like Form2.ListBox1.Items.Add(sTemp) '// add to ListBox on Form2.

Oh wow, I dont know why I put the code in the textbox instead of the button and I put the other code in but it came up with an error under, sTemp, it said it wasnt declared, could this be because it is suppose to be something else or do I need to declare it

If you leave it as is in line 61 of your previously posted code, for the Private Sub Bbtnadd_Click event, you should have no issues with sTemp not being declared when you need to add the value from it to your ListBox. That is, if the add items to ListBox code is somewhere within the same Sub.

after I posted what I said, I looked at the code and seen on line 12 it was the wrong textbox and thats why the error was coming up, it was suppose to be textbox1, not textbox3, now everything is working except two things. Im still having trouble with the add button and the form 2 button to come up with the listboxes
The code for the add button is still the same as when I posted the code, but the form 2 button changed

Private Sub btnform2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnform2.Click
        Dim sTemp As String = TextBox1.Text & ":" & textbox2.Text & ":" & textbox3.Text & ":" & textbox4.Text & ":" & textbox5.Text
        Form2.ListBox1.Items.Add(sTemp) '// add to ListBox on Form2.
    End Sub

These are the last two things I need for it to work. Everytime I hit the add button nothing happens and when I hit the form2 button it doesnt go to the form 2.
I do have a listbox on my form1 and form2 and when I deleted the listbox from form1, it came up an error under btnAdd for listbox1 it was under ListBox1.Items.Add(sTemp) '// add to ListBox.
Could that be the reason why its not allowing me to add the textboxs to the listbox and then over to form2?

btnAdd.Click event should have your btnform2.Click event code(for adding items to ListBox on Form2) and btnform2.Click should have a Form2.Show or Form2.ShowDialog (.ShowDialog displays the Form as a MsgBox, not allowing access to the Form it was called from, until closed).

wow it was in my original code and somehow I guess it got deleted, so I didnt think about it, but when I ran everything, everything ran fine, but when I closed the application and restarted it everything was erased (what I put in there), is there a way when I add something it automaticaly saves it and keeps it there until I delete it, even if I close the application it still will be saved or do I need to make a seperate button for this or does this part need to be in an array?

Save ListBox items to a File from Form1_FormClosing event, then use the Form1_Load to check if your File exists and if it does, to load the File into your ListBox.

If you need help with this new issue, start a new thread.

This article has been dead for over six months. Start a new discussion instead.