john.knapp 25 Posting Whiz in Training

Thanks all, my code now works! I will plan to add error handling later.

Bad idea! If you had error handling the first time, you would have been able to figure out that your DataAdapter wasn't working and why...

Get in the habit of typing Try and tabbing twice in every new procedure you write.
Going back and adding error handling is a major PITA!

Begginnerdev commented: I add it on the first draft! +6
john.knapp 25 Posting Whiz in Training

While you're at it, put some error handling in...

Imports System.Data.SqlServerCe
Public Class Edit_Sensor_Form
    Try
        ' Shared variables  
        Dim con As SqlCeConnection = _
                New SqlCeConnection("Data Source=|DataDirectory|\Database1.sdf")
        Dim myDA As New SqlCeDataAdapter
        Dim myDataSet As New DataSet
        Dim DataGridView1 As New DataGrid
        Dim ret As New SqlCeDataReader
        Dim mySelectQuery As String = "Select * FROM Sensor_Table"
        Dim SelectedIndex As Integer

        Private Sub Edit_Sensor_Form_Load(sender As System.Object, _
                                            e As System.EventArgs) _
                                            Handles MyBase.Load

            SelectedIndex = My.Forms.Form1.ListBox1.SelectedIndex
            Dim cmd As New SqlCeCommand(mySelectQuery, con)
            con.Open()
            myDA.SelectCommand = cmd
            myDA.Fill(myDataSet)
            TextBox1.Text = _
            IIF(IsDBNull(myDataSet.Tables(0).Rows(SelectedIndex)("Equipment_ID")), _
            "",myDataSet.Tables(0).Rows(SelectedIndex)("Equipment_ID"))

        End Sub

    Catch ex as Exception
        MsgBox(ex.Message)
    End Try

End Class
TnTinMN commented: good point +6
john.knapp 25 Posting Whiz in Training

Known issue.
First hit on a Google Search....

Click here for workaround.

Begginnerdev commented: Great, John! +6
john.knapp 25 Posting Whiz in Training

Do you actually have 15 physical Serial Ports? I don't know for certain, but I suspect that you cannot just arbitrarily decide to give yourself another serial port without the appropriate hardware - at least not using this method. I don't see any mention of a "virtual" port in the docs at MSDN...

You can get a list of available ports using
Dim myAvailablePorts as String() = System.IO.Ports.SerialPort.GetPortNames()

Be aware however, per MSDN:

The port names are obtained from the system registry (for example, HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM). If the registry contains stale or otherwise incorrect data then the GetPortNames method will return incorrect data.

john.knapp 25 Posting Whiz in Training

I'm a simple cop trying to piece something together

we can tell... :) it's all good though.

You're actually doing a good job clearly labeling the textboxes - I can tell at a glance what they mean - props to you

SO I'm having trouble going back and forth with this loop between the textboxes and the checkboxes.

If you have moe than one or two of those CheckBox statements, you shold put all the checkbox code after the loop finishes, best practice is to let the loop do it's thing, and then set the other controls afterward.

If there are enough of those DataGrid value checks (say 3 or more), another array or a dictionary/list would be less code to write, even better would be to enfold that logic into the array loop or use a dictionary with named keys. Post your whole textbox/datagrid code block - we'll take a look at putting it into a dictionary.

FYI, the main difference between a dictionary and an array is that arrays store a range of objects accessed randomly by index - a Dictionary/List stores a range of key/value pairs. So in your case we would code the dictionary somewhat like this:

DISCLAIMER
This is untested code, it is entirely likely there are logic errors in here that will
put you in an infinite loop! Code for demo purposes only!

Private Sub DataGridView1_CellClick(ByVal sender As Object, _
                        ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
                        Handles DataGridView1.CellClick
        Try …
john.knapp 25 Posting Whiz in Training

If you step through the code, what is the value of e.Index on Rows 58 & 59?

You should use a loop for that incremental count too. You'd have to put the textboxes into an array in the order you want them filled in, then just loop 0 to 59.

Something like:

Dim myTextBoxes() As string = {frmImpound.lblRev.Text, _
                                frmImpound.txt_agency_case_number.Text, _
                                frmImpound.txtImpoundNumber}

For i As Integer = 0 To UBound(myTextBoxes)
    While i < DataGridView1.Rows.Count
        myTextBoxes(i).Text = DataGridView1.Item(i, e.RowIndex).Value.ToString
        If i = 52 AndAlso DataGridView1.Item(i, e.RowIndex).Value.ToString = "1" _
                                            Then frmImpound.cbOther2.Checked = True
        ' debug line here, to see where we're at with that index issue
        If i = 58 
            Debug.Print DataGridView1.Rows.Count
            Debug.Print e.RowIndex
        End If
    End While
Next
RobRTaylor commented: Awesome, thanks +0
john.knapp 25 Posting Whiz in Training

Definitely the query string. I didn't rewrite the whole project though... :)

TnTinMN commented: if they would just read what we post. +0
john.knapp 25 Posting Whiz in Training

If you're using SQLExpress you have to specify that as part of the SQL instance name.
For example: "Server = WH306UT\SQLExpress"

I just ran a test using your code, but specifying my machine and SQL instance successfully.

See code below, change server and instance name to match your system (of course!):

Private Sub CreateDSN()

    ' NOTE: This procedure creates a User DSN, **NOT** a System DSN
    '
    Dim strDriver As String
    Dim strAttributes As String
    strDriver = "SQL Server"
    Dim catalog As String = "Hospital_DSN"
    '
    ' NOTE THE INSTANCE NAME
    strAttributes = "SERVER=WH306UT\SQLExpress" & Chr(0)
    'strAttributes = "SERVER=" & machName & "" & Chr(0)
    '
    ' THESE ARE YOUR CONNECTION ATTRIBUTES BELOW
    strAttributes = strAttributes & "DSN=" & catalog & Chr(0)
    strAttributes = strAttributes & "DESCRIPTION=DSN For HOSPITAL" & Chr(0)
    strAttributes = strAttributes & "DATABASE=TEST_DB" & Chr(0)
    strAttributes = strAttributes & "TRUSTED_CONNECTION=YES" & Chr(0)

    ' IF YOU WANT TO SEE THE ODBCAD32.exe DIALOG 
    ' PASS THE WINDOW HANDLE OF THIS FORM AS THE FIRST ARGUMENT
    ' EX: SQLConfigDataSourceW(Me.Handle, 1, "SQL Server", strAttributes)
    '
    Dim iReturn As Integer = PInvokeImports.SQLConfigDataSourceW(CType(0, IntPtr), _
                                                    1, "SQL Server", strAttributes)
    If CBool(iReturn) Then
        MsgBox("DSN setup complete successfully.", _
                CType(MsgBoxStyle.OkOnly + MsgBoxStyle.Information, MsgBoxStyle))
    Else
        MsgBox("DSN setup can not complete successfully.")
    End If
End Sub

PInvokeImports Class (in a separate code file):

Imports System.Runtime.InteropServices

Public Class PInvokeImports
    'Const ODBC_ADD_DSN = 1           ' Add data source
    'Const ODBC_CONFIG_DSN = 2        ' Configure (edit) data source
    'Const ODBC_REMOVE_DSN = 3        ' Remove data source …
TnTinMN commented: Nice Job finding and using the function +5
john.knapp 25 Posting Whiz in Training

I still highly recommend Try..Catch blocks in all your procedures.

john.knapp 25 Posting Whiz in Training

Post the code you have so far.

john.knapp 25 Posting Whiz in Training

Scope_Identity() is always the primary key value of the last insert operation in the current user scope. You need a primary key on your data table or you're going to have issues. I'm too tired at the moment to think about whether that is causing issues in this particular query, but I think not - as long as you have a limited amount of data that you're working with anyway - say 10-15 numbers for testing.

For "Your_Identity_Column_Name" I entered the column name "Phone" which is what I am trying to match.

Nope. Use whatever you called your primary key column in the input : [Input].[ID]

john.knapp 25 Posting Whiz in Training

Try this mod to your code

        ' clear the imagelist so we don't have extras
        ImageList1.Images.Clear()
        ' you need this next line to keep the ListView from flickering!
        ListView1.BeginUpdate()

        Dim di As New IO.DirectoryInfo(LocationA.Text)

        For Each fi As IO.FileInfo In di.GetFiles("*")
            ' provide a default icon in case we can't extract one
            Dim icons As Icon = SystemIcons.WinLogo
            ' set that default as the new listitem's icon
            Dim li As New ListViewItem(fi.Name, 1)
            ' check ImageList to see if we have an icon for this file type
            If Not (ImageList1.Images.ContainsKey(fi.Extension)) Then
                ' we don't, let's try to get one
                icons = System.Drawing.Icon.ExtractAssociatedIcon(fi.FullName)
                ImageList1.Images.Add(fi.Extension, icons)
            End If
            icons = Icon.ExtractAssociatedIcon(fi.FullName)
            ImageList1.Images.Add(icons)
            ListView1.Items.Add(fi.Name, fi.Extension)
        Next

        ' all done, redraw the listview
        ListView1.EndUpdate()
john.knapp 25 Posting Whiz in Training
Have you ever tried using the String.Compare method for a case-insensitive string comparison?

The documentation on MSDN for the overloaded method:

'Declaration
Public Shared Function Compare ( _
    strA As String, _
    strB As String, _
    ignoreCase As Boolean _
) As Integer

states
Compares two specified String objects, ignoring or honoring their case, and returns an integer that indicates their relative position in the sort order.

At first glance, this looks like exactly what we want, doesn't it?

There's a catch... look at the documentation again, especially the last phrase
and returns an integer that indicates their relative position in the sort order

The integer value returned is 0 if the strings are equal, if you try to use this comparison in an If statement the return value is False.

For example:
dim stringA as String = "lowercase", stringB as String = "Lowercase"
String.Compare(stringA, stringB, True)
returns 0, which is a Boolean False.

There is a solution! String.Equals to the rescue!

stringA.Equals(stringB, StringComparison.OrdinalIgnoreCase)
returns True - As an added benefit, this is already a Boolean value!

There are lessons to be learned here:

  • Always, always, always, read the documentation! (ReadTheFineManual)
  • When you think you understand what it says, go read it again, write some example code and step through that code
  • When your code doesn't "behave" - go read the docs again...
john.knapp 25 Posting Whiz in Training

Items have multiple entries in [Transaction Details]. That is throwing off the totals. Especially the Ttype = NULL rows. You might want to rethink your database design - especially if you can't query from it... :)

Try this and see if it works for you.

SELECT Description.Dgroup AS Description,
        COUNT(Item.IID) As TotalCount,
        [Under Repair]
FROM [Description] JOIN [Item]
    ON Description.DeID = Item.DeID
    JOIN (SELECT Description.Dgroup AS Description, 
                    SUM(CASE WHEN 
                        [Transaction Details].Ttype = 'Repair' 
                        THEN 1 ELSE 0 END) AS 'Under Repair'
            FROM [Transaction Details]
                JOIN [Item] ON [Transaction Details].[IID] = [Item].[IID]
                JOIN [Description] ON Description.DeID = Item.DeID
            GROUP BY DGroup) AS tmp
    ON Description.Dgroup = tmp.Description
WHERE [Under Repair] IS Not Null
GROUP BY DGroup, [Under Repair]
john.knapp 25 Posting Whiz in Training

Here's some source code at MSDN for the Data Connection Dialog that was
?packaged/affiliated/an add-in? for Visual Studio 2005. Alternatively, there's this project at CodeProject.com.

john.knapp 25 Posting Whiz in Training

Use a nested For loop.
please step through this code, I wrote it off the cuff without the IDE, and without testing, it may have undesired "features"

' this will get you started, but you'll need to figure out
' how you're going to handle the rest when you run out of
' straight number to letter substitutions
For i = 0 to 51                             ' only 26 lower and 26 upper
    For char = 65 to 122                    ' ascii values for A-Z, [ \ ] ^ _ `, a-z
        If ((char > 90) AND (char < 97))    ' skip the non-letter characters
            char = 97
        End If
        TextBox4.Text.Replace(i , Chr(char))
    Next
Next
john.knapp 25 Posting Whiz in Training

Assuming your character limit is a "hard" stop, the following occurs to me:

  1. Item One: Re-use the same template instead of recreating number(x) templates
  2. Item Two: Make sure you put the bookmark back per previous link
  3. Item Three: Break the text up into "chunks" and send each chunk to a sub-procedure

Off the top code below:

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) _
                                                            Handles btnOk.Click

        'Fill the textbox first for testing
        Dim myNewLongString As String = vbNullString
        For i = 0 To 9
            myNewLongString = myNewLongString + New String(CChar(CStr(i)), 900)
        Next
        Me.txtOffense1.Text = myNewLongString

        'working variable
        Dim strToChunk As String
        'adjust chunksize as needed
        Dim chunksize As Integer = 900
        'variable to hold textbox character count
        Dim txtlength As Integer = txtOffense1.TextLength
        'how many chunks we talking about?
        Dim numberChunks As Integer = CInt(txtlength / chunksize)
        'create an array to hold the text chunks
        Dim txtchunks(0) As String

        strToChunk = Me.txtOffense1.Text

        If (strToChunk.Length > chunksize) Then
            For i = 0 To numberChunks
                If UBound(txtchunks) < i Then
                    ReDim Preserve txtchunks(i)
                End If
                If strToChunk.Length > chunksize Then
                    txtchunks(i) = Strings.Left(strToChunk, chunksize)
                    strToChunk = strToChunk.Substring(chunksize - 1)
                Else
                    txtchunks(i) = strToChunk
                End If
            Next
        Else ' less than 900 characters in original chunk
            'txtchunks(i) should still be 0 at this point
            txtchunks(0) = strToChunk
        End If

        For i = 0 To UBound(txtchunks)
            SendDataToWord(CStr(txtchunks(i)))
        Next
        ' all done with txtchunks
        Erase txtchunks

    End Sub

    Sub SendDataToWord(stringIn As String)
        ' dummy procedure
    End Sub
mrbungle commented: Great code- thanks! +2
john.knapp 25 Posting Whiz in Training

so much syntax, so little brainpower...
Thank you Reverend

john.knapp 25 Posting Whiz in Training

str = Left(str, str.length -4)

john.knapp 25 Posting Whiz in Training

This has already been done, and even with 'www.downforeveryoneorjustme.com'. Click Here to see the thread.

By the way, I did a Google search using "vb.net check if website is down" and that was the first hit...

john.knapp 25 Posting Whiz in Training

Google has a custom search API, Click Here for the overview.

What are your specific requirements?
How many websites do you need to be able to view?
How much of each website do you need to "block"?
Is this for a class project, just killing time, or what?