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

Consider it moved.

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

When you run task manager and look at the performance meter what is the CPU usage on your system while the keybord is slow? Is it high usage?

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

You can use Access for the database back end and do all the programming through vb. Likewise you can install (free) MS SQL Express (which would be better in my opinion) and use that. I would not use Excel. Depending on which version of vb you are using you might want to reconsider which forum to post in. This is the forum for vb 4, 5 and 6. The vb.net forum is more current. Which are you using?

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

@akeera - Please start a new thread and show us you have made some effort by providing some code.

@Don - I'll say it one more time. If you specify integrated security then you don't need a userid and password. You are authenticated by your windows logon.

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

The @ values are just place holders. The names, such as @phone, don't have to be the same as (or even remotely close to) the actual fields in the database. It's just good practice to make them the same or similar. As I pointed out in the example, when using OleDb you use ? in the actual query and each successive AddWithValue replaces the next ? with the actual value you provide. When using SqlClient the placeholders in the query must have the same name as that given in the AddWithValue and the parameters can be added in any order.

If you were to code a query such as

qry = "INSERT INTO mytable (LastName, FirstName) VALUES(" _
    & "'" & txtLast.Text & "'," _
    & "'" & txtFirst.Text & "')"

and the name just happened to be Conan O'Brien then your actual query string would be

INSERT INTO mytable (LastName, FirstName) VALUES('O'Brien','Conan')

which would be invalid because of the single quote in the last name. If, however, you used

qry = "INSERT INTO mytable (LastName, FirstName) VALUES(@lname,@fname)"
cmd.Parameters.AddWithValue("@lname", txtLast.Text)
cmd.Parameters.AddWithValue("@fname", txtFirst.Text)

the resulting query would be

INSERT INTO mytable (LastName, FirstName) VALUES('O''Brien','Conan')

Notice how changing the single quote to two single quotes was done for you. Notice also how much easier it is to code the template query and much clearer it is when reading the code.

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

But before you reverse the string you should normalize it.

  1. convert everything to upper or lower case
  2. remove all non-letters

If you were to check the phrase "Able was I ere I saw Elba" without normalizing it would not be flagged as a palindrome. After normalizing it would be "ablewasiereisawelba" which would be flagged as a palindrome.

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

@savedlema - c'mon back if you need further clarification.

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

Tablename.replace("TextBox1.text");

That is not only syntactically incorrect, but it also is a meaningless statement.

  • what is Tablename
  • what is the text that you are replacing
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The SQL command (you didn't specify what type of database) to create a table looks like

qry = "CREATE TABLE [xxxxxxx] (                      " _
    & "  [LastName]   varchar](50) NOT NULL,         " _
    & "  [FirstName]  varchar](50) NOT NULL,         " _
    & "CONSTRAINT [PK_xxxxxxx] PRIMARY KEY CLUSTERED " _
    & "   ([LastName](Asc))                          " _
    & ") ON [PRIMARY]"

so to create the query string you could do

qry = qry.Replace("xxxxxxx",TextBox1.Text)

then execute that query.

savedlema commented: Thanks Rev. +1
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I got here from your last thread. I'm assuming you are changing the sa password because you don't want to leave it as the default when you installed (an all too common mistake). I'm not sure what your problem is with establishing a connection. Is your database set to use Windows Authentication or SQL Server Authentication? Are you trying to connect (in your app) with a userid/password or are you using a trusted connection? Your example in the previous thread used trusted connection in which case your connection string should be something like

"Server=.\SQLEXPRESS;Database=DataDesignSolutions;Trusted_Connection=yes;"
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

This is what i would like to shrink it to: 6df29bf4ac41937cc233fa07dfa55519

That's just not gonna happen. You can't shrink it down to that without losing information. What you are doing is calculating a checksum and all that does is allow you to determine if the original string has been altered.

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

Can you give us an example of a string you want to shorten and what you might like to see as a result?

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

I guess it all depends on the definition of shorten. Perhaps the OP will elaborate.

An old saying (usually attributed to a wise old native) about daylight saving time goes "only the government could believe that you could cut the top off a blanket, sew it to the bottom and end up with a longer blanket.

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

Try

Dim cmd As New OleDbCommand("", con)

cmd.CommandText = "SELECT * FROM Table1 WHERE Department = ?"
cmd.Parameters.AddWithValue("@dept", txtDept.Text)

con.Open()
Dim rdr As OleDbDataReader = cmd.ExecuteReader()

If rdr.Read Then
    TextBox1.Text = rdr.GetString(0)
    TextBox1.Text = rdr.GetString(1)
    TextBox1.Text = rdr.GetString(2)
End If

rdr.Close()
con.Close()
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can set the advanced properties on a folder to make it a compressed folder. Then, you can store the string in a file in that folder. The file, and therefore the string, will be automatically compressed when saved and decompressed when read into the app.

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

Look at the example here which also shows you how you should be forming your queries using parameters rather than concatenation.

By the way, if you are using SQL Server you should not be specifying the name and location of the database file. You should let the database server handle that and just refer to the database name. You'll see how that is done in the example as well.

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

Depending on how many random numbers you need and over what range, regenerating when you get a duplicate might not be a good idea. For example, if you need ten random numbers from 1-1000 there won't be a problem. However, if you need 1000 random numbers (with no duplicates) then you will be ok at the start but not at the end because the more numbers you get, the more likely it is you will get a duplicate. At the end you will spend most of your time regenerating. For a reasonably sized range you can generate an initial list containing all of the possible numbers, then remove each number from the list as needed at random, of course). Skeleton code (with no error checking) is

Imports System.Random

Public Class Form1

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

        Dim myrand As New Unique(-5, 20)
        Dim n As Integer

        Do While myrand.More()
            n = myrand.GetNext()
            Debug.WriteLine(n)
        Loop

    End Sub

End Class

Public Class Unique

    Private _list As New List(Of Integer)
    Private _rand As New Random(Now.Ticks Mod Integer.MaxValue)

    Public Sub New(lo As Integer, hi As Integer)

        For i As Integer = lo To hi
            _list.Add(i)
        Next

    End Sub

    Public Function GetNext() As Integer

        If _list.Count > 0 Then
            Dim r As Integer = _list(_rand.Next(0, _list.Count))
            _list.Remove(r)
            Return r
        Else
            Return -1
        End If

    End Function

    Public Function More() As Boolean
        Return _list.Count > 0
    End Function

End Class

_rand.Next(0, _list.Count) generates a random index into the list. …

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

You need a wildcard at each end like

    command.CommandText = command.CommandText & " where name like '%" & Me.txtsearch.Text & "%'"
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Add the closing single quote as

command.CommandText = command.CommandText & " where name like '%" & Me.txtsearch.Text & "'"
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Can you provide a little more code? Are you using SqlClient, OleDb, ADO, etc? Does the sample code here help?

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

Although I do sit in awe at those with 'Posting Guru' status.

I once commented (verbally) to a friend on a beautiful, bright, moonlit/scattered clouds night that I was "awed by nature". She look back at me and said "well, I've always thought so".

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

The following loop looks at each entry in the intPoints array and exits when it finds the first one that is greater than or equal to the user entered score.

For Each entry As Integer In intPoints
    If intSearchPoints < entry Then Exit For
    intSub += 1
Next

Once we get here either intSub will point to an entry in intPoints (in which case the entered score was within 0-500 and therefore corresponds to a letter grade) or intSub is greater than the largest entry in insPoints (in which case the entered number was > 500 and therefore invalid).

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

Seriously? I get a downvote for suggesting that some code might be of help in solving the problem? And for asking for a clarification on a control type? Someone has a pretty thin skin.

AndreRet commented: Up you go :) +13
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try

sql = "SELECT rooms.roomID, rooms.roomNumber, rooms.roomStatus,roomType.roomType, " _
    & "       roomType.adultRate, roomType.childrenRate, roomType.roomTypeID " _
    & "  FROM rooms INNER JOIN roomType " _
    & "    ON rooms.roomType = roomType.roomTypeID"
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

What error are you getting and on which line?

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

Ideally, the customer name should not appear more than once. What you should have is an Orders table that contains (possibly) the fields

OrderNo
CustomerName
OrderDate
etc

where you have only one record per order, and an OrderItems table with one record per order item such as

OrderNo
PartNo
Quantity
UnitCost
etc

Compare it to a paper order which has the information from the Orders table at the top of the page followed by a table containing the items.

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

In the Form Load handler you can set focus to the desired control like

TextBox1.Focus

When in design mode, under the View menu item, select Tab Order. This will show a number on each control. As you click on each control the tab order will be set to that sequence. That will be the order in which the controls will get focus as you use the tab key when running the program.

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

You could do (pseudocode)

Dim strGrades() As String = {"F", "D", "C", "B", "A"}
Dim intPoints() As Integer = {300, 350, 400, 450, 501}

Dim intSearchPoints As Integer
Dim intSub As Integer = 0

Integer.TryParse(txtPoints.Text, intSearchPoints)

For Each entry As Integer In intPoints
    If intSearchPoints < entry Then Exit For
    intSub += 1
Next

If intSub < intPoints.Length Then
    lblGrade.Text = strGrades(intSub).ToString
Else
    lblGrade.Text = "Invalid Points"
End If

but you should type check and range check your value first. For example

if the entered value is numeric
    convert text to integer
    if number is 0-500
        convert to letter grade
    else
        "number out of range"
    end if
else
    "entered value is not a number"
end if
siaosituimoloaublood commented: Thank you Rev. for your quick response. Just need a little bit more help. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Well then, enjoy :-)

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

MsgBox is modal so when it is displayed the script pauses at that point. You can't make it auto-acknowledge if the drive comes online. Another option is to do something like

const DRIVE = "F"

set fso = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

Do
    set drv = fso.Drives(DRIVE) 

    if err.Number = 0 then
        wscript.echo "Drive found"
        exit do
    end if

    wscript.echo "Drive not found. Press CTRL-C to quit or wait for auto retry"
    wscript.Sleep 1000

    err.Clear

Loop

or to write a VB app which does the same thing except displays the results after each pass in a label, and provides a button (for example) to quit.

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

If there is no code under the listview double click event, it will not do anything.

This might be easier to determine if the OP had actually provided code.

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

Perhaps the behaviour is different in VB6 and earlier but in VB 2010 the items in the ListView are not editable. Are you sure you mean ListView and not some other control?

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

Unfortunately (for you) I can't test it under Windows 8. Perhaps some else out there can?

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

I tried it on my computer (Windows 7 Pro). I have an external hard drive assigned to F. I run the script and click on Retry a couple of times before plugging in the drive. Then I click on Retry until the drive is recognized. No crashes.

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

Try this

const DRIVE = "F"

set fso = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

Do
    set drv = fso.Drives(DRIVE) 
    if err.Number = 0 then Exit Do

    If MsgBox("Drive " & DRIVE & ": is not available, Please mount the drive", vbRetryCancel, "Test") = vbCancel Then
        Wscript.Quit
    End If

    err.Clear

Loop

MsgBox "Drive " & DRIVE & " Found"
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

So if arr already contains binary data why do you need the IOStream? And if you do need the IOStream then try

    Photograph1.Image = New Bitmap(New IO.MemoryStream(arr))

It's not my area of expertise so I'm just throwing out suggestions and hoping that one sticks.

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

I know that to load an image from a file I do

Photograph1.Image = New Bitmap(filename)

I can't recommend what you should do without knowing what arr is or what it contains.

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

For Server Type you want to pick Database Engine. That should be the default. For Server name you should select Don-PC\SQLEXPRESS. And for the last box, take the default of Windows Authentication. Then click Connect. Once you have connected and get to the main screen you can proceed as I stated in my previous post. Let me know what happens.

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

If you've installed SQL Management Studio then you can find the current location of your files by right clicking the server instance in the left pane and selecting Properties. Select Database Settings in the window that appears and the folders for Data and Logs will be displayed. You can attach your database files from their current location, or you can move or copy them to the displayed folders. You can attach the database files to the new server instance using sp_attach_db (which will eventually go away as it has been deprecated but still works for now). The syntax is

sp_attach_db 'dbname','datafile','logfile'
sp_attach_db 'PUBS','D:\SQL\DATA\PUBS.MDF','D:\SQL\DATA\PUBS_LOG.LDF'

Using the PUBS database as an example

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

Add another column (make the width=0) and populate it with the month numbers, then sort on that column. Or you could just add the items in month order to begin with. Or you could add your own custom sort routine for when the user clicks on the Month column header.

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

The differences are explained here with examples. In a nutshell, using OleDb you have to add the parameters in the order in which they appear in the query. Using SqlClient you can add the parameters in any order. If you are using a SQL database you can use SqlClient (preferred). Otherwise you have to use OleDb. SqlClient is optimized for SQL databases.

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

I suggest you download (free) {MS SQL Management Studio](http://www.microsoft.com/en-ca/download/details.aspx?id=8961) and install it using this procedure. It will greatly help in creating and managing databases. You can open a table and type the data directly into a grid.

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

Here is an example using SQL server. It retrieves all records where au_lname starts with D. In Access the wildcard is "*" instead of "%". And you will have to use your own connection string.

Private Sub btnOleDB_Click(sender As System.Object, e As System.EventArgs) Handles btnOleDB.Click

    'OLEDB is more generic (can be used for different data sources) and supports
    'parameters but they are unnamed and positional

    ListView1.Items.Clear()

    Dim con As New OleDbConnection("Provider=SQLNCLI10;Server=.\SQLEXPRESS;Database=PUBS;Trusted_Connection=Yes;Connect Timeout=15;")
    Dim cmd As New OleDbCommand("", con)

    cmd.CommandText = "SELECT au_lname,au_fname,zip FROM authors WHERE au_lname like ?"
    cmd.Parameters.AddWithValue("@pan", "D%")

    con.Open()
    Dim rdr As OleDbDataReader = cmd.ExecuteReader()

    Do While rdr.Read
        ListView1.Items.Add(New ListViewItem({rdr.GetString(0), rdr.GetString(1), rdr.GetString(2)}))
    Loop

    rdr.Close()
    con.Close()

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

0 to 36 will generate 37, not 36

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

Or he could do

Public Class Form1

    Private TextBoxes(37) As TextBox

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

        For i As Integer = 1 To 36

            Dim txt As New TextBox
            txt.Location = New Point(10, 25 * i)
            txt.Name = "TextBox" & i
            txt.Text = "TextBox" & i
            Panel1.Controls.Add(txt)
            TextBoxes(i) = txt

        Next

    End Sub

End Class

and just reference each textbox as in

TextBoxes(i).Text

Considering that he is a self-admitted newbie perhaps the custom class might be a tad confusing just now.

If you need to add handlers for the textbox events we can show you how to easily manage that. As a plus, you'd only need one handler for all 36 controls.

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

I don't understand what you mean by the form doesn't "see" the TextBox names. Forms don't see things. How are you trying to reference a textbox inside the panel? I put a textbox in a panel and had no trouble referencing it. Did you create the textboxes ar runtime? If so then that might have been worth a mention.

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

Perhaps we are going about this all wrong. What we have been doing is trying to get this 36 textbox thing going. Why don't you tell us what you are trying to do instead of how you are trying to do it and we can try to suggest a more reasonable approach.

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

The line above that is

Dim con As New SqlConnection("Server=.\SQLEXPRESS;Database=PUBS;Trusted_Connection=yes;")

Do you understand the example or would you like me to add a little more detail to the explanation?

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

You should be using parameterized queries. But to answer your question, try

login = "SELECT * from usernames " _
      & " WHERE Username   = '" & TextBox2.Text & "' " _
      & "   AND [Password] = '" & TextBox1.Text & "' " _
      & "   AND GETDATE()  < ExpireDate"

or use "<=" if the user can still log in on the ExpireDate.

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

That is correct. I've tried to find a way to have both the headphones and internal speakers active at the same time and was told (at least by Dell) that it would require a hardware mod.