crankyslap 0 Newbie Poster

Hey guys, I'm seriously breaking my head over this one. This project should have been finished 10 hours ago but I've been stuck on this for ages.

First I set the DataSources / Dataviews of all the things I need;

Dim dsPubs As New DataSet()
        dsPubs.ReadXml(pathdone)
        DataGridView2.DataSource = dsPubs.Tables(0)

        Dim dsWord As New DataSet()
        dsWord.ReadXml(pathdone2)

        Dim dsSynonyms As New DataSet()
        dsSynonyms.ReadXml(pathdone3)

        Dim fileStr2 As String
        Dim fileStr3 As String
        Dim fileStr4 As String

        Dim dv2 As DataView
        dv2 = New DataView
        dv2.Table = dsWord.Tables(0)
        Me.DataGridView4.DataSource = dv2

        Dim dv3 As DataView
        dv3 = New DataView
        dv3.Table = dsSynonyms.Tables(0)
        Me.DataGridView6.DataSource = dv3

Is great, so now For each row in DataGrid2, I break down all the words in the text to arrays.

For Each row As DataGridViewRow In DataGridView2.Rows
            If Not row.IsNewRow Then

                Dim OriginalContent As String = row.Cells(1).Value
                astrSplitItems = Split(OriginalContent, " ")

Then, for each word, I prevent errors by doubling all single quotes. I then filter DataGrid4 to only include rows where the word matches the word in the array(the first for-each).

For intX = 0 To UBound(astrSplitItems)
                    Dim OriginalWord As String = astrSplitItems(intX)

                    fileStr2 = OriginalWord
                    fileStr3 = fileStr2.Replace(Chr(39), "''")
                    fileStr4 = fileStr3.Replace(Chr(34), Chr(34))

                    dv2.RowFilter = "word = '" & OriginalWord & "'"

Then for each of those rows in DataGrid4, we filter DataGrid6 to only include rows where "wordID" matches the ID in DataGrid4. And then for each of those rows we input the word given to TextBox2.

For Each row2 As DataGridViewRow In DataGridView4.Rows

If row2.Cells(1).Value = OriginalWord Then

dv3.RowFilter = "wordID = '" & row2.Cells(0).Value & "'"

 For Each row3 As DataGridViewRow In DataGridView6.Rows
   If Not row3.Cells(2).Value = "" Then
      wordsID = row2.Cells(0).Value
         synonymID = row3.Cells(0).Value
           theSynonym = row3.Cells(2).Value

                Dim n As Integer = DataGridView8.Rows.Add()
                  If Not row3.IsNewRow Then
                  If Not synonymID = "" Then
                  If Not theSynonym = "" Then
                  If Not wordsID = "" Then
                                                        DataGridView8.Rows.Item(n).Cells(0).Value = synonymID
                                                        DataGridView8.Rows.Item(n).Cells(1).Value = wordsID
                                                        DataGridView8.Rows.Item(n).Cells(2).Value = theSynonym

  TextBox2.Text = TextBox2.Text + theSynonym + wordsID
   TextBox2.Refresh()
DataGridView8.Refresh()

     End If
       End If
         End If
         End If
           End If
            Next

Still with me? here's what happened:
We broke down the original text into individual words. For each word, we searched the main dictionary for a match. If a word was found to indeed be in the dictionary, we retrieved all that words' synonyms from the synonym-database, and we then added that synonym to the text that already was in TextBox2.

This all works great, but I can't figure out the next two steps;
1. Instead of adding *all* synonyms to the TextBox2, add a random found one. So not the first or the last, but truely random.
2. When a synonym for the word is *not* found, add the original word to TextBox2 instead.

By the way, the code is so messy because I've been testing alot of stuff, I will clean it all up when it's done.

Sorry for the complicated question, but I've been fighting with this oen for way too long :<

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.