Begginnerdev 256 Junior Poster

First off, it is bittersweet to be ahead of your class. Bitter due to having a higher chance to make errors on code that you can't fully understand, but sweet because you can use the time to improve your coding/understanding of the language and logic.

As for this:

   Public Function ReadLine(ByVal lineNumber As Integer, ByVal lines As List(Of String)) As String
       Return lines(lineNumber - 1)
   End Function

If the value of lineNumber is equal to zero or greater than the size of the list + 1 you will always get this error.

You can fix this with something like this:

  Public Function ReadLine(ByVal lineNumber As Integer, ByVal lines As List(Of String)) As String
       If lineNumber - 1 > lines.Count - 1 Then Return "lineNumber was to large for the list: " & (lineNumber - 1) & " > " & lines.Count
       Return lines(lineNumber - 1)
  End Function

If you are trying to retreive the last element in the list, try this:

Public Function ReadLine(ByVal lines As List(Of String)) As String
    If lines.Count <=0 Then 
        Return String.Empty
    Else
        Return lines(lines.Count - 1)
    End If
End Function 

This will return the last element of the list, being the last line read in from the text file.

Begginnerdev 256 Junior Poster

Are you trying to read/write from/to the same file?

Begginnerdev 256 Junior Poster

Do you have the file open in Excel while trying to run the process?

Something has control of the file at that time.

Begginnerdev 256 Junior Poster

The correct syntax would be:

'Read/Split all lines.
 While sr.Peek <> -1
     lstAllLines.Add(sr.ReadLine().Split(",").ToList)
 End While
Begginnerdev 256 Junior Poster

I use code very close to this to manipulate CSV files all of the time.

A CSV file is treated as a text file; it just has formatting that you would not see usually.

What error are you getting for your csv?

Be sure to close the StreamReader/Writer with you are finished with your operations.

sr.Close()
sr = Nothing
sw.Close()
sw = Nothing
Begginnerdev 256 Junior Poster

What mail client are you using?

Outlook?
Mozilla?
Live?

Begginnerdev 256 Junior Poster

You can add an attachment to an email by doing the following:

Dim oMail As New Net.Mail.MailMessage
oMail.Attachments.Add(New Net.Mail.Attachment("Path to my file"))

As for saving a copy local, you could parse the email into a text file and save it.

Begginnerdev 256 Junior Poster

You will want to open the file, read/split all lines, then rehash them with your delimiter:

This code is written on the fly.

Try
    'Reader/Writer for file operations.
    Dim sr As New StreamReader("PathToMyFile")
    Dim sw As New StreamWriter("PathToFile")

    'Lists for storage
    Dim lstAllLines As New List(Of List(Of String))
    Dim lstFinal As New List(Of String)

    'Read/Split all lines.
    Do While sr.Peek <> -1
        lstAllLines.Add(sr.ReadLine().Split(",").ToList)
    End While

    'Cycle through and delimit
    For Each lst As List(Of String) in lstAllLines
      Dim str As String = String.Empty
      For i = 0 to lst.Count - 1
          'Check to make sure you are not on the last element.
          If lst(i) < lst.Count - 1 Then
              str &= lst(i) & "|"
          Else
              str &= lst(i)
          End If
      Next
      lstFinal.Add(str)
    Next

    'Write all lines
    For Each s As String in lstFinal
        sw.WriteLine(s)
    Next
Catch ex As Exception
    MsgBox(ex.ToString)
End Try
Begginnerdev 256 Junior Poster

Are you writing this software for your android, or to run on a PC?

If you are writing for an android, you will need to learn the language. (modified Java)

As for it not working, are you getting an error - or nothing happens?

Begginnerdev 256 Junior Poster

I was having problems with this concept quite a long time ago, but found this article.

Begginnerdev 256 Junior Poster

If you have an exchange server that allows you to bounce emails, just use the server ip and port to send a SMTP email.

For example:

Sending SMTP Mail in VB.NET

Begginnerdev 256 Junior Poster

You will be working with the Graphics class.

You will need to define if you want the worms to be fixed variable, random, or mixed.

I am assuming you wanted mixed: certain width and colour

Here is an article that covers the basics on how to drawn in vb.net.

Begginnerdev 256 Junior Poster

You will have to elaborate on what an "Artistic Warm" is, friend.

Begginnerdev 256 Junior Poster

Is the pc on the same network? If so, just use the IP of the host machine.

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\serverName\shareName\folder\myAccess2007file.accdb;"

Here is a wonderful reference for connection strings.

Begginnerdev 256 Junior Poster

Change:

Dim dr As New DataRow = ds.Tables("tblRegCust").Rows.Add

To:

Dim dr As DataRow = ds.Tables("tblRegCust").Rows.Add

And change:

dat = Nothing

To:

da = Nothing

My appologies. This is what happens when you type code on the fly. :)

Begginnerdev 256 Junior Poster

The question is, are all columns from the database present in the list view?

ie: If you have more columns in the ListViewItem than that exists in the ListView - the data will not render.

Begginnerdev 256 Junior Poster

The code snippet:

For i = 0 To ds.Tables(0).Rows.Count - 1
    For j = 0 To ds.Tables(0).Columns.Count - 1
        itemcoll(j) = ds.Tables(0).Rows(i)(j).ToString()
    Next
    Dim lvi As New ListViewItem(itemcoll)
    Me.lvPrinterSetup.Items.Add(lvi)       
Next

Is loading values into a string array, then into a listview item, just like this:

For i = 0 to ds.Tables("MyData").Rows.Count - 1
    With ds.Tables("MyData")
        Dim lvi As New ListViewItem

        lvi.Text = .Rows(i)("PrinterID")
        lvi.SubItems.Add(.Rows(i)("PrinterName"))
        lvi.SubItems.Add(.Rows(i)("PrinterNumber"))
        lvi.SubItems.Add(.Rows(i)("PrinterLocation"))
        lvi.SubItems.Add(.Rows(i)("PrinterAddress"))

        ListView1.Items.Add(lvi)
    End With
Next

It just enumerates on the index, instead of referencing the column name.

Begginnerdev 256 Junior Poster

I know one that you can clean that code up: DataAdapters

For instance:

Private Sub IssueInsert()
    Dim cmd As New SQLCommand("SELECT * FROM registered_cust_tbl",myCon)
    Dim da As New SQLDataAdapter(cmd)
    Dim ds As New DataSet
    Try
        da.Fill(ds,"tblRegCust")

        If IsNothing(ds.Tables("tblRegCust")) = False Then
            Dim dr As New DataRow = ds.Tables("tblRegCust").Rows.Add

            'Put your column names here:
            dr("customer_fname") = firstNameTb.Text.Trim
            dr("customer_lname") = lastNameTb.Text.Trim
            dr("customer_DoB") = DoBtb.Text
            '........

            ds.Tables("tblRegCust").Rows.Add(dr)

            da.UpdateCommand = New SQLCommandBuilder(da).GetUpdateCommand()
            da.Update(ds)
        Else
            MsgBox("Nothing was returned from the table.")
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)
    Finally
        cmd = Nothing
        dat = Nothing
        ds = Nothing
    End Try        
End Sub

This will be protected against SQL injection attacks.

Begginnerdev 256 Junior Poster

Have you insured that the ListView is set to Details view, and has columns added to it?

If you have not added columns to it, try this:

For i = 0 To ds.Tables("MyData").Columns.Count
    'This will create a column with a default width of 100.
    lvPrinterSetup.Columns.Add(ds.Tables("MyData").Columns(i).ColumnName, 100)
Next

You also need to check for code that might be clearing the listview.

Begginnerdev 256 Junior Poster

The safest way to do so, if you have not solved the problem, would be to use Properties.

For Example:

Public Class Form1  
    Public Property TextString As String
        Get
            Return TextBox1.Text
        End Get
        Set(value As String)
            TextBox1.Text = value
        End Set
    End Property    
End Class

Public Class Form2
    Private Sub btnSendTo_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSendTo.Click
        Form1.TextString = "This is a test."
    End Sub
End Class
TnTinMN commented: something along the lines of great minds think alike ;>) +8
Begginnerdev 256 Junior Poster

Either was is just as effecient as the other. I just learned by using DataSets. It is a personal preference kind of thing.

The advantage a dataset has is that you can reference it and use it later for updating data.

Begginnerdev 256 Junior Poster

Are you sure the path is correct?

You can verify it by doing this:

If File.Exists("C:\Users\Abdueie\Desktop\BMS\Bridge Asset Management\Bridge Asset Management\bin\Debug\Adigrat.accdb") Then MsgBox("It is there!") Else MsgBox("Path May Be Wrong!")
Begginnerdev 256 Junior Poster

Is the listview set to view.Details?

You can set this in the designer, and in the code.

As far as loading data goes, the code snippet looks fine to me.

I do not use readers as much though. I use DataSets/DataAdapters.

You can do the same with them by:

Dim da As New SQLDataAdapter(cmd)
Dim ds As new DataSet

da.Fill(ds,"MyData")

IF IsNothing(ds.Tables("MyData")) = False And ds.Tables("MyData").Rows.Count > 0 Then

    For i = 0 to ds.Tables("MyData").Rows.Count - 1
        With ds.Tables("MyData")
            Dim lvi As New ListViewItem

            lvi.Text = .Rows(i)("PrinterID")
            lvi.SubItems.Add(.Rows(i)("PrinterName"))
            lvi.SubItems.Add(.Rows(i)("PrinterNumber"))
            lvi.SubItems.Add(.Rows(i)("PrinterLocation"))
            lvi.SubItems.Add(.Rows(i)("PrinterAddress"))

            ListView1.Items.Add(lvi)
        End With
    Next
End If
Begginnerdev 256 Junior Poster

No problem friend!

Please do not forget to mark the question as solved.

Begginnerdev 256 Junior Poster

I suspect the "Bridge Number" part of your query.

You may have to wrap your field name with [ brakets.

For example:

cmd = New OleDBCommand("DELETE FROM Adigrat WHERE [Bridge Number]=@BridgeNumber",conn)
cmd.Parameters.AddWithValue("@BridgeNumber",bridgenumber)

cmd.ExecuteNonQuery()
Begginnerdev 256 Junior Poster

What exception is being thrown?

You have never stated it.

Begginnerdev 256 Junior Poster

Be sure to reference the library in the project.

Go to My Project > References > Add New > Navigate to the correct verison (14.0 I think) then add.

Begginnerdev 256 Junior Poster

Before issueing the update, check to see if the parameters are passing in correctly:

MsgBox(cmd2.CommandText)
cmd2.ExecuteNonQuery
Begginnerdev 256 Junior Poster

Open the access database, and open the table in datasheet view.

Once the table is open, look for the current record you are editing - see if the value that is being pulled in is correct.

Begginnerdev 256 Junior Poster

Have you verified that the number you are putting in the textbox is indeed the correct customer ID from the table?

Begginnerdev 256 Junior Poster

If the CustomerIDTextBox is accessable, that will be the value you need.

If the problem is that the text box is on another form, you can create a Public Property in that form's class and call it from the other form:

Public Class Form1
'....
    Public Property CustomerID as String
        Get
            Return CustomerIDTextBox.Text
        End Get
        Set(value As String)
            CustomerIDTextBox.Text = Value
        End Set
    End Property
End Class

Public Class Form2

    Private Sub btnUpdate.Click(ByVal sender as object, ByVal e as eventargs) Handles btnUpdate.Click
        Try

            Dim cmd2 As OleDBCommand("UPDATE tbl_Customers SET cust_Company=@cust_Company WHERE CustomerID=@CustomerID",conn)
            cmd2.Parameters.AddWithValue("@cust_Company",Cust_CompanyTextBox.Text)
            cmd2.Parameters.AddWithValue("@CustomerID",Form1.CustomerID) 'GETTING THE PROPERTY VALUE

            cmd2.ExecuteNonQuery()
        Catch ex As Exception
              MsgBox(ex.ToString)
        End Try
    End Sub
End Class

I hope this clarifies for you.

When you say tieing it to it, are you wanting to pull in the new values into a dataset?

Begginnerdev 256 Junior Poster

If your table structure looks something like:

customerID|customerCompany|customerLocation
Identity  |    text       |     text

Then when you issue update, it is already tied to the same row.

If the CustomerIDTextBox.Text is the correct value that is.

If you are pulling the values into the form , as you stated earlier, I am assuming you have a select statement?

If so, you can use that ID for the customer ID

Begginnerdev 256 Junior Poster

That is correct, assuming that customer ID is a unique value in that table.

If customer ID appears more than once in that column/ in that table - the statement will update all of those records.

It is always a smart thing to use an identity column or something of the sort.

Begginnerdev 256 Junior Poster

You will need a WHERE clause and a unique value;

For example:

"UPDATE tbl_Customers SET cust_Company=@custCompany WHERE cust_ID = 3"
Begginnerdev 256 Junior Poster

I'm sorry. The correct syntax will be:

"UPDATE tbl_Customers SET cust_Company=@custCompany"

That's what I get for absent mindedly typing responses.

Begginnerdev 256 Junior Poster

You just simply need to change your query:

   'SQL Update statements will not have an INTO clause.
   Dim UpdateCommand As New OleDb.OleDbCommand("UPDATE tbl_Customers(cust_Company) VALUES(@custCompany)", con)
Begginnerdev 256 Junior Poster

Just create a DataSet to hold the table in:

Private Function GetTable() As DataSet
    Dim con As New Data.OleDB.OleDBDataAdapter("YourConnectionStringHere")
    Dim da As New Data.OleDB.OleDBDataAdapter(New Data.OleDB.OleDBCommand("SELECT * FROM tbl_Employees",con)
    Dim ds As New DataSet
    Try
        da.Fill(ds,"tbl_Employee")
        'To reference the table, use ds.Tables("tbl_Employee")
        If ds.Tables("tbl_Employee") IsNot Nothing Then Return ds Else Return New DataSet
    Catch ex As Exception
        MsgBox(ex.ToString)
    Finally
        con.Close()
        con = nothing
        da = nothing
    End Try
End Function

As for the array (If absolutely wanted.)

Dim strAr As New List(Of String)
'To Add a new item to the list, do the following...
strAr.Add("MyString")
'As all arrays, the list will be zeroth based. 
'First index will be 0 and so on...
Begginnerdev 256 Junior Poster

You have to update the datasource of the datagrid view.

A DataAdapter will do the job:

Dim da As OleDB.OleDBDataAdapter(New OleDB.OleDBCommand("SELECT * FROM TabelName",MyDbConnection)) 'Make sure the connection passed in is open.
da.UpdateCommand = New OleDBCommandBuilder(da).GetUpdateCommand()' If not you will have to open the connection before calling this line.
da.Update(MyDataGridViewSource) 'Where MyDataGridViewSource is a DataSet
Begginnerdev 256 Junior Poster

Do you have code that draws the chart, or are you using some kind of office interopt to draw it?

Begginnerdev 256 Junior Poster

Do you have code that fires on exit click?

If so: I would start there.
Step through the code and see where it stops.

If not: I would start with Cleaning/Rebuilding the Solution.
Build > Clean
Build > Rebuild

It has worked for me a few times.

Begginnerdev 256 Junior Poster

You can do as Jim has said and shave a VERY small amount of time off by placing everything inside of the If statement:

If MsgBox("Do you want to Delete?", MsgBoxStyle.YesNo, "Confirm") = MsgBoxResult.Yes Then
    Dim cmd As new OleDBCommand("",con)
    cmd.CommandText = "DELETE FROM [" & EBU2DB_LOB & "] " _
            & " WHERE Brand  = ? " _
            & "   AND LOB    = ? " _
            & "   AND Months = ? "
    cmd.Parameters.AddWithValue("@Brand ", Form_Month_End_Report.Combo_LOB_Brand.Text)
    cmd.Parameters.AddWithValue("@LOB   ", Form_Month_End_Report.Combo_LOB_LOB.Text)
    cmd.Parameters.AddWithValue("@Months", Form_Month_End_Report.Combo_LOB_Month.Text)
    If con.State = ConnectionState.Closed Then con.Open()
    cmd.ExecuteNonQuery()
End If

This will only create the command and set the command text when you want to delete the item.

Reverend Jim commented: Also yep! +12
Begginnerdev 256 Junior Poster

Can you have something like this:

Do While True
    strVarName = ds.Tables("MyTable")(iRow)("varname")
    strVarValue = ds.Tables("MyTable")(iRow)("varvalue")
    If Execute(strVarName, strVarValue) Then Exit Do
    'If the function returns True, the loop will exit.
Loop

Private Function Execute(ByVal sVarName As String, ByVal sVarValue As String) As Boolean
    'Your code here
End Function

Or am I grossly misunderstanding the question?

Begginnerdev 256 Junior Poster

If you are wanting the button - you can try to reference the last clicked button to figure out which one was clicked.

Example:

Dim btnLastClicked As New Button

Private Sub Button2_Click(sender As Object,e As EventArgs) Handles Button1.Click
    btnLastClicked=CType(sender,Button)
    'btnLastClicked will now reference Button1
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    btnLastClicked = Ctype(sender,Button)
    'btnLastClicked will now reference Button2
End Sub

Just food for thought.

Begginnerdev 256 Junior Poster

As Jim has stated, listviews are zero based.

Therefore:

List.Items(currentTimer - 1).SubItems(List.Items(currentTimer - 1).SubItems.Count).Text = ""

Should be:

List.Items(currentTimer - 1).SubItems(List.Items(currentTimer - 1).SubItems.Count - 1).Text = ""
Begginnerdev 256 Junior Poster

You can simplify this code with something like this:

Public Class Main
    Dim rnd As New Random
    Dim iNumberToGuess As Integer

    Private Sub btnEnter_Click(sender As Object, e As EventArgs) Handles btnEnter.Click
        Try
            If IsNumeric(txtAttempt.Text) Then
                If CheckGuess(CInt(txtAttempt.Text)) Then
                    Dim res As DialogResult = MsgBox("Do you want to exit the application?", MsgBoxStyle.YesNo, "Congratulations!")
                    If res = MsgBoxResult.Yes Then
                        'Place your code here.
                    ElseIf res = MsgBoxResult.No Then
                        iNumberToGuess = GetRandom()
                        ClearAll()
                    Else
                        MsgBox("Could not determine result!")
                    End If
                Else
                    txtAttempt.Text = Missed(CInt(txtAttempt.Text))
                End If
            Else
                MsgBox("Only numbers can be entered to guess.")
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Function CheckGuess(ByVal iGuess As Integer) As Boolean
        If iGuess = iNumberToGuess Then Return True Else Return False
    End Function

    Private Function GetRandom() As Integer
        Return rnd.Next(0, 30)
    End Function

    Private Function Missed(ByVal iInVal As Integer) As String
        If iInVal > iNumberToGuess Then
            Return "You are to high!"
        Else
            Return "You are to low!"
        End If
    End Function

    Private Sub ClearAll()
        'Place clear code here.
    End Sub
End Class
Begginnerdev 256 Junior Poster

Can you please post the block of code that is throwing the error?

Seeing the code would help bring a better understanding of your problem.

Begginnerdev 256 Junior Poster

ListViewItems are zero based.

Therefore 0 will be column one, and 1 will be column two.

Begginnerdev 256 Junior Poster

You will have to keep track of total time elapsed that the application has ran.

You can't assume the app will stay loaded into memory for 10 days - therefore you will have to look into storing the total time it has spent running.

You can use Registry Keys, Serialized files, text files (Easy to "hack") to store the time.

You pull the time into the application on load and start the timer, save the total + instance time on exit.

You check the time on load to see if time = 10days and if so delete the file...

OR

Keep the date/time stored that the application launched the First launch and check to see if the current date is 10 days...

Begginnerdev 256 Junior Poster

If you are using datasets - You may have the problem of opening and closing a connection the same table multiple times.

When I do this I declare one connection that will stay open until all operations are completed on that table - then close.

If this is not the case - one thing that you can do is to create a test in the dll solution to check the code in debug to see if it is doing something undesirable.

Begginnerdev 256 Junior Poster

It appears that in the coversion from VB.NET to C# that the code is not a working C# code.

Try something like this:

private WebResponse CreateDirectory(string sDir)
{
    try {
        FtpWebRequest req = FtpWebRequest.Create(sDir);
        req.Credentials = new NetworkCredential("username", "passw");
        req.Method = WebRequestMethods.Ftp.MakeDirectory;
        WebResponse Response = req.GetResponse;
        return Response;
    } catch (Exception ex) {
        MessageBox.Show(ex.ToString());
        return null;
    }
}

When you say "This does not work either" do you mean that the code doesn't compile or that the code does not behave as wanted?