cgeier 187 Junior Poster

'SqlDataReader' version is basically the same one that I posted previously. Other minor modifications are documented in the code.

'SQLDataAdapter' version has the changes made by xj implemented (uses SqlDataAdapter and a DataTable). I tried to document the changes that xj made the best that I could (in the "Modified" section).

Both versions contain the fix for "lblName not being declared" (see my previous post) and contain more comments / documentation than the version in my previous post.

You should be able to open / run these in your version of VS.

cgeier 187 Junior Poster

In the For Loop where the labels are removed, it refers to lblName (for each lblName in...) but when i add that it complains that lblName is not declared.

Fix: Add "As String".

Change the following code from:

'remove old labels
For Each lblName In lblNameList
    Me.Controls.RemoveByKey(lblName)
Next

To:

'remove old labels
For Each lblName As String In lblNameList
    Me.Controls.RemoveByKey(lblName)
Next
cgeier 187 Junior Poster

I think that it is easier to understand if I post some sample data.

Team Sample Data:

TeamMember Sample Data:

Schedule Sample Data:

A primary key must be unique--it's value cannot be inserted more than once in a table. By looking at the data in "Schedule", we can see that an employeeID (called teamMemberEmpID in table Schedule), has multiple schedules--start times and finish times. So how can we create a unique value from that? Well, in my table design, we have two choices:

Choice 1:
teamMemberEmpID, start

Choice 2:
teamMemberEmpID, finish

Question 1: Will start time always be known?

Question 2: Will finish time always be known?

Question 3: Is it possible that start OR finish will ever contain a null value?

A null value can be unique so long as another one is not entered.

It is possible that an employee is given a start time, but the finish time is subject to change based on the needs of the company. In choosing a primary key, it is better to choose data that is more likely to remain static. Therefore, I chose to use start time as the other part of my primary key.

Since, one employee can only work one shift at a time, he/she will only ever have one start date/time on a particular day. Therefore this will always make it unique.

cgeier 187 Junior Poster

You may notice some flashing when an update is occuring because the labels are removed and added again. A work-around, would be to check to see if any of the data has changed. If it has, delete the labels and re-add them. If not, don't do anything. Could use another list and compare the lists using List.Except (compare the names).

cgeier 187 Junior Poster

The code should work with your local project database too--I tested it both ways. In "SQLExpressDB.vb" (connectStr), comment out the "connectStr" that is currently used and uncomment one of the other ones. I couldn't include the database in the .zip file because it made the file too large.

Read about SQL Server Express User Instances

*"...Databases running on a user instance are opened in single-user mode only, and it is not possible for multiple users to connect to databases running on a user instance...."

I also noticed that when VS is open, the database connection is not released, however it didn't affect my project. Only if you tried to connect to the database file (or attach it in SQL Management Studio). If you eliminate the using statements and close the connection yourself, you may not have that problem any more.

cgeier 187 Junior Poster

Here is a project I created. It is based on the code you posted above.

It requires that you have SQLExpress installed.

Download SQL Management Studio. It will make it easier for you when using a service-based database. (You can use the 2012 version with SQLExpress 2005/2008)

cgeier 187 Junior Poster
cgeier 187 Junior Poster

Duplicate post: http://www.daniweb.com/software-development/vbnet/threads/476214/saving-selected-data-from-textbox-to-db

See your other post for a better database design. When you have a properly designed database, you can use "join" statements to retrieve the data you want.

cgeier 187 Junior Poster
cgeier 187 Junior Poster

We don't write your code for you. If you want to hire someone to write your code for you, there are other sites for that.

cgeier 187 Junior Poster

I don't know your data, but you should probably use 3 tables:

Table 1:

  • ID: primary key
  • Name
  • Age
  • Sex

If one ID in Table 1 has many entries in Table 2:

Table 2:
1:M (1 to many)

  • ID: primary key, foreign key references Table1(ID)
  • Hb: primary key

If one ID in Table 1 has, at most, one entry in Table 2:

Table 2:
1:1 (1 to 1)

  • ID: primary key, foreign key references Table1(ID)
  • Hb:

If one ID in Table 1 has many entries in Table 3:

Table 3:
1:M (1 to many)

  • ID: primary key, foreign key references Table1(ID)
  • BG: primary key

If one ID in Table 1 has, at most, one entry in Table 3:

Table 3:
1:1 (1 to 1)

  • ID: primary key, foreign key references Table1(ID)
  • BG:

Of course, you have to look at your data, and then choose your table design appropriately. If you are duplicating a bunch of columns, you probably need another table.

cgeier 187 Junior Poster

Here is the table creation code. It is in "SQLExpress.vb" which is in "Files.zip". I will put it here in case the file becomes unavailable.

Connection String (same as above):

'Project => Add New Item => Service-based Database
'SQLExpress as a service (Service-based Database)
'Private connectStr = "Server=.\SQLExpress;Database=ShiftRota;Trusted_Connection=Yes;"

'Project => Add New Item => Local Database
'SQLExpress as a file (Local Database)
'Private connectStr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & Application.StartupPath & "\ShiftRota.mdf;Integrated Security=True;User Instance=True"

'Project => Add New Item => Local Database
'SQLExpress as a file (Local Database)
Private connectStr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & Application.StartupPath & "\ShiftRota.mdf;Trusted_Connection=Yes;User Instance=True"

CreateTeamTbl:

    Public Sub CreateTeamTbl()

        Try

            Using cn As New SqlConnection(connectStr)
                Dim sqlText As String = String.Empty

                sqlText = "CREATE TABLE Team (teamID nvarchar(25) NOT NULL "
                sqlText += "CONSTRAINT PK_Team_teamID PRIMARY KEY,"
                sqlText += "name nvarchar(25))"

                'open connection
                cn.Open()

                'create new SqlCommand
                Using sqlCmd As New SqlCommand(sqlText, cn)

                    'execute
                    sqlCmd.ExecuteNonQuery()
                End Using

                Console.WriteLine("Table: Team created.")
            End Using

        Catch ex As SqlClient.SqlException
            Console.WriteLine("Error:: CreateTeamTbl: " & ex.Message)
        Catch ex As Exception
            Console.WriteLine("Error:: CreateTeamTbl: " & ex.Message)
        End Try
    End Sub

CreateTeamMemberTbl:

    Public Sub CreateTeamMemberTbl()

        Try

            Using cn As New SqlConnection(connectStr)
                Dim sqlText As String = String.Empty

                sqlText = "CREATE TABLE TeamMember (employeeID nvarchar(25) NOT NULL "
                sqlText += "CONSTRAINT PK_TeamMember_employeeID PRIMARY KEY, "
                sqlText += "firstName nvarchar(50), "
                sqlText += "surName nvarchar(50), "
                sqlText += "onCallPhone nvarchar(25), "
                sqlText += "location nvarchar(25), "
                sqlText += "teamID nvarchar(25), "
                sqlText += "CONSTRAINT FK_TeamMember_TeamID_Team_TeamID FOREIGN …
cgeier 187 Junior Poster

Here's some of the code I used. The database structure is slightly different from what you currently have.

I use the following table names:

  • Team
  • TeamMember
  • Schedule

Team:
1857c8ab21a8994b719f43a7701aaf70

ebc52fb9aa11fa5e472d1ffe24e7edbc

TeamMember:
9218831db65cd60fa4cbfdb9ace28c43

bd4806bee9f4139639fbbd155f9ed770

Schedule:
6c84dbba35db3f70560019d416df0ebc

8e6f58845dc62628ee7d9385eafa6e1d

fbf740cf3ceba571050c500f1754a83d

And here is the sql select statement text:

Dim sqlText As String = String.Empty
sqlText = "SELECT Team.name as 'TeamName', TeamMember.firstName, "
sqlText += "TeamMember.Surname, TeamMember.onCallPhone, TeamMember.location, "
sqlText += "Schedule.start, Schedule.finish FROM Team "
sqlText += "INNER JOIN TeamMember "
sqlText += "ON Team.teamID = TeamMember.teamID "
sqlText += "INNER JOIN Schedule "
sqlText += "ON TeamMember.employeeID = Schedule.TeamMemberEmpID "
sqlText += "WHERE (Schedule.start < { fn NOW() }) AND (Schedule.finish > { fn NOW() })"

The connection strings I used:

'Project => Add New Item => Service-based Database
'SQLExpress as a service (Service-based Database)
'Private connectStr = "Server=.\SQLExpress;Database=ShiftRota;Trusted_Connection=Yes;"

'Project => Add New Item => Local Database
'SQLExpress as a file (Local Database)
'Private connectStr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & Application.StartupPath & "\ShiftRota.mdf;Integrated Security=True;User Instance=True"

'Project => Add New Item => Local Database
'SQLExpress as a file (Local Database)
Private connectStr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & Application.StartupPath & "\ShiftRota.mdf;Trusted_Connection=Yes;User Instance=True"

"SQLExpress.vb" and "DefaultData.vb" are attached in "Files.zip" below. The connection string is specified in the top of "SQLExpress.vb".

To create a database using "SQLExpress.vb":

SQLExpressDB.CreateDatabase("ShiftRota")
cgeier 187 Junior Poster

If you should decide to place your labels onto a panel, you will need to reference each label by it's parent. To do so, you need to first find it's parent. So instead of:

            'remove old labels
            'the names are in lblNameList
           For Each lblName In lblNameList
               Me.Controls.RemoveByKey(lblName)
           Next

           Using cn As New SqlConnection(sqlString)

            ...

You would do something like this:

        'remove old labels
        For Each lblName In lblNameList

            'holds the parent control of
            'the control we are looking for
            Dim parentCtrl As Control = Nothing

            'find the label name and put 
            'results into list
            Dim ctrlList = Me.Controls.Find(lblName, True).ToList()

            'find parent control name
            'this is so we can reference the 
            'control in relation to it's parent.
            'This is necessary if an object
            'is placed on a panel.
            For Each ctrlItem In ctrlList
                parentCtrl = ctrlItem.Parent
            Next

            If parentCtrl IsNot Nothing Then

                'remove the label
                parentCtrl.Controls.RemoveByKey(lblName)
            End If

            'Me.Controls.RemoveByKey(lblName)
        Next


        Using cn As New SqlConnection(sqlString)

            ...
cgeier 187 Junior Poster

I believe that your issue is that you are creating a label for each person, but never attempt to remove them before updating the data. So if a person's shift is over you will still see their label because you haven't removed it.

How to fix it:
Keep track of the name of the labels you are adding and delete them each time before querying the database. I will use a list:

Public Class Form1

        'list to keep track of label names
        'that were dynamically added
        Dim lblNameList As List(Of String) = New List(Of String)

        ....

Delete the old labels (from the previous query), before getting the updated data from the database:

            'remove old labels
            'the names are in lblNameList
            For Each lblName In lblNameList
                Me.Controls.RemoveByKey(lblName)
            Next

            Using cn As New SqlConnection(sqlString)

            ...

Clear the previous list and add the names of the newly created labels to our list:

    'clear the previous list
    lblNameList.Clear()

    'keep track of labels that were created
    'add lblTeam.Name to list
    lblNameList.Add(lblTeam.Name)

    ' Add the label control to the form
    Me.Controls.Add(lblTeam)

I think updating your form every 5 seconds is excessive. Every 15 to 30 seconds is more than enough. Once per 45 or 60 seconds may be better.

Also, in my opinion it is not good practice to include the table names in the column names (unless you are using a reserved word in your column name and can't find any other name to name it).

cgeier 187 Junior Poster

I haven't tried this, but this post shows how you can read a csv file into a dataset. Once you have a dataset you should be able to set DataGridView.Datasource = to the dataset. It looks like the post is for C#, but VB .NET should be similar.

Here's another post.

Although, this post shows the way I have previously added data to a DataGridView.

cgeier 187 Junior Poster

How many sequences are you supposed to prompt for? You probably need a while loop.

You could probably use two Vectors or ArrayLists. One holds the longest list of numbers in the sequence and the other the current list of numbers in the sequence. If the current list of numbers is longer than the previous one, set the longest list = to the current list.

cgeier 187 Junior Poster

Tough crowd. The Console.WriteLine statements were for debugging. I left them in so that one could verify the results. They should be removed when finished debugging.

Here is an updated version:
The concept of the code is the same. However, I moved the majority of the code to it's own class: ListBoxMonitor. "getLastItemChanged" now returns an "ItemInfo" object. I removed some parameters from "getLastItemChanged" and made them private variables in class ListBoxMonitor. I've also made ListBoxMonitor static.

Create a new class called "ListBoxMonitor.cs" and replace with the following code:

    public static class ListBoxMonitor
    {
        //holds the last item that was changed
        //based on SelectionType chosen by user
        private static ItemInfo lastItem = new ItemInfo();

        //holds the previously selected list items
        private static List<string> previousSelectedItemsList = new List<string>();

        //create an enumeration 
        public enum SelectionType { Deselected, Either, Selected }; 


        public static ItemInfo getLastItemChanged(System.Windows.Forms.ListBox lb, SelectionType sType)
        {

            List<string> currentSelectedItemsList = new List<string>();

            //put selected items into a list
            //so we can use list.Except
            for (int i = 0; i < lb.SelectedItems.Count; i++)
            {
                currentSelectedItemsList.Add(lb.SelectedItems[i].ToString());
            }//for

            if (sType.Equals(SelectionType.Either))
            {
                lastItem = findExcludedItemInList(currentSelectedItemsList,
                                                  previousSelectedItemsList);
            }//if
            else if (sType.Equals(SelectionType.Selected))
            {
                //get last item selected as a list
                //by comparing the current list
                //to the previous list

                if (String.Compare(findExcludedItemInList(currentSelectedItemsList,
                    previousSelectedItemsList).SelectionType, "Selected", true) == 0)
                {
                    lastItem = findExcludedItemInList(currentSelectedItemsList,
                               previousSelectedItemsList);
                }//if
            }//else if
            else if (sType.Equals(SelectionType.Deselected))
            {
                //if item was deselected, switch the order
                //compare previous list to current list

                //if > 0, last item was de-selected
                if (String.Compare(findExcludedItemInList(currentSelectedItemsList,
                    previousSelectedItemsList).SelectionType, "Deselected", true) == …
cgeier 187 Junior Poster

I think that Reverend Jim has identified the problem--controls being on a panel.

Try something like the following:

Let's create a sub to rename our controls:

 Private Sub renameControl(ByRef myCtrl As Control,
                          ByVal columnsCode As Integer,
                          ByVal rowsCode As Integer)

 End Sub

To deal with the situation of controls being on a panel, first read the list of controls into a list:

Private Sub renameControl(ByRef myCtrl As Control,
                          ByVal columnsCode As Integer,
                          ByVal rowsCode As Integer)

    'put controls into a list
    Dim ctrlList = Me.Controls.Find(myCtrl.Name, True).ToList()


End Sub

Now, we want to find the control's parent:

    'holds the parent control
    Dim parentCtrl As Control = Nothing

    'find parent for control
    For Each ctrlItem As Control In ctrlList
        parentCtrl = ctrlItem.Parent

        'Console.WriteLine("PARENT: " + ctrlItem.Parent.Name)
    Next

So now we have:

Private Sub renameControl(ByRef myCtrl As Control,
                          ByVal columnsCode As Integer,
                          ByVal rowsCode As Integer)

    'put controls into a list
     Dim ctrlList = Me.Controls.Find(myCtrl.Name, True).ToList()

    'holds the parent control
    Dim parentCtrl As Control = Nothing

    'find parent for control
    For Each ctrlItem As Control In ctrlList
        parentCtrl = ctrlItem.Parent

        'Console.WriteLine("PARENT: " + ctrlItem.Parent.Name)
    Next

End Sub

Next, create a control variable we can use to change the control properties and reference it using it's parent control.

'this will be the control whose
'properties that we will modify
Dim ctrl As Control

'reference control by it's parent control
ctrl = parentCtrl.Controls(myCtrl.Name)

Now we have:

Private Sub renameControl(ByRef myCtrl As Control, …
cgeier 187 Junior Poster

I re-worked the above code to create a version that allows you to specify if you want the last "Selected" item, the last "De-selected" item, or last item that was changed (either "Selected" or "De-selected").

Create a new class called "ItemInfo". Replace the code with the following:
ItemInfo:

public class ItemInfo
{
    public string Name { get; set; }
    public string SelectionType { get; set; }
}

In the form (Form1), create a list, a new instance of ItemInfo, and an enum as seen below:

public partial class Form1 : Form
{
    //holds previously selected items
    List<string> previousSelectedItemsList = new List<string>();

    //holds the last selected and/or de-selected item
    ItemInfo lastItem = new ItemInfo();

    //create an enumeration 
    enum SelectionType { Deselected, Either, Selected }; 

    public Form1()
    {
        InitializeComponent();
    }
}

Now, we will create a method that will compare our lists and return an ItemInfo object:

private ItemInfo findExcludedItemInList(List<string> list1, List<string> list2)
{
    ItemInfo item = new ItemInfo();

    //get list of items in list1 that aren't in list2
    var lastItemList1 = list1.Except(list2).ToList();

    if (lastItemList1.Count > 0)
    {
        //there should only be 1 item in the list
        item.Name = lastItemList1[0].ToString();
        item.SelectionType = "Selected";
    }//if
    else
    {
        //get list of items in list2 that aren't in list1
        var lastItemList2 = list2.Except(list1).ToList();

        if (lastItemList2.Count > 0)
        {
            //there should only be 1 item in the list
            item.Name = lastItemList2[0].ToString();
            item.SelectionType = "Deselected";
        }//if
    }//else

    return item;
}//findExcludedItemInList

Next, we will create a method "getLastItemChanged" that will use …

ddanbe commented: Great effort +15
Ketsuekiame commented: Bad coding standards, numerous ref used unnecessarily. No SoC. "But it works" is not something you should aim for. -2
cgeier 187 Junior Poster

Here's a solution. Version 2 code has been tested.

Create a new class called "ItemInfo". Replace with the following code:

ItemInfo:

    public class ItemInfo
    {
        public string Name { get; set; }
        public string SelectionType { get; set; }
    }

In your form, (ex: Form1.cs), do the following:

Create a list to hold the previously selected items and an instance of ItemInfo.

    public partial class Form1 : Form
    {
        List<string> previousSelectedItemsList = new List<string>();
        ItemInfo lastItem = new ItemInfo();

        public Form1()
        {
            InitializeComponent();
        }
    }

Then we create a method to find the last selected item:

Version 1
(keeps track of last selected item):

private void getLastItemChanged(ref ListBox lb)
{
    List<string> lastItemSelected;


    List<string> currentSelectedItemsList = new List<string>();

    //put selected items into a list
    //so we can use list.except

    for (int i = 0; i < lb.SelectedItems.Count; i++)
    {
        //add selected items to list
        currentSelectedItemsList.Add(lb.SelectedItems[i].ToString());

        //Console.WriteLine("item: " + lb.SelectedItems[i]);
    }//for

    //get last item selected as a list
    //by comparing the current list
    //to the previous list

    lastItemSelected = currentSelectedItemsList.Except(previousSelectedItemsList).ToList();

    //if last item was selected count > 0
    //else if last item was de-selected 
    //lastItemSelected.Count = -1

    if (lastItemSelected.Count > 0)
    {
        lastItem.Name = lastItemSelected[0].ToString();
        lastItem.SelectionType = "selected";
    }//if


     Console.WriteLine(lastItem.Name + " : " + lastItem.SelectionType);

     //updated previousSelectedItems before returning
     previousSelectedItemsList = currentSelectedItemsList;
}//getLastItemChanged

Version 2
(keeps track of last item - selected OR de-selected):

private void getLastItemChanged(ref ListBox lb)
{
    List<string> lastItemSelected;
    List<string> lastItemDeSelected;

    List<string> currentSelectedItemsList = new List<string>();

    //put …
cgeier 187 Junior Poster

To help with debugging, you can print out all of the control names on your form using the following sub:

    Private Sub printControls(ByVal ctrlParent As Control)
        Dim ctrl As Control

        For Each ctrl In ctrlParent.Controls

            Console.Write("Parent: " + ctrlParent.Name + "...")
            Console.Write("Child: " + ctrl.Name + "...")
            Console.WriteLine("Type: " + ctrl.GetType().ToString())

            'if control has children
            'recursively call this sub
            If ctrl.HasChildren Then
                printControls(ctrl)
            End If
        Next
    End Sub

Call it like this:

        'Me = this form
        printControls(Me)

Code adapted from here.

cgeier 187 Junior Poster

Two errors.

Error #1:

OrderCalc
In line 10, you declare "decks".

private deckPanel decks; 

In line 47, you attempt to use "decks":

add(decks, BorderLayout.NORTH); 

However, you haven't created a new instance of "decks":

deckPanel decks = new deckPanel();

before attempting to use it.

In line 23, you have:

deckPanel dp = new deckPanel(); 

and in line 43:

dp.deckPanel();

Did you mean to have two instances of deckPanel? Or did you decide to change the name at some point and forgot to rename some things.

The fix:

deckPanel decks = new deckPanel(); //added

//add the components to the pane
add(decks, BorderLayout.NORTH);

Error #2:

deckPanel
In line 106, you declare:

 private JPanel deckPanel;

In line 117, you attempt to use deckPanel:

deckPanel.add(deckList); 

without creating a new instance first:

deckPanel = new JPanel();

The fix:

    deckPanel = new JPanel(); //added

    deckPanel.add(deckList); 
cgeier 187 Junior Poster

Hint: Use the following for loops:

If want to print out the average score and letter grade for each student before prompting for the scores from the next student, you don't need an array.

double[] studentsArray = new double[students];   

for(int i= 0; i < students; i++){ 

    for (int j=0; j < numScores; j++){

        //ToDo: get scores here

    }//for

    //calculate average
    studNormAve = (double)(studTotal/numScores);

    //ToDo: print out averages and grade letter


 }//for

Otherwise, put the values in the array and print out the averages and letter grade later.

    double[] studentsArray = new double[students];   

    for(int i= 0; i < students; i++){ 

        for (int j=0; j < numScores; j++){

            //ToDo: get scores here

        }//for

        //calculate average
        studNormAve = (double)(studTotal/numScores);

        //put average into array
        studentsArray[i] = studNormAve;

     }//for


     for (double studentAverage : studentsArray)
     {
         //put value from array into
         //studNormAve
         studNormAve = studentAverage;


         //ToDo: print out averages and grade letter

     }
cgeier 187 Junior Poster

Please review the following documentation:

For-each loop

"...When you see the colon (:) read it as “in.” "

Applied to one of your loops:
for(int bigTemp: studentsArray){

The loop reads as “for each int bigTemp in studentArray.”

Arrays

"a one-dimensional array is created of the specified length, and each component of the array is initialized to its default value"

Initial Values of Variables

"For type int, the default value is zero, that is, 0."

For loop

"...the variable...holds the current value from the...array..."

Applied to one of your loops:
for(int bigTemp: studentsArray){

Assume we entered "3" for students.

Then,

students = 3

The code states:

int[] studentsArray = new int[students];

So,

int[] studentsArray = new int[3]; 

On the first iteration,
bigTemp = studentsArray[0] which contains 0.

On the second iteration,
bigTemp = studentsArray[1] which contains 0.

On the third iteration,
bigTemp = studentsArray[2] which contains 0.

So, as you can see the value "n" you have in line 25:

int n = bigTemp+1;

is always 1.

students: 2
exam grades: 4

students x exam grades = 2 x 4 = 8

which is the number of times the following occurs:

System.out.println("Enter a score for student number: "+n);
cgeier 187 Junior Poster

What seems to be the issue?

Sentintel value

cgeier 187 Junior Poster

Please post the code that you are now using. A screen shot would also be helpful.

I've implemented some checking to see if the control exists (a possible issue that Reverend Jim mentioned above).

Try this:

Dim name As String = "TextBox1"

'check if control with name exists

If Me.Controls.Find(name, True).Count > 0 Then

    Console.WriteLine("Changing name...")

    Dim ctrl As Control = Me.Controls(name)

    'check to see if control is a TextBox
    'if so, change Properties

    If TypeOf ctrl Is System.Windows.Forms.TextBox Then
        ctrl.Name = "txt" & ChrW(columnsCode) & ChrW(rowsCode)
        ctrl.Visible = True
        ctrl.Enabled = True
        ctrl.BringToFront()

        Console.WriteLine("ctrl:  " & ctrl.Name)
    End If

End If
cgeier 187 Junior Poster

If you change your database as in my previous post, all of the data from all the tables you currently have will be in one table (Weather). You could even add a column named "Hour" and make it part of the primary key if you want to maintain hourly data.

cgeier 187 Junior Poster

Why are you wanting to create a separate table for each week? I recommend that you create one table named "Weather" (it will be the same as one of the tables that you currently have, except add the following columns: "WeekNumber" (Number), "MonthNumber" (Number), "YearNumber" (Number) to the columns you already have.

Set the "Required" property for: YearNumber, MonthNumber, WeekNumber, DayNumber

Open the table in "Design View".

The following columns will form the primary key:
YearNumber, MonthNumber, WeekNumber, DayNumber

Use the "Ctrl" key along with your left-mouse button to select multiple columns. While continuing to hold the "Ctrl" key, right-click the mouse, and select "Primary Key".

d48e0b0812260761fa590320cebfabe0

decbcae051d5874510ef61562384904d

cgeier 187 Junior Poster

In "ChooseAnAction", after changing:

possibleAction = getRandomAction(Q_SIZE);

To:

possibleAction = getRandomAction(Q_SIZE - 1);

it will compile. However, there is an infinite loop in "getRandomAction".

R[currentState][action] is always -1 so

choiceIsValid = true;

never occurs.

To help you debug:

In "episode" add a println statement in the for loop (as shown below):

        // When currentState = 15, Run through the set once more for convergence.
        for(int i = 0; i < Q_SIZE; i++)
        {
            System.out.println("i: " + i);

            chooseAnAction();

            System.out.println("after chooseAnAction");
        }

In "getRandomAction" add println statements in the while loop (as shown below):

        // Randomly choose a possible action connected to the current state.
        while(choiceIsValid == false)
        {
            // Get a random value between 0(inclusive) and 16(exclusive).
            action = new Random().nextInt(upperBound);

            System.out.println("action: " + action);
            System.out.println("R[" + currentState + "][" + currentState + "]: " + R[currentState][action]);
            System.out.println();

            if(R[currentState][action] > -1){
                choiceIsValid = true;
            }
        }
cgeier 187 Junior Poster

Try this:

        Dim myxml As String
        myxml = "<response><item><acct>1001</acct></item><item><acct>1002</acct></item></response>"

        Dim ds As New DataSet()

        ds.ReadXml(New System.IO.StringReader(myxml))

        Dim DataGridView1 As New DataGridView()

        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "item"

        Me.Controls.Add(DataGridView1)
cgeier 187 Junior Poster

Unless this is a homework assignment, I hope that you are not storing a username / password in plain text in a text file.

Use "String.Compare" to compare your strings.

cgeier 187 Junior Poster

See my tutorial on form communication.

This one is for vb .net. I don't have time to write one for C# right now. The code I previously posted in your question (above) is how do it in C#. If you read the one for vb .net it should offer you an explanation of the different parts.

cgeier 187 Junior Poster

I'll help you to get started. Create a variable for each final result you want to calculate. Use if-then-else if-else statements as appropriate.

Your tasks. Find out:

  1. What is an integer?
  2. What is a double?
  3. What data types should you use?
  4. How do you write an "if" statement? How do you include "else if", and "else"?
  5. Do you need to use parentheses to affect order of computation?
cgeier 187 Junior Poster

We've done our homework assignments. This one is yours. People are here to assist if you get stuck, but you have to show that you've put in effort. Show some code for each one of your pseudo code items.

cgeier 187 Junior Poster

Maybe this post will help:

Refresh / Update WPF Controls

cgeier 187 Junior Poster

I haven't worked with WPF, but can't you just use an eventhandler (and a delegate)?

cgeier 187 Junior Poster
cgeier 187 Junior Poster

What is the problem that you are having? What is the formula that you are using to calculate the values?

cgeier 187 Junior Poster

I'm confused by your explanation. How do you go from 11110011 to 1,2,3,4,9,12 ? How is "minimum support" defined? What kind of comparison do you want to do? Integer? Can you try to re-explain it. Also, what problems are you having?

cgeier 187 Junior Poster

Thanks.

cgeier 187 Junior Poster

You haven't posted enough of your code to really know what you are trying to do.

cgeier 187 Junior Poster

I will be showing how to pass data between two forms in VB .NET. I will be using two forms, two classes which we will define, a delegate, an event, and an event handler. It is my first tutorial and is a bit long because I wanted to make it easy to follow. If you want to skip the explanation and just see the code, scroll down to "The short version:"

Here is what I will be using:

  • A form named: MainFrm
  • A form named: ChildFrm
  • A class named: ScheduleInfo
  • A class named: ValueUpdatedEventsArgs

An instance of ChildFrm will be created and shown when clicking a button on the main form (MainFrm). After adding our data in the child form (ChildFrm), we will click a button on the child form to send the data back to the main form. Then on the main form we will display the newly received data, as well as add our data to a list (or update the data in the list if it was previously added).

Let's start out by creating "ScheduleInfo.vb". An instance of this class will be used to hold the data that we want to pass between the forms. It only contains two variables. You can add more if you like.

Public Class ScheduleInfo
    Public Name As String = String.Empty
    Public EventType As String = String.Empty
End Class

Next, we create "ValueUpdatedEventArgs.vb":

Public Class ValueUpdatedEventArgs

End Class

We want to inherit from System.EventArgs, so we add …

Reverend Jim commented: Nice tutorial. +12
ddanbe commented: An often asked subject well done! +15
cgeier 187 Junior Poster

Placing into your code, it should look like this. This version is untested:

' For loop repeats for each row
For i As Integer = 1 To rows Step +1

   ' Creates unicode character code for row naming scheme (Numeric)
   Dim rowsCode As String = "&H" & (rows + 30).ToString()

   ' For loop repeats for each text box in row
   For j As Integer = 1 To columns Step +1

      ' Creates unicode character code for column naming scheme (Alphabetic)
      Dim columnsCode As String = "&H" & (i + 40).ToString()

      ' Creates text box variable and sets settings

      Dim name As String = "txt" & ChrW(columnsCode) & ChrW(rowsCode)

      '------------------
      'Added
      '------------------
      Dim ctrl As Control = Me.Controls(name)

      If TypeOf ctrl Is System.Windows.Forms.TextBox Then
         ctrl.Name = "txt" & ChrW(columnsCode) & ChrW(rowsCode)
         ctrl.Visible = True
         ctrl.Enabled = True
         ctrl.BringToFront()

         Console.WriteLine("ctrl:  " & ctrl.Name)
      End If

Next
            Next

The "if" statement may be unnecessary, as long as you know the control contains the properties that you are trying to set.

The important part is:

    Dim ctrl As Control = Me.Controls(name)

    ctrl.Name = "txt" & ChrW(columnsCode) & ChrW(rowsCode)
    ctrl.Visible = True
    ctrl.Enabled = True
    ctrl.BringToFront()

    Console.WriteLine("ctrl:  " & ctrl.Name)

Alternatively, you could do the following:

    Dim txt As TextBox
    txt = CType(Me.Controls(name), TextBox)

    txt.Name = "txt" & ChrW(columnsCode) & ChrW(rowsCode)
    txt.Visible = True
    txt.Enabled = True
    txt.BringToFront()
cgeier 187 Junior Poster

I ran the code and the error is occuring with:

Dim txt As TextBox = Me.Controls(name)

I don't think that you can do that.

The following works for me:

        Dim name As String = "TextBox1"

        Dim columnsCode As Integer = 42
        Dim rowsCode As Integer = 55

        Dim ctrl As Control = Me.Controls(Name)

        Console.WriteLine("TextBox before: " & TextBox1.Name)
        Console.WriteLine()

        If TypeOf ctrl Is System.Windows.Forms.TextBox Then
            ctrl.Name = "txt" & ChrW(columnsCode) & ChrW(rowsCode)
            ctrl.Visible = True
            ctrl.Enabled = True
            ctrl.BringToFront()
            Console.WriteLine("ctrl:  " & ctrl.Name)
        End If

        Console.WriteLine("TextBox after: " & TextBox1.Name)
cgeier 187 Junior Poster

This error typically occurs if you declare an object and try to use it without creating an instance of it (using the "New" key error.

cgeier 187 Junior Poster

In line #6 you do the following:

Me.Ministry_HeadTableAdapter3.Fill(Me.DbVPioDataSet.Ministry_Head)

Then in line #13:

Me.TableAdapterManager3.UpdateAll(Me.DbVPioDataSet)

Try changing line #13 to:

Me.TableAdapterManager3.UpdateAll(Me.DbVPioDataSet.Ministry_Head)
cgeier 187 Junior Poster

I don't really have experience with this, but here is some info I found that may or may not be helpful.

This article suggests that compatibility mode creates a new session. And that one should "..set match user agent to FALSE".

cgeier 187 Junior Poster

Not a fix, but here is some info I found that may or may not be helpful.

Document Compatibility Modes in Internet Explorer 9

The above article states that "...an end user can click the Compatibility View button which will cause IE 9 to switch to IE 7 Standards mode..."

Compatability view (quirks mode).

Internet Explorer Compatibility Mode Breaks JQuery

Activating Browser Modes with DocType

cgeier 187 Junior Poster

I haven't really checked this out, nor have I tried to print to a COM port printer, but see if it might help you. The initial post is for DataGrid, but if you scroll down, you will see a file "DataGridViewPrinter.zip" that you can download.

DataGridViewPrinter