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

What is the layout of the new table? There is always a way to combine tables. The trick is to combine them in a way that makes sense. If you just want a table of people regardless of whether the people are students or faculty then you could

SELECT * FROM table1 
UNION 
SELECT * FROM table2

If you want to include a field that distinguishes between faculty and students you could do

SELECT 'S' AS classID,* FROM table1
UNION
SELECT 'F' AS classID,* FROM table2

which will return the fields classID, lname, fname and age where classID=S indicates a student and classID=F indicates faculty. If you want to insert the records inito a new table then add

INSERT INTO table3

at the start of the query.

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

@diafol - here's a handy tip. If you are losot in a foreign city and you don't speak the language and they don't speak English, it helps the locals to understand you better if you yell in English.

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

It would be fast enough if you lived in Chatanooga. They have incredibly fast (publicly owned) internet there.

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

So you display a word, the correct definition, and two other unique definitions from the list. The user selects a radiobutton and the code checks to see if the selected answer is correct. What you could do is use the same handler for all three radiobuttons. See the following

Private Sub radDef_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles radDef1.CheckedChanged, radDef2.CheckedChanged, radDef3.CheckedChanged

    Dim rad As RadioButton = sender

    If rad.Checked Then
        If rad.Text = Dict("plutocracy") Then
            MsgBox("correct")
        Else
            MsgBox("incorrect")
        End If
    End If

End Sub

If you notice, I created a handler for the first radiobutton then renamed it from

rad1Def_CheckedChanged

to

radDef_CheckedChanged

I then changed the Handles clause to

Handles radDef1.CheckedChanged, radDef2.CheckedChanged, radDef3.CheckedChanged

Now when the user selects any radio button the same code will execute. That's OK because you want to do the same thing no matter which button gets selected. The line

Dim rad As RadioButton = sender

gets a reference to the button that changed. One potential problem is that the event fires on a change, not just a select so if a button is already selected and the user selects a different one, the even fires for the unselect, then again for the select. We can process only the select event by

If rad.Checked Then

and you can get the text associated with the selected button by

rad.Text

now just compare that to Dict(currentWord) to see if the user chose the correct …

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

Have you considered a loop? That will make the code independent of the number of words and definitions.

'using MIN ensures you don't get an error if one array is longer than the other.
'checking TRIMmed values eliminates blank entries

For i As Integer = 0 To Math.Min(UBound(Keywords), UBound(Definitions))

    Dim wrd As String = Trim(Keywords(i))
    Dim def As String = Trim(Definitions(i))

    If wrd <> "" And def <> "" Then
        Dict.Add(wrd, def)
    End If

Next

For reasons unknown to me and possibly unexplainable by Microsoft

rnd.Next(min, max)

returns a random number which is >= min and < max. So in order to generate (for example) a random number from 1 to 1-0 you must code

rnd.Next(1, 101)

I don't know if it is a requirement that you have the definitions and the words in separate files but if not then I suggest you store them in one file as in

plutocracy = govermnent by the wealthy

That way the words and definitions do not get out of sync and reading them in becomes a lot easier. Just Split the line on "=" and Trim both parts.

Now to the original question - that will depend on how you are presenting the words and definitions to the user. If, for example, a word is presented and the user selects a definition from a drop down list then all you have to do to compare them is compare Dict(displayed word) to the selected text …

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

Anytime. The best questions are the ones where I learn something as well.

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

This example implements drag and drop from both ListBox and ListView to a TextBox. The ListView is in Details view.

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

    For Each word As String In Split("the quick brown fox jumped over the lazy dog")
        ListBox1.Items.Add(word)
        ListView1.Items.Add(New ListViewItem(word))
    Next

End Sub

Private Sub TextBox1_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter

    If e.Data.GetDataPresent(DataFormats.StringFormat) Then
        e.Effect = DragDropEffects.Copy
    End If

End Sub

Private Sub TextBox1_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop

    'If empty then add text, else start a new line and add text

    If e.Data.GetDataPresent(DataFormats.StringFormat) Then
        TextBox1.Text &= IIf(TextBox1.Text = "", "", vbCrLf)
        TextBox1.Text &= e.Data.GetData(DataFormats.StringFormat)
    End If

End Sub

Private Sub Listbox1_Mousedown(ByVal Sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
    ListBox1.DoDragDrop(ListBox1.SelectedItems.Item(0), DragDropEffects.Copy Or DragDropEffects.Move)
End Sub

Private Sub ListView1_ItemDrag(sender As System.Object, e As System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag
    ListView1.DoDragDrop(ListView1.SelectedItems(0).Text, DragDropEffects.Copy Or DragDropEffects.Move)

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

I can play around to see what I can come up with but it will have to wait until I finish slogging through my taxes. I should get a chance either later today or tomorrow morning.

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

That's not code. That's just a string. Please show us your code and include the error message (if any) and the line causing it.

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

In your earlier post you had

cmd.CommandText = "INSERT INTO Resident(ResidentNo, Residential, Street, Telephone, LName, FName, MName, Gender, Birthday, Age, CivilStatus, Religion, Education, Profession, Salary) " _
            & ("VALUES @ResidentNo, @Residential, @Street, @Telephone, @LName, @FName, @MName, @Gender, @Birthday, @Age, @CivilStatus, @Religion, @Education, @Profession, @Salary")

The actual string created is

INSERT INTO Resident(ResidentNo, Residential, Street, Telephone, LName, FName, MName, Gender, Birthday, Age, CivilStatus, Religion, Education, Profession, Salary) VALUES @ResidentNo, @Residential, @Street, @Telephone, @LName, @FName, @MName, @Gender, @Birthday, @Age, @CivilStatus, @Religion, @Education, @Profession, @Salary

You can see that you are missing the parentheses around the values. The format is

INSERT INTO tablename (field, field,...) VALUES(value, value,...)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try typing this at the command line

net use /persistent:yes

If it is set to no then connections will not be automatically re-established.

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

What happens if you add

127.0.0.1   apis.google.com

to your hosts file?

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

You should put single quotes around string (character) values and not around numeric values. You didn't include your field definitions for the database table so we can't tell which values are which. For example,

INSERT INTO myTable (idnum) VALUES('123')

where idnum is defined as INT may cause a problem because the actual value you are passing is a string, not a number. It should be

INSERT INTO myTable (idnum) VALUES(123)

In any case, you should be using parameterized queries which would not only handle that for you but also prevent against SQL injection attacks. Please see the example here.

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

Are you trying to import the data from within Excel or are you doing it from another environment such as C, C++, vb.net, vbScript, etc.? Once we get more information we can move this thread to the appropriate forum and proceed from there.

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

If you use proper indentation then the solution becomes more obvious.

Dim decCharges As Decimal
Dim intHours As Integer

Const decA As Decimal = 9.95D
Const decB As Decimal = 14.95D
Const decC As Decimal = 19.95D

inthours = CInt(txtHours.Text)

If radA.Checked = True Then
    If intHours >= 10 Then
        decCharges = decA
    Else
        If intHours < 10 And intHours > 744 Then
            decCharges = intHours * 2
        End If
    End If

    If radB.Checked = True Then
        If intHours >= 20 Then
            decCharges = decB
        Else
            If intHours < 10 And intHours > 744 Then
                decCharges = intHours * 2
            End If
        End If
    End If

End If

If radC.Checked = True Then
    If intHours >= 744 Then
        decCharges = decC
    End If
End If

lblTotal.Text = decCharges.ToString("c")

You should not introduce so many blank lines. It reduces the number of lines of code that are visible at one time. Use just enough to form logical groupings of code. You could also use the Select Case True form to improve readability and structure even more. In that case you get

Dim decCharges As Decimal
Dim intHours As Integer

Const decA As Decimal = 9.95D
Const decB As Decimal = 14.95D
Const decC As Decimal = 19.95D

intHours = CInt(txtHours.Text)

Select Case True

    Case radA.Checked

        If intHours >= 10 Then
            decCharges = decA
        Else
            If intHours < 10 And intHours > 744 Then
                decCharges = intHours * 2
            End If
        End If

    Case radB.Checked

        If intHours >= 20 …
Stuugie commented: I wish all used proper indentation. +5
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you enjoyed Face Off (or even if you didn't) you have to watch The Nostalgia Critic review

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

Keep in mind that chat is not the best option for getting help for anything other than the simplest problems.

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

So are you saying that now it does work (successfully dragged a file to it) or that it doesn't (it just refuses to allow the drag)?

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

By the way, I don't know if this is a bug, or just a problem with my installation, but I wanted to implement drag and drop to a rich text box, however, the RichTextBox control did not have an AllowDrop property, or DragEnter or DragDrop events available in the IDE. I had to set AllowDrop manually in the form load and add the handlers manually at the same time using AddHandler.

I just thought I'd mention this is case you ever decide to use a RichTextBox instead of TextBox.

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

Add this code

Private Sub TextBox1_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter

    If e.Data.GetDataPresent(DataFormats.FileDrop) Then
        e.Effect = DragDropEffects.All
    End If

End Sub

Private Sub TextBox1_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop

    If e.Data.GetDataPresent(DataFormats.FileDrop) Then
        Dim files() As String
        files = e.Data.GetData(DataFormats.FileDrop)
        TextBox1.Text = My.Computer.FileSystem.ReadAllText(files(0))
    End If

End Sub

Then try dropping a file on the textbox.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
SELECT JOB, GRADE FROM EMP 
 WHERE GRADE <= 'O'
 ORDER BY GRADE
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try

dtaTitles.Recordset.Find("Author >= '" & cmdLetter(Index).Caption & "'", 0, adSearchForward)

It would also help if you specify what version of VB you are using. In my version (2010), Variant is not a valid type. You should be using "&" for concatenation rather than "+". And finally, instead of

If dtaTitles.Recordset.EOF = True Then

you can use

If dtaTitles.Recordset.EOF Then
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I'm also seeing something else strange. I check several forums regularly throughout the day. After browsing the threads of interest I always click on Mark Forum Read. And yet, in the vb.net forum I am seeing threads marked as New that were updated no more recently than 3 days ago.

Same thing with this forum and Microsoft Windows

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

Have a look here and here.

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

You could use a BackGroundWorker control to execute the code in another thread.

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

Same here.

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

I suggest using CTRL instead of ALT for two reasons:

  1. CTRL-ENTER is used in many other apps for this purpose
  2. ALT typically activates the menu
cambalinho commented: thansk for correct me ;) +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try

SELECT CASE fldname WHEN 0 THEN 'No' ELSE 'Yes' END AS fldname
  FROM tablename
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can specify the sort order when you retrieve the records by using the ORDER BY clause in the query.

SELECT * FROM mytable ORDER BY fieldname
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

My GUI is entirely separate from that. What you are looking at is the setup for the equalizer. You have to run my GUI after it is all set up. It looks like this

36c18fb8d65022179e94f00910e0b719

Until I get around to it (or until you change it for yourself) the GUI will work only for the frequencies I have defined. I hope to make the frequencies, number of bands and filter types configurable.

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

Is there anyway I could do this using MS-Dos commands

You can run it as a batch job. That's what scripts are for. vbs files are executed either by cscript.ece or wscript.exe. One is for command line (c) mode and the other is from windowed (w) mode. One difference is that under cscript.exe, output goes to the console window and under wscript.exe, output is to a MessageBox. You can set console as the default by

cscript //h:cscript //s

To run it automatically you can set up a task in the Task Scheduler.

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

I wrote this script a few years ago to do just that. You can modify it to restrict it to specific types of names. See attached.

Usage:

  delete_older_than #days [folder] [-s] [-l] 

  where 

    #days       number of days to keep 
    folder      name of folder containing files to delete 
                (default is current)
    -s          delete in sub-directories also (optional)
    -l          list files to delete withoout deleting them (optional)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I've attached two files. One is the zip file that contains the source code and compiled application. The other is an example config file. Once you install Equalizer APO, go to the folder

C:\Program Files\EqualizerAPO\config

and replace example.txt with the one I posted. I'm still working on my GUI so in a newer version you won't have to do this. Also, I hope to add more options for the filters. When you run the GUI you can adjust the sliders and the config file will be updated in near real time. If you right click on any filter you can enable/disable all filters so you can see what difference (if any) your settings make. You can close the GUI (with ALT-F4) without disabling the equalizer.

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

The nice thing about Equalizer EPO is you get to define the frequencies, the number of bands, and you can specify the filter types (high, low, band-pass, etc).

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

I had a similar problem. I have lost some hearing in the higher frequencies and was looking for a way to adjust the sound over all applications. I found Equalizer EPO. You can download the 32 bit version here. There is a 64 bit version available as well but you may have to look around for it. You configure it using a text file. I have written a GUI front end in vb.net which I can post if you need it.

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

See this example (con is the connection object)

    Dim cmd As New SqlCommand("", con)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "InsertRecord"
    cmd.Parameters.Add("@Details", SqlDbType.VarChar)

    con.Open()

    cmd.Parameters("@Details").Value = "Sample details 1"
    cmd.ExecuteNonQuery()
    cmd.Parameters("@Details").Value = "Sample details 2"
    cmd.ExecuteNonQuery()
    cmd.Parameters("@Details").Value = "Sample details 3"
    cmd.ExecuteNonQuery()

    con.Close()

Just replace the centre block (between con.Open and con.Close) with your loop.

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

You'll have to be more specific. You haven't told us anything useful. We don't know

  1. what your form looks like
  2. what kind of data you are searching
  3. how you want to present the results
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You have to add it to the panel, not the form as in

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

Did you notice that if the number of checks written is >= 60 you don't do a calculation? You might want to consider a case statement which is simpler and clearer.

Select Case checks
    Case 0 To 19
        fee = 0.1
    Case 20 To 39
        fee = 0.08
    Case 40 To 59
        fee = 0.06
    Case Else '60 or more
        fee = 0.04
End Select
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It's hard to be specific without seeing the code but generally the problem is because you declared a reference to an object but did not actually create an instance. It's the difference between

Dim myobj As SomeObject         'a reference to SomeObject

and

Dim myobj As New SomeObject     'an instance of SomeObject
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

What are the fields in the tables Salup and Salary? And when you say monthly salary do you mean total or per employee? Please provide an explanation as to what the fields are. The names Dsgn, Doj and Bp are not descriptive.

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

Why do you need to make it shorter? It works, it's simple and it's clear. What more do you want?

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

Modifying the recordset within a loop that terminates on EOF is like modifying a loop index within a For loop. It's generally a bad idea. If you can explain what you are trying to do perhaps I can suggest an alternative method.

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

Try

Dim qry As String
Dim con As New ADODB.Connection
con.Open("Driver={Microsoft Access Driver (*.mdb)};" _
       & "Dbq=database;Uid=user;Pwd=password;")
qry = "INSERT INTO table2 SELECT * FROM table1" 
con.Execute(qry)
con.Close()

If you want specific records then try

qry = "INSERT INTO table2 SELECT * FROM table1 " _
    & " WHERE Sex = 'Male'"

Substitute appropriate values for database, user, password, table1 and table2.

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

That solution was already posted.

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

Creating a file when a flag will do is not the way to go, especially a file in the location (root of C) that you are suggesting. The location is unrelated to the application and the filename gives no indication of what the file is for. All in all a very bad idea.

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

I installed visual Studio 2012 (hate the look and feel of the "flat" interface) and loaded up your project. The reason it isn't working is because you didn't add the suggested code. If you want to display Settings on first run then you have to add code in the Form_Load event handler. Have another look at the sample project I posted earlier.

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

If you stored the level number with each record then it becomes trivial to determine how many slots are available on a level.

SELECT Available = POWER(3,4)-COUNT(*) 
  FROM myTable
 WHERE Level = 4

and it only takes one extra byte for each record in the table.

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

I posted a reply twice and both times they disappeared. I'll try again.

I think I get what you are trying to do. To put it into concrete terms, your table represents membership in a club (or pyramid scheme) where there are ten possible levels of membership. The top level can have three members. Each member can sponsor up to three members on the next level down. You already store a member id and the id of each member's sponsor (uplink). Is there any other info in the table (level number, for example) that would be of use?

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

I'm going to have to pass on this. I still have no idea what you are doing or how the structure you describe is represented in your database.