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

Speaking of rep and such, I have changed my mind about anonymous voting. I think that if someone wants to downvote another member, anonymous voting should not be allowed. It's not that I am overly concerned about my points, etc, but when I get downvoted for comments such as those I made here then I think we have gone too far in one extreme. This certainly is not in the same league as when one member went gonzo over lastmitch but I think if someone has a problem with a post, they should have the decency to attach a comment with explanation, and a name to go with it.

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

How would you define "active contributors"? Anyone can make large numbers of posts. They don't have to be quality posts. Would that person be an active contributor? Should he/she be allowed to award endorsements even though nothing of value has been contributed? It's difficult to devise a system that is both automated and fair. Basing it on reputation points, however, might be easier to automate.

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

What do you consider valid text? If you limit it to only letters and blanks then names like Ryan O'Neal and Joseph Gordon-Levitt would both be invalid. Why not just allow any characters, then parse on a blank. If you get more than two names then disallow. If the two names don't match anything in the database then disallow.

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

1c1104fb003f10328fbd8fb6645a8d00 The spending on the "war on drugs" in the U.S. has risen from around half a billion annually in 1970 to around 20 billion in 2010. Total cost of the "war on drugs" as of 2010 is around 1.5 trillion dollars. The U.S. drug addiction rate since 1970 has remained relatively constant at around 1.5%. Net effect on addiction - zero.

LastMitch commented: This has to be the most creative graph chart I seen so far! =) +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you don't have your alarm set then you won't lose any sleep at all.

<edit> unless you have a cat </edit>

LastMitch commented: LOL +0
<M/> commented: true +0
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

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

You make a string of valid grades such as

Dim ValidGrades As String = "ABCDF"

then you validate the input as

If Instr(ValidGrades,strSearchFor) = 0 Then
    MsgBox("Invalid grade")
Else
    'do the search
End If
siaosituimoloaublood commented: Awesomeness..it works..thank you for helping expand my knowledge +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Still too many commas. Try

If result = DialogResult.Yes Then
    cmd.CommandText = "UPDATE [" & EBU2DB_LOB & "] " _
                    & "   SET Months = ?," _
                    & "       Brand  = ? " _
                    & " WHERE LOB    = ? "
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It's not so much that you can't remember names so much as you don't bother to remember them (my problem). I find that the best way to remember soneone's name is to immediately use it a few times. For example, when you are introduced to someone, instead of saying, "pleased to meet you", say, "pleased to meet you, Dave". If you work the name into the conversation a few times it will help to "fix" the name in your memory.

Mike Askew commented: This. Will have to try! +0
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

If you have any particular topics that you'd like to see a code snippet for then please post your requests here. In order to avoid duplication of effort, if you feel inclined to respond to a request then please post here indicating that you will create the requested code snippet in a timely fashion.

A proper code snippet should include a description of what the snippet is demonstrating as well as embedded comments to clarify as needed.

A proper code snippet should also be as simple as possible to illustrate the topic. Code not relevant to the topic should be removed.

Tags should be used to improve search results.

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

Unfortunately I have seen at least one signature stating "if you endorse me then I will endorse you", which defeats the purpose of the endorsement and, as was stated, devalues it for everyone. I think we should all strive to endorse only those people who actually deserve it. By the same token, some people like to post every thought that pops into their head just to increase their post count. This brings down the reputation of the site as a whole. That's what Twitter is for (and that's why you'll never see me on Twitter).

Mike Askew commented: Well put, all valid points. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Washington has spent $791 billion on “homeland security” since 9/11.

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

You should not use

Me.Controls("txbUserFld" & intIndex).Text = reader.ReadLine

because Me.Controls does not return a TextBox control. It returns a reference that must be converted to a TextBox reference. You can do that by assigning it to a TextBox variable or by doing an explicit cast (which is probably the preferred way).

Nutster commented: Quite right. I forgot about that. The generic Control needs to be cast to TextBox. +4
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can download the service manual which should provide details.

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

The maximum size of a hard drive partition is not determined by the operating system (32 bit or 64 bit). It is determined by the file system. Thus, NTFS can manage a larger partition than FAT or FAT32. Whether the medium is solid state memory or magnetic platters is irrelevant.

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

I threw together a test project. The form has ten textbox controls named TextBox1 through TextBox10. There is one button named btnSave. When the form loads it puts ten strings inito the ten textboxes. Clicking btnSave copies all of the text from the textboxes (in order of name) into a buffer, then writes the buffer to a text file.

Public Class Form1

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

        Dim buffer As String = ""

        For i As Integer = 1 To 10
            Dim txt As TextBox = Me.Controls("TextBox" & i)
            buffer &= txt.Text & vbCrLf
        Next

        My.Computer.FileSystem.WriteAllText("d:\temp\save.txt", buffer, False)

    End Sub

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

        For i As Integer = 1 To 10
            Dim txt As TextBox = Me.Controls("TextBox" & i)
            txt.Text = "This is line " & i
        Next

    End Sub

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

And not one has ever been charged with a crime. In fact, they were heavily rewarded for their malfeasance. It was a great racket. The banks provided mortgages to people who couldn't afford them, then foreclosed on those mortgages and got paid back from taxes paid by those same people. Now they are renting back the houses that were basically given to them by the government. What else can you expect when someone like David Koch says things like "I only want my fair share, which is all of it".

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

Try this

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 MsgBox("Do you want to Delete?", MsgBoxStyle.YesNo, "Confirm") = MsgBoxResult.Yes Then
    If con.State = ConnectionState.Closed Then con.Open()
    cmd.ExecuteNonQuery()
End If
Begginnerdev commented: Yep. +8
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I was in a competition once. The rules were simple. If I produced quality code in a timely manner I got to keep my job. The competition lasted 29 years.

tux4life commented: I loved the sarcasm ;) +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

25/8 for the exceptional ones :-)

tux4life commented: Hehe :) +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you go to the Settings page of your project proprties you can add an Application scope string variable with any name you want. Do not enter a value. You can access the value through My.Settings. For example, if your variable is named Database then you can access it like any other variable by

My.Settings.Database

except that when you save a value into this variable it is saved so it is available the next time the app runs. When the form loads you can do

If My.Settings.Database = "" Then
    'prompt the user for a database name
End If

Alternatively, if the dataabase is the same name on all systems you can do

Dim constr As String = ""Server=.\SQLEXPRESS;Database=" _
                     & My.Settings.Database _
                     & ";Trusted_Connection=yes;"

and if the connection fails you can then prompt for an alternate database name or possible even a server name.

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

Prompt the user for the name of the database on first use and save the result in a settings variable for subsequent use. I'd also recommend changing your connection string so that is does not depend ona particular file name. For SqlDb you can use

"Server=.\SQLEXPRESS;Database=PUBS;Trusted_Connection=yes;"

for OleDb you can use

"Provider=SQLNCLI10;Server=.\SQLEXPRESS;Database=PUBS;Trusted_Connection=Yes;"

and for ADO.net you can use

"Driver={SQL Server};Server=.\SQLEXPRESS;Database=PUBS;Trusted_Connection=yes;"

In all cases you shgould replace PUBS with txtSource.Text. However, if the database name is the same as the source machine, and the server instance is ".\SQLEXPRESS" then you do not need to modify the connection string via user input.

savedlema commented: this has been useful to me too. +1
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The following three statements get the values correctly

Dim PurchasePrice As Double = ToDouble(txtPurchasePrice.Text)
Dim InterestRate As Double = ToDouble(txtInterestRate.Text) / 100
Dim DownPayment As Double = ToDouble(txtDownPayment.Text)

However, if you are calculating the minimum down payment as a portion of the purchase price then there is no reason for the third line unless you intend to do something like

Dim PurchasePrice As Double = ToDouble(txtPurchasePrice.Text)
Dim InterestRate As Double = ToDouble(txtInterestRate.Text) / 100
Dim DownPayment As Double = ToDouble(txtDownPayment.Text)
Dim MinimumDown As Double = PurchasePrice / DOWN_PAYMENT

If DownPayment < MinimiumDown Then
    MsgBox("The minimum down payment is " & MinimumDown)
    etc.

And keep in mind that you should validate the text controls before converting to ensure that they are valid. That means

  • checking that the entered values are numeric
  • checking that the entered values are within a given range of allowable values
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you are using an oledb interface then you have to use "?" when adding values as in

'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;")
Dim cmd As New OleDbCommand("", con)

cmd.CommandText = "SELECT au_lname,au_fname,zip FROM authors WHERE au_lname like ?"
cmd.Parameters.Add("@pan", OleDbType.VarChar).Value = "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()

OleDb does not support named parameters. You can see the difference between SqlClient and OleDb here. That's the same sample code I posted a link to just above.

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

Lately when I post a response that says "google it" I include an actual link that includes the google search phrase plus "site:www.daniweb.com". For example google SQL injection. If the user clicks on that link he/she is shown a list of threads on DaniWeb that address the particular question. The result is to ensure that the traffic is directed back to this website.

mike_2000_17 commented: Good idea! +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You might want to use a backslash instead of a forward slash as a separator.

AndreRet commented: As always the reverend is here to catch my mistakes, thanx. :) +13
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
List.Items(currentTimer - 1).SubItems(List.Items(currentTimer - 1).SubItems.Count).Text = ""

Will probably not work because Count will always return a number whic is one more than the highest valid index. Iitems and SubItems are zero-relative indexed so if you have 5 SubItems then then Count = 5 and the rightmost SubIitem has an index of 4.

Begginnerdev commented: Sorry for absence. +8
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The format of an If statement is

If <expression> Then

where <expression is expected to be something that eventually boils down to a boolean. For example

If str = "abc" Then

the expression

str = "abc"

when evaluated results in either the value True or False. Your statement

If Me.TbmembersTableAdapter.ScalarQueryCardID(cardid) Then

does not result in a boolean value and generates the error because it cannot be converted to one.

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

My most interesting job was my second job after graduating. I worked in the Neuro-Science department of the University of Manitoba Medical College. I worked for two doctors doing research. The first was doing vestibular studies (balance, eye-hand coordination) on a grant for NASA and the other was doing spinal cord research with the hope of developing implants for people with spinal cord injuries. That was when 8080/8086 micro-computers were just becoming available so I got to get down and dirty with the hardware as well as the code. It was the only time I had to use a soldering gun on the job. It was cool getting in on the ground floor of the new technology but I wish I'd had the opportunities that Mike had.

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

Don't disable the label. Replace your code with

Dim lblPrtNo As New Label()
lblPrtNo.Name = "lblPrtNo"
lblPrtNo.Text = "Part Number"
lblPrtNo.BackColor = Color.DarkBlue
lblPrtNo.ForeColor = Color.White
lblPrtNo.Font = New Font("Sans Serif", 9, FontStyle.Bold)
lblPrtNo.Location = New Point(15, 56)
lblPrtNo.Size = New Size(77, 15)
pnlOrderLine.Controls.Add(lblPrtNo)

and it will work the way you want.

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

If you want the controls in the panel then you have to add them to the panel controls collection instead of the form controls collection as in

pnlOrderEntry.Controls.Add(lblPrtNo)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I've never used the Friend declaration and I've never had a problem. I also don't use the With Events option. That doesn't mean I am doing it correctly.

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

Keep in mind that if you want to reference the controls other than from within the event handlers, you will need a variable to hold that reference. If you are creating an array of textboxes then Ii suggest you use an array to save the references. As tinstaafl says, declare the array at the class level as

Private TxtRefs(10) As TextBox
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

At line 34 you have

Me.Controls.Add(txbPartNo)

but you don't have an End Sub before the next statement. On my system (VB 2010), the statement

txbPartNo.TextAlign = ContentAlignment.MiddleLeft

is not valid. When I remove it and add the End Sub the code works fine. And just out of curiousity, why do you need a TextChanged event handler for a label control?

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

My in-laws are pretty old. After a recent snowstorm, some neighbour kids came over, shoveled their driveway, then left without going to the door. They weren't asked to come over and they didn't ask for payment or even recognition. The only way my in-laws knew who had done the shovelling was by the trail of footprints they left behind. Apparently there are still some parents left who instill good values in their children.

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

Rake some leaves, shovel some snow, wash somebody's car or walk their dog. You can make 9$ doing just about any trivial chore. It doesn't take a lot of imagination.

AndreRet commented: How the old school works!! work for your cash or be broke, ;) +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I did. I wrapped some tinsel around my willy.

Don't try that in Colorado. They passed a law a few years ago outlawing aluminum (aluminium for you) underpants. Apparently people were stuffing merchandise with RFIDs in there to shoplift past sensors.

AndreRet commented: OR to avoid kidnapping by aliens ;) +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I think you can clear out saved text by clicking the dropdown box and moving the cursor over an option. When it is highlighted, press the DELETE key.

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

Which index is it complaining about? You have two

  • currentTimer - 1
  • List.Items(currentTimer - 1).SubItems.Count

Try replacing the code with

Debug.WriteLine("index 1 = " & (CurrentTimes - 1).ToString)
Debug.WriteLine("index 2 = " & (List.Items(currentTimer - 1).SubItems.Count).ToString)
Debug.WriteLine("# items = " & List.Items.Count)
List.Items(currentTimer - 1).SubItems(List.Items(currentTimer - 1).SubItems.Count).Text = ""

The obvious problem is that you are either indexing past the number of items or past the number of subitems. You can't determine that just by looking at the code. You have to see the actual values of the indices.

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

Please display the value of sqlupdate (Debug.WriteLine would be good) and post the results here. And before someone else says it, you should be using parameterized values instead of just concatenating to create your query.

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

This thread is for code snippets. Please post this as a regular forum thread and I will be happy to respond. Please include the code from the entire section (Function or Sum) and please indicate what line is causing the error.

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

For numeric input I suggest you use a NumericUpDown control. It will accept only numbers and you can set maximum and minimum values for the control (and alter them at runtime).

You set the messagebox style to Critical or YesNoCancel but only ever check for Yes, No or Cancel. Try setting it up as follows:

Select Case MsgBox(msg, MsgBoxStyle.YesNoCancel, title)

    Case MsgBoxResult.Yes
        .
        .
        .
    Case MsgBoxResult.No
        .
        .
        .
    Case MsgBoxCancel
        .
        .
        .
End Select    

You retest where it is not necessary. Your code basically looks like

If num = x Then
    .
End If

If num < x Then
    .
End If

If num > x Then
    .
End If

If the first case is true then you don't need to do the following two tests. Using the NumericUpDown control with a Select Case gives you

Select Case NumericUpDown1.Value

    Case Is = X
        Me.Text = "you guessed it"

    Case Is < X
        Me.Text = "too low"

    Case Is > X
        Me.Text = "too high"

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

We cook a special Valentine's Day meal together. Lobster, shrimp, cheese fondue, stir fry, etc.

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

Rest assured. It would not be possible to confuse me further. Thanks again for the explanation. I really think I got it this time.

AndreRet commented: lol. +13