Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If certain parties had their way that would be the accepted theory on how all rabbits came to be (only with a much more ancient magician).

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I think the question makes about as much sense as "what is the sound of one hand clapping". It is supposed to be profound but it's actually just nonsense.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I don't think you should be allowed to use that particular avatar until you have had a job that required supporting end-users (or working with engineers).

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Why not have the remaining letters in a dropdown combobox. Once a letter has been guessed you remove it from the combobox. That way there is no need to validate input.

Begginnerdev commented: True +6
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I have one suggestion (not necessarily a great one). Set a class variable in the main form (call it something like ShowForm). Set it to True initially. Have a timer on the main form and set the interval to 1000. In the timer Tick event do

Me.Visible = ShowForm

You can modify the value of ShowForm from another thread. The Tick event in the main form will do the actual show/hide. If you need the show/hide to be more reactive then shorten the Interval value.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Make all cells in row 1 blue.

For Each c As DataGridViewCell In DataGridView1.Rows(1).Cells
        c.Style.BackColor = Color.Blue
Next
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

"sender" is a generic object. I cast it to a Timer object so I can access the Enabled property. You could also do

Dim t As Timer = sender
t.Enabled = False
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

1000 milliseconds is one second so the statement stands.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The Timer.Tick event fires once every Interval milliseconds so you don't need a loop inside the handler. If you are counting down to zero then just stop the timer at that point.

Private Sub ... Handles timer1.tick

    If datetime.Minute > 0 Then
        datetime.AddSeconds(-1)
    Else
        DirectCast(sender,Timer).Enabled = False
    end if
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Simpler way is

Date.Today.ToString("yyyyMMdd")
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Index is a reserved word. You can either rename the field to something other than Index, or you can specify the field as [Index] as in

Dim myUpdateQuery As String = "UPDATE Sensor_Table         " & _
                              "   SET Equipment_ID = @id,  " & _
                              "       Location = @Loc,     " & _
                              "       Supervisor = @Sup,   " & _
                              "       Alarm_Start = @Astr, " & _
                              "       Alarm_Stop = @Asto   " & _
                              " WHERE [Index] = @LBIndex"
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I once left one comma out of a call (from FORTRAN) to an assembler routine. It caused all kinds of problems in a production system and took weeks to track down. It looked something like

CALL MDREAD(PARM1,PARM2,PARM3,,,,,,,,,,,,,,,TEMP)

If you are done then please mark this thread as solved.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

To validate a user you can use

Private LoggedIn As Boolean = False   'class level variable

Private Sub btnLogIn_Click(sender As System.Object, e As System.EventArgs) Handles btnLogIn.Click

    Dim con As New OleDbConnection("Provider=SQLNCLI10;Server=.\SQLEXPRESS;Database=mydb;Trusted_Connection=Yes;")
    Dim qry As String = "SELECT COUNT(*) FROM test3 WHERE username = ? and pswd = ?"
    Dim cmd As New OleDbCommand(qry, con)

    cmd.Parameters.AddWithValue("col1", txtUser.Text)
    cmd.Parameters.AddWithValue("col2", txtPswd.Text)

    con.Open()
    LoggedIn = cmd.ExecuteScalar <> 0
    con.Close()

End Sub

PS, with SqlClient you could do (named parameters)

Dim qry As String = "INSERT INTO test3 (username,pswd) Values(@user,@pswd)"
Dim cmd As New OleDbCommand(qry, con)

cmd.Parameters.AddWithValue("@user", "Barney")
cmd.Parameters.AddWithValue("@pswd", "Rubble")
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Wow. Marathon gaming session. Just got the computer back.

To the best of my knowledge, oledb lacks the parameter naming used by SqlClient so you have to use sequential parameters as in

    Dim con As New OleDbConnection("Provider=SQLNCLI10;Server=.\SQLEXPRESS;Database=mydb;Trusted_Connection=Yes;Connect Timeout=15;")
    Dim qry As String = "INSERT INTO test3 (username,pswd) Values(?,?)"

    Dim cmd As New OleDbCommand(qry, con)

    cmd.Parameters.AddWithValue("col1", "Barney")
    cmd.Parameters.AddWithValue("col2", "Rubble")

    con.Open()
    cmd.ExecuteNonQuery()
    con.Close()

You indicate the number of columns in the insert query by adding one "?" for each column. Each instance of cmd.Parameters.AddWithValue replaces the next "?" with an actual value. In your case the query would look like

Dim qry As String = "INSERT INTO ADCBaleCutterLC " & _
                    " (Old Formula,New Formula,Raw Material Name," & _
                    "  Raw Material Number,Batch Number,Preformed By," & _
                    "  Preformed by Date,Verified By,Verified By Date) " & _
                    "VALUES (?,?,?,?,?,?,?,?,?)"

and your calls to AddWithValue can stay the way they are. Note that you don't need the single quotes around the field names. Side note - I have always found that blanks in field names are a problem. I suggest replacing them with underscores or using camel case. ie

Raw_Material_Name
RawMaterialName

Let me know how that works.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Have you seen the second Berserk that was just released?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

When the boys get done playing their Christmas (networked) game I'll have a look. While I am waiting, could you possibly post the structure and types of the relevant database tables? If they are not overly large I'll recreate them here for testing.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

He's home from the hospital. Had surgery for a hernia last night.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Sorry. There were several shots of rum involved in the decision to post that and if it gets deleted I wouldn't be at all surprised.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I have a bit of a family thing at the moment (had to take my father-in-law to emergency) so I can't address the bigger issue just now, but I have a suggestion to simplify the username/password verification. Have the user enter both the username and password at the same time then do

sql = "SELECT * FROM SecAccess " & _
      " WHERE User = '" & txtUser.Text & "'" & _
      "   AND Pswd = '" & txtPswd.Text & "'"

If the number of records returned is zero then either the username or password was incorrect and the login should fail. This is a lot simpler than retrieving the record then comparing fields. Note that I use names for the textbox controls that reflect their function. Always a good practice.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I keep wanting to make a very rude joke here but it would be unbefitting of my fake honorific.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Thank you for not posting yet another database question ;-P

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try the following (requires Imports System.Text.RegularExpressions)

Dim s As String = "[1-5][8-10][10-20][21-31]"
Dim rex As New Regex("\[\d+-\d+\]")

For Each m As Match In rex.Matches(s)
    Dim range As String = m.Value.Substring(1, m.Length - 2)
    Dim nums() As String = range.Split("-")
    Debug.WriteLine(range & " = " & nums(0) & " to " & nums(1))
Next

The output is

1-5 = 1 to 5
8-10 = 8 to 10
10-20 = 10 to 20
21-31 = 21 to 31

This will work even if you have spaces or other delimiters embedded such as

[1-5] [8-10] [10-20]   [21-31]
[1-5],[8-10],[10-20],[21-31]
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It is complaining because the compiler has determined that if the loop doesn't get executed then pname will not have a value to return at line 80. By assigning a null string when you Dim pname you ensure that pname will have a value no matter what execution path is taken. However, you have another problem. The last few lines of your function look like

    Return (pname)

    dr1.Close()
    myConnection.Close()

End Function

The two lines following the Return can never be executed because of the Return statement. You should reorder the lines as

    dr1.Close()
    myConnection.Close()
    Return (pname)

End Function
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The regular expression

^\d+-\d+$

will match any string of the form

"#-#"

where "#" is any sequence of one or more digits. Once you have a match you can do a Split on the "-". For example

Dim s As String = "123-45"
Dim nums() As String = s.Split("-")

nums(0) will be "123" and nums(1) will be "45"

As for multiple intervals, was the example you gave "[1-5][8-10]" an actual string to parse in the exact format? It would be easier to parse if the separate ranges were separated by blanks or commas as in "12-15 23-49 102-119" or "12-15,23-49,102-119"

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You have to convert the string to a number first. In your case that would be

If CDec(CapAmount) >= 3000 Then
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It's the people who believe the world is coming to an end and decide to help the process along that worry me. It also bothers me that the end of the world (a least this week's version) is one day before my birthday. That blows. I guess I'll just have to start celebrating today.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Whether or not the specs are adequate depends a lot on what you want to do with it. Document editing doesn't require much power. Hardcore gaming is another matter.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

@MICHAEL - He's doing a post-doc in bio-physics.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

My Christmas gift is having my older son fly home from Long Island to spend the holidays with us. He's due here Wednesday evening.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

after finding all the AM in the listview1 to listview2 i will sum all their calls and visits by Month (January to December)

You already have that data in ListView2.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I want to find all the "AM" in my Listview1 to the Listview2

Still unclear. Do you mean you want to find all AM values from ListView1 that exist in ListView2 or do you want to find all AM values from ListView2 that exist in ListView1? Or do you want something else entirely?

Whatever it is that you want, how do you want to present the results?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I only put "some text" into the string for testing and to demonstrate that the text is still there inside the event handler. You can assign it any text you want at any point in your code. As tinstaafl points out, if you declare fo1 inside the handler it overrides the global copy with a local one and makes the global fo1 inaccessible.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Your code

Dim path As String = Directory.GetCurrentDirectory() & "\Setings.txt"
If File.Exists(path) Then
    Dim test1 As New System.IO.StreamWriter(path, False)
    test1.WriteLine(fo1)
    test1.Close()
    MsgBox(fo1)
Else
    Dim fs As FileStream = File.Create(path)
End If

will not write anything to the file if the file does not exist. Look at it in pseudo code

compose file name

if the file exists then
    write the contents of fo1 to the file
otherwise
    create the file but don't write anything to it

As I mentioned before, the WriteAllText will create the file if it doesn't exist so you don't need the test. The following seems to be what you intended

Imports System.IO

Public Class Form1

    Public fo1 As String = "some test text"

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

        Dim filename As String = Directory.GetCurrentDirectory() & "\test.txt"
        MsgBox("writing " & fo1 & " to " & filename)
        My.Computer.FileSystem.WriteAllText(filename, fo1, True)

    End Sub

End Class
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

how to find all data in my first listview to another

Can you please explain what you mean by this?

TnTinMN commented: and I thought I was the only one who din not comprehend that +6
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Perhaps you haven't put any text into fo1. In any case you don't need to have the If. We know the current directory exists and WriteAllText will create the file if it doesn't exist.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

ComboBox1.Text is the text from the currently selected item.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It helps if you post the error message, but to add items to a combobox the syntax is

ComboBox1.Items.Add(string value)

in your case

ComboBox1.Items.Add(myReader("Uname"))
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try removing the single quotes from around the numeric fields. You should only use single quotes for string type database values.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

So in pseudo code

For Each "Code Name" in the listview
    get all calls and visits for that Code Name
Next

and in real code that is

Dim query As String

For Each item As ListViewItem In ListView1.Items
    query = "Select * from [Calls and Visits$] where AM like '" & item.SubItems(1).Text & "%'"
    'execute the query and do something with the results
Next
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

So every time the user clicks on a line in the listview you want to append the value from the Code Name column to AccountName. The query

"Select * from [Calls and Visits$] where AM like '" & AccountName & "%'

will never match any records if AccountName contains more than one Code Name.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

At line 80 add the following

Debug.WriteLine(cmdUpdate.CommandText)

and post the output here. One further comment, a GOTO is a rarely used feature. There are only a small number of cases where a GOTO is warranted. This isn't one of them.

Replace

If conn.State = ConnectionState.Open Then
    GoTo cont
Else
    If conn.State = ConnectionState.Closed Then
        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source =C:\CGPA\e-CGPA Stat\e-CGPA Stat\bin\Debug\Scoredata.mdb;Persist Security Info=False"
        conn.ConnectionString = dbProvider & dbSource
        conn.Open()
        da.SelectCommand = New OleDb.OleDbCommand("SELECT * FROM 100Level1stSemester WHERE MatNO like '%" +     cmbMATNO.Text + "%'")
        da.SelectCommand.Connection = conn
        Dim mycomand As New OleDb.OleDbCommandBuilder(da)
        da.Fill(ds, "100Level1stSemester")
cont: If cmbCourseLevel.SelectedItem = "100 Level" Then

with

If conn.State <> ConnectionState.Open Then
    dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
    dbSource = "Data Source =C:\CGPA\e-CGPA Stat\e-CGPA Stat\bin\Debug\Scoredata.mdb;Persist Security Info=False"
    conn.ConnectionString = dbProvider & dbSource
    conn.Open()
    da.SelectCommand = New OleDb.OleDbCommand("SELECT * FROM 100Level1stSemester WHERE MatNO like '%" +     cmbMATNO.Text + "%'")
    da.SelectCommand.Connection = conn
    Dim mycomand As New OleDb.OleDbCommandBuilder(da)
End If

If cmbCourseLevel.SelectedItem = "100 Level" Then
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Please clarify what you want to do.

i want the AM Field to input in the AccountName

is unclear.

I need to get them and put it on a

Dim AccountName as String

You already have them. They are in the ListView.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try running msconfig and select "Safe Boot" and "Minimal" on the Boot tab. Then reboot. If that doesn't work then try selecting "Diagnostic startup" on the General tab.

Stuugie commented: As always, thank you very much +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You could just use a file browser control on form load and ask the user to select the appropriate *.accdb file. Of course, you'd have to ensure that the selected file is one that actually contains the correct tables. Remember to set the file mask to restrict the selection to accdb files.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The connection string will have parameters like

dbq (the file name)
uid (user ID)
pwd (password)

You can prompt the user for them the first time then save the resulting connection string (or the individual parameters) in Settings variables to preseve them between sessions. The actual connections string will also depend on whether you are using OLEDB, SQL, ADO, etc for access. For example, ADO might be

Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\temp\my.db;Uid=John;Pwd=Joshua;
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You may also run into problems with the field password. In some SQL implementations, password is a reserved word. If you must use this field name, you can use it in queries as [password].

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

How many times are you planning to ignore my request for you to post the output (in the debug window) from your code?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Since you already created the MySqlCommand object at line 2 you don't have to create it again. You can just replace line 18 with

myCommand.CommandText = comm

You made the same mistake with conn. You created a new instance when you declared it and again when you initialized it. You should be aware of the difference between the two statements

Dim conn As MySqlConnection
Dim conn As New MySqlConnection

The first statement creates a variable that can be used to refer to a MySqlConnection object but does not create the object. The second one declares the reference and creates the object. The second statement is equivalent to

Dim conn As MySqlConnection
conn = New MySqlConnection
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I tried the following code and it worked fine. Note that I didn't bother filling in complete code for all fields. This should be enough to give you the idea.

If My.Computer.FileSystem.FileExists(infofile) Then

    For Each line As String In System.IO.File.ReadAllLines(infofile)

        If Trim(line) <> "" Then

            Dim fields() As String = line.Split(":")

            Select Case UCase(fields(0))
                Case "DESCRIPTION"
                Case "FLOWERING"
                Case "HEIGHT"
                Case "SPREAD"
                Case "TEMP"
                Case "ZONE"
                Case "MOISTURE"
                Case "LIGHT"
                Case "CULTIVATION"
                Case "PROPAGATION"
                Case "DISEASE"
                Case "LANDSCAPE"
                Case "COMMON"
                    Debug.WriteLine("COMMON NAME = " & Trim(fields(1)))
                Case "LATIN"
                    Debug.WriteLine("LATIN NAME  = " & Trim(fields(1)))
                Case "COLOR"
                    Debug.WriteLine("COLOR       = " & Trim(fields(1)))
                Case Else
                    MsgBox("unknown field " & fields(0))
            End Select

        End If

    Next

End If
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Run the following code and post the output from the debug window

Private Sub ComboBox2_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged

myConnection = New SqlConnection(connectionstring)
myConnection.Open()

myCommand = New SqlCommand(" Select  Name FROM [Product_Name_List] Where P_Id='" & ComboBox2.Text & "'", myConnection)

Debug.WriteLine(myCommand.CommandText)

Dim dr As SqlDataReader = myCommand.ExecuteReader

ComboBox2.Items.Clear

While dr.Read()
    Debug.WriteLine(dr(0))
    TextBox8.Text = Val(dr(0)).ToString
End While

dr.Close()
myConnection.Close()

End Sub