Chair 17 Light Poster

Hi, if somebody can help me..
On main form, I have this set of alphabet letters and a datagridview. Each letter represents the first letter of each item in the datagrid. When a letter has items in the datagrid, it's underlined to show that it's clickable; no items=not clickable. When I click Edit to a row in the datagrid, another form comes up, and after I save the form, it should update the set of alphabet. So, if an item starts with letter A,A shows as clickable. But if I change it to B and save,letter B should now show as clickable, and A not.

Here are the relevant code snippets:

//on main form
public partial class FormMain : Form
    {
        
        Label[] lblalpha = null;

public FormMain()
        {
            InitializeComponent();
            lblalpha = new Label[26];

        }

        public FormMain(Label[] emplalpha,TabPage empltabpage)
        {
            InitializeComponent();
            lblalpha = emplalpha;
            tabPage2 = empltabpage;

        }

//function to create the alphabet
public void createAlphabet()
        {
            
            int x = 150;
            int y = 51;
            lblalpha = new Label[26];
            string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            char[] array = alphabet.ToCharArray();

            for (int i = 0; i < array.Length; i++)
            {
                
                char letter = array[i];
                lblalpha[i] = new Label();
                lblalpha[i].Text = letter.ToString();
                lblalpha[i].Location = new Point(x, y);
                lblalpha[i].Size = new Size(15, 13);

                Class1.readrecord("Select * from dbo.displayemplbylastname('" + lblalpha[i].Text + "')");
                if (Class1.dr.HasRows)
                {
                    lblalpha[i].ForeColor = Color.Blue;
                    lblalpha[i].Cursor = Cursors.Hand;
                    lblalpha[i].Font = new Font(lblalpha[i].Font, FontStyle.Underline);

                }
                Class1.con.Close();

                tabPage2.Controls.Add(lblalpha[i]);
                lblalpha[i].Click += new System.EventHandler(lblalpha_Click);
                x += 25;

            }

        }

//function to clear the alphabet
public …
Chair 17 Light Poster

"Clear the loop". I knew it was silly :=) I was adding "Controls" so what I needed was to clear them. Of course. What a blooper :=) Found my solution. I have to add this into my lblalpha_Click (before the loadgridview line):

for (int i = pagecount; i >= 1; i--)
            {
                this.panel1.Controls.Remove(lblpage[i]);
            }

To all who took peeks into this post (and were probably shaking their heads at the silliness), thanks for your time :=)

Chair 17 Light Poster

Hi,

Is there a way to "clear a previous loop and form a fresh new loop"? I'm paging my datagrid. Upon form_load, it shows all records in batches of for example 10, which I can set in a textbox. If for example I have 60 records, then my loop code produces lblpage.Text 1 2 3 4 5 6. These labels when clicked, show the correct batch of records in the datagrid. Now, if I click letter A to mean show all records that start with A (for example it has 15 records), then that same loop code should produce lblpage.Text 1 2.

Here's my code:

private void loadgridview(string gridviewquery,string countquery)
        {

            Class1.displayempl(dataGridViewempl, gridviewquery); //load gridview
            
            //create page numbers
            int x = 103;
            int y = 6;
            int recordcount = getnumofrecords(countquery);
            int pagecount = (recordcount/int.Parse(txtpagesize.Text)); 
            if ((recordcount % int.Parse(txtpagesize.Text)) > 0) //to compute for partial page if any
                pagecount++;  //if partial page, make it still 1 page
           
            lblpage = new Label[pagecount+1];
            
            for (int i = 1; i <= pagecount; i++)
            {
                
                lblpage[i] = new Label();
                lblpage[i].Text = i.ToString();
                lblpage[i].Location = new Point(x, y);
                lblpage[i].Size = new Size(15, 13);
                lblpage[i].ForeColor = Color.Blue;
                lblpage[i].Cursor = Cursors.Hand;
                lblpage[i].Font = new Font(this.Font, FontStyle.Underline);
                this.panel1.Controls.Add(lblpage[i]);
                lblpage[i].Click += new System.EventHandler(lblpage_Click);
                x += 25;
            
            }
            

        }

//upon form_load
private void FormMain_Load(object sender, EventArgs e)
        {

loadgridview("Select TOP " + int.Parse(txtpagesize.Text) + " * from dbo.displayallempl()", "Select COUNT(*) from dbo.displayallempl()");
}


//upon clicking for example letter A
private void lblalpha_Click(object sender, EventArgs e)
        {
letter = …
Chair 17 Light Poster

And I thought that was taken cared of by the .Location, spaced wide apart :=)

Chair 17 Light Poster

Yup! That's exactly what happened, only letter A showed. Thanks so much for this! :=)

Chair 17 Light Poster

Wow, thanks thanks so much Mitja! It does help. I'm really grateful. I'm tweaking my code; I want to understand what's the difference between your code and mine. And I found out that I lack this line:

lbls.Size = new Size(15, 13);

I added that, and just retained my code inside my form_load, and it now works. Why do you think is that? :=)

Chair 17 Light Poster

Hi,

I need to have all the letters of the alphabet displayed across my tabpage, with each letter clickable. Can someone pls help me; I can't get this right, I only have the letter A displayed:

Label[] lblalpha = null;
            lblalpha = new Label[26];
            string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            char[] array = alphabet.ToCharArray();

            for(int i=0; i < array.Length; i++)
            {
                char letter = array[i];
                lblalpha[i] = new Label();
                lblalpha[i].Visible = true;
                lblalpha[i].Text = letter.ToString();
                lblalpha[i].Location = new Point(74 + 2*i, 51);
                lblalpha[i].Cursor = Cursors.Hand;
                lblalpha[i].Enabled = true;                
                this.tabPage2.Controls.Add(lblalpha[i]);
                lblalpha[i].Click += new System.EventHandler(lblalpha_Click);
            }

Appreciate so much any help. Thanks in advance!

Chair 17 Light Poster

Oops, OK, I just found out I can't cast it into a checkbox, but I can cast it into a boolean type, the same code I used above in reply to @ddanbe.

And so, here's the complete code that works now:

private void FormMain_Load(object sender, EventArgs e)
        {
Class1.displayempl(dataGridViewempl);
            dataGridViewempl.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(dataGridViewempl_CellClick);
}

private void dataGridViewempl_CellClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
if (dataGridViewempl.CurrentCell.ColumnIndex == 6)
                    {
                        if (dataGridViewempl.CurrentCell.Value != null)
                        {
                        dataGridViewempl.BeginEdit(true);
                        bool checkstate = (bool)dataGridViewempl.CurrentCell.Value;

                        if (checkstate == false)
                            dataGridViewempl.CurrentCell.Value = true;
                        else
                            dataGridViewempl.CurrentCell.Value = false;
                        }
                        else

                    dataGridViewempl.CurrentCell.Value = true;
                    }
}

To @ddanbe and @abelLazm, thanks so much for the solutions. And to all the others, for your time :=)

Chair 17 Light Poster

@abelLazm: OMG! You saved me, you you! I'm so so grateful :=) I've been reading msdn and about DataGridView and explored their sample codes there on the off-chance something will work but just made my head ache. And here you are with this clean code...

Questions:
1. What does this mean?

this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(dataGridView1_CellClick);

2. It doesn't work if I cast it into a checkbox, like what I did with my code. And so now I'm curious why it has to be .Value.ToString().ToUpper() == "FALSE" and not just .Value.ToString() == "False" or "false".

I'm so relieved with your solution. Again, thanks so much!

Chair 17 Light Poster

And it doesn't work at all still..

Chair 17 Light Poster

Oops, sorry, wrong code..I was tweaking and adding/removing and re-arranging my code, guess I did not remove some..Here's the correct one:

if (dataGridViewempl.CurrentCell.ColumnIndex == 6)
            {
                
                if (dataGridViewempl.CurrentCell.Value != null)
                {
                    bool checkstate = (bool)dataGridViewempl.CurrentCell.Value;

                    if (checkstate == false)
                        dataGridViewempl.CurrentCell.Value = true;
                    else
                        dataGridViewempl.CurrentCell.Value = false;

                }
                else
                    dataGridViewempl.CurrentCell.Value = true;

            }
Chair 17 Light Poster

Hi ddanbe,
Thanks for pointing the article. I've revised my code, but still it doesn't work:

if (dataGridViewempl.CurrentCell.ColumnIndex == 6)
            {
                if (dataGridViewempl.CurrentCell.FormattedValueType == Type.GetType("System.String"))
                if (dataGridViewempl.CurrentCell.Value != null)
                {
                    bool checkstate = (bool)dataGridViewempl.CurrentCell.Value;

                    if (checkstate == false)
                        dataGridViewempl.CurrentCell.Value = true;
                    else
                        dataGridViewempl.CurrentCell.Value = false;

                }
                else
                    dataGridViewempl.CurrentCell.Value = true;

            }

@Mitja -- that's alright :=) I'm still trying to solve this.

Chair 17 Light Poster

Oh OK. I'm not relieved after all :=( EditOnEnter lets me edit any of my columns and I don't want that. This is getting frustrating...

Chair 17 Light Poster

OMG, I just found the solution. My code is correct, the property of my datagrid is not. EditMode should have been EditOnEnter. I set it as EditProgrammatically because I'm so used to doing that :=)

Whew, I'm just so relieved. Thanks all!

Chair 17 Light Poster

Hi all,

Thanks for your feedback. However, none of them didn't do it. I don't understand why this is so difficult when this is relatively easy in VB :=) Even I can't find any solution in the internet.

@Mitja -- Thanks! But I don't understand; your code involves a combobox, not a checkbox? I'm probably missing something..

Still trying to tweak my code..

Chair 17 Light Poster

Hi,

Can someone help me pls why this doesn't seem to work?

private void dataGridViewempl_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
            if (dataGridViewempl.CurrentCell.ColumnIndex == 6)
            {
                CheckBox deletebox = new CheckBox();
                deletebox = (CheckBox)dataGridViewempl.CurrentCell.Value;

                if (deletebox != null)
                {
                    if (deletebox.Checked == false)
                        deletebox.Checked = true;
                    else
                        deletebox.Checked = false;
                }

            }
           
        }

Really appreciate it. Thanks much!

Chair 17 Light Poster

OK, thanks for the advice then!

Chair 17 Light Poster

Hi all,

Thanks so much for your feedback. Unfortunately, "Adding one return statement at the end will solve a problem" did not do it. I've tried using Mitja's and skamatic's code, but it always returned a null or "" value. I still haven't figured out WHY. BUT I've figured out a different way:

public string loggedinuser()
        {
           
            Class1.readrecord("Select dbo.loggeduser('" + txtusername.Text + "','" + txtpassword.Text + "')");
            Class1.dr.Read();
            string name = (Class1.dr[0].ToString());
            Class1.con.Close();
            return name;

        }

(I transferred my function to the login form). And I have other lines of code that take care of catching if login info is not found. Here are the rest of my code in my login form:

public string getloggeduser
        {
            get { return loggedinuser(); }

        }
        
        
        private void btnlogin_Click(object sender, EventArgs e)
        {
            if ((txtusername.Text == String.Empty) || (txtpassword.Text == String.Empty))
            {
                lblwarning.Visible = true;

            }
            else
            {

                Class1.readrecord("Select * from dbo.logininfo('" + txtusername.Text + "','" + txtpassword.Text + "')");
                if (Class1.dr.Read())
                {
                    Class1.con.Close();
                    lblwarning.Visible = false;
                    FormMain formmain = new FormMain();                   
                    formmain.setloggeduser = getloggeduser;
                    this.Hide();
                    formmain.Show();

                }
                else
                {
                    lblwarning.Visible = true;
                    lblwarning.Text = "Invalid username/password.";
                    txtpassword.Clear();

                }
                Class1.con.Close();
                
            }

It works fine :=) You may have some thoughts to tweak the code a little more. I'd be grateful still.

To abelLazm: You can try to be a little nice, and just say "this might work" and stop there. Saying what you did does not help at all. I see you're a "virtuoso" now, but when you were …

abelLazm commented: Well done +11
Chair 17 Light Poster

Hi, can someone pls help me.

I'm trying to pass the name of the user who logs in from a login form and display his/her name on a Main form. I'm using get{} and set{}. My problem is with the function I'm trying to create to return the name of the user which I'm going to place inside my get{}. Here's my function (I've placed this within a Class):

public static string loggedinuser(TextBox uname,TextBox password)
        {
            
            readrecord("Select dbo.loggeduser('" + uname.Text + "','" + password.Text + "')");
            if (dr.Read())
            {
                
                while (dr.Read())
                {                   
                    string name =(dr[0].ToString());
                    return name;
                    
                }
                
            }
            con.Close();
                       
        }

It's showing this error "Not all code paths return a value." I don't understand. I already have the return statement.

If somebody can help me, I'm most grateful. Thanks so much in advance!

Chair 17 Light Poster

Hi,

I guess I really have to stop asking this forum UNTIL I have exhausted everything to solve my problem :=) I just solved this from reading another thread from another webforum. It just didn't occur to me. Inside my repeater tag, I put a line OnItemCommand="selectitem". Then I compiled. It shows an error because I should put this method in my code-behind (even if I still don't have the codes inside it yet):

Protected sub selectitem(ByVal Sender As Object, ByVal e As RepeaterCommandEventArgs

End sub

I didn't know that. I really had an intention to put this (because it's obviously my code to edit my RepeaterItem), but later. I didn't know it could throw an error :=)

Chair 17 Light Poster

Pls can somebody help me. I'm developing a project using ASP.net. In my project, I'm using a repeater. But I can't seem to use OnItemCommand or OnCommand. It's showing this compilation error, e.g. BC30456: 'selectitem' is not a member of 'ASP.usermainform_aspx'. This error shows in all repeaters across my forms AND it also shows even if I create a new different Project and create a new repeater there.

I'm using Visual Web 2008 Express Edition. Appreciate any help.

Chair 17 Light Poster

WELL, I've solved this (again) :=) Just in case, someone has the same problem: The solution is putting tblPassenger on a Crystal Report sub-report, and then link that to a primary field in the main report (in this case, PONumber is my primary field); you can do this linking through the Crystal Report Sub-report wizard. Then place this code on Form_Load of your report:

Dim con as New SqlConnection("your connection string")
Dim com as New SqlCommand
Dim adapt as New SqlDataAdapter
Dim ds as New DataSet
Dim rptdocument as New ReportDocument
Dim viewer as CrystalDecisions.Windows.Forms.CrystalReportViewer

con.Open()
        com.Connection = con
        com.CommandText = "yourquery"
        adapt.SelectCommand = com
        adapt.Fill(ds, "yourtable")
        rptdocument.Load("yourreportpath") 
        rptdocument.SetDataSource(ds)
        viewer.ReportSource = rptdocument
        viewer.RefreshReport()
        con.Close()
Chair 17 Light Poster

Hi,

I'm making a printable Purchase Order form using Crystal Report. This report retrieves data from two tables. Example, I have fields PONumber,DateofPO,Airline,DateofFlight,ETA,ETD from a table called tblFlight. I have fields PassengerName and Rate on another table called tblPassenger. Each PONumber can have multiple passengers. How can I get it so that I'll just be generating one PO that shows the multiple passengers while the rest of the items show only once? I've placed the PONumber and DateofPO on the PageHeader and the rest of the items on the Details section. But right now, on the Details section, if I have 3 passengers, the other fields also show 3 times on the report. Also, I'm considering to make a query but I have a conditional statement on my query, a WHERE clause that retrieves data dynamically. My problem is I'm not sure where to put the query, will it be on the .rpt or just on the Form? NOTE: I'm coding my SQL queries on the application itself, not inside the server, so no stored procedures/functions for me here.

Would greatly appreciate any help. Thanks in advance.

Chair 17 Light Poster

Hi,

Just want to post here that I finally solved my problem. Instead of using this code,

For x As Integer = 0 To (DataGridView1.Rows.Count() - 1)

I needed to have these lines:

For Each row as DataGridViewRow In DataGridView1.Rows
                    If Not row.IsNewRow Then

Whew. I'm just so relieved.

AndreRet commented: Well done on solving this yourself. +6
Chair 17 Light Poster

Hi CodeWord/Vegasvidiot, thanks for replying!

Re: this:

VB.NET Syntax (Toggle Plain Text)

1.
For Each row As DataGridViewRow In DataGridView1.Rows
2.
Listview1.Items.Add(row.Cells("ColumnName").Value)
3.
Next

I tried it. The error says "Overload resolution failed because no Public 'Add' is most specific for these arguments: 'Public Overrides Function Add(text As String) As System.Windows.Forms.ListViewItem': Not most specific. 'Public Overrides Function Add(value As System.Windows.Forms.ListViewItem) As System.Windows.Forms.ListViewItem': Not most specific." I don't understand what this means :=) I tried to use an index too but I got the same error.

Also how about if the listview has multiple columns? Shouldn't I use a SubItem? I can't have a subitem property directly from the listview.

I tried this:

For Each row As DataGridViewRow In DataGridViewCart.Rows
            Dim rowlist As DataRow
            Dim item As ListViewItem = New ListViewItem(rowlist(row.Cells("Number").Value).ToString)
            item.SubItems.Add(rowlist(row.Cells("AmountDue").Value).ToString)
            FormPayment.listduePOs.Items.Add(item)

        Next

But it still doesn't work. Sigh :=(

Thanks much!

Chair 17 Light Poster

Sorry, wrong post above. Here's the correct one:

Hi,

Do you think it's because there's something wrong with how I programmatically created my datagrid? I did it this way:

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

DataGridView1.Columns.Add("Name", "Name")
DataGridView1.Columns.Add("AmtDue", "Amount Due")

Anyone please? Someone?

Chair 17 Light Poster

Hi,

Do you think it's because there's something wrong with how I programmatically created my datagrid? I did it this way:

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

DataGrid1.Columns.Add("Name", "Name")
DataGrid1.Columns.Add("AmtDue", "Amount Due")

Anyone please? Someone?

Chair 17 Light Poster

Oops sorry, it wasn't included within the CODE tags. Pls look at my code above, the operators trailed behind

Chair 17 Light Poster

Hi,

I want to populate a listview with items from datagrid view. I've been searching for solutions but it seems that all the scenarios I found were about populating listview with items from tables in database, not from another listview or datagrid view.

I'm trying this code:

For count As Integer = 0 To (DataGridView1.Rows.Count() - 1)
                    Dim row As DataRow = DataGridView1.Rows(count)
                    Dim item As ListViewItem = New ListViewItem(row(fieldfirstcol).ToString())
                    item.SubItems.Add(row(fieldsecondcol.ToString()))
                    ListView1.Items.Add(item)

but it doesn't work; it says DataGridViewRow cannot be converted to DataRow.

Appreciate any help. Thanks much!

Chair 17 Light Poster

Hi, thanks for replying! But is it possible to have the data successfully saved to the table if there's an error like this?

The error is pointing to this line --

Class1.readrecord("Select * from myTable where Name='" + DataGridView1.Rows(x).Cells(1).Value.ToString + "

'")

but I see that it's reading myID fine because this line

Class1.insertrecord("Insert into amtdue(nameID,name,amount) values('" + myID.ToString + "','" + DataGridView1.Rows(x).Cells(1).Value.ToString + "','" + CType(DataGridView1.Rows(x).Cells(2).Value,Double).ToString + "')")

has been successfully inserted into the table.

I don't understand :=)

Chair 17 Light Poster

Hi,

I'd like to get the value of a column from a datagrid and insert that to a table. I get an error "Object reference not set to an instance of an object."

Here's my code:

Imports System.Data.SqlClient
Imports System.Data
Public Class Class1

Public Shared Sub insertrecord(ByVal query As String)
        con.Open()
        com.Connection = con
        com.CommandText = query
        com.ExecuteNonQuery()
        con.Close()

End Sub

Public Shared Sub readrecord(ByVal query As String)
        con.Open()
        com.CommandText = query
        com.Connection = con
        dr = com.ExecuteReader

    End Sub

End Class

Public Class FormRentals

Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click

Dim indx As Integer = DataGridView1.Rows.Add()
                DataGridView1.Rows(indx).Cells(0).Value = (indx + 1).ToString
                DataGridView1.Rows(indx).Cells(1).Value = txtboxName.Text
                DataGridView1.Rows(indx).Cells(2).Value = FormatNumber(txtboxamt.Text,2).ToString

End Sub

Private Sub btnaddtocart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddtocart.Click

'This generates a primary key called ID that is set to be identity(1,1)
Class1.insertrecord("Insert into myTable(Name) values('" + txtboxName.Text + "')")

For x As Integer = 0 To (DataGridView1.Rows.Count() - 1)
     Class1.readrecord("Select * from myTable where Name='" + DataGridView1.Rows(x).Cells(1).Value.ToString + "'")
     If Class1.dr.Read() then
       Dim myID as Integer = Class1.dr("ID")
       Class1.con.Close
       Class1.insertrecord("Insert into amtdue(nameID,name,amount) values('" + myID.ToString + "','" + DataGridView1.Rows(x).Cells(1).Value.ToString + "','" + CType(DataGridView1.Rows(x).Cells(2).Value,Double).ToString + "')")
     End if
     Class1.con.Close

End Sub

End Class

The thing is -- when I look at table amtdue, everything is actually saved there. I just don't understand why I'm getting the error, and so I can't proceed with what I have to do after clicking the btnaddtocart button.

Would really appreciate any …

Chair 17 Light Poster

Hi Junior Poster in Training,

Thanks thanks so much! I got it..I just added added an index=1 and used it to assign to the dr.Item(0), instead of using the variable in my for loop:

My revised code for remove:

Dim indx As Integer = 1
            For x As Integer = 0 To (DataGridViewPassengers.Rows.Count() - 1)
                DataGridViewPassengers.Rows(x).Cells(0).Value = indx.ToString
                indx = indx + 1
            Next

Thanks so much! Appreciate it! :=)

Chair 17 Light Poster

Hi,

I need help in numbering rows in datagrid. I have a column that should number 1,2,3 so on when adding a new row. When I delete a row, those numbers should re-number still to 1,2,3. So when I delete row 2, the row that's been added as 3 should now number to 2. Then when I add new rows, these should re-number again, and so on..

My code:

'when adding a new row
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click

Dim indx As Integer = DataGridViewPassengers.Rows.Add()
                DataGridViewPassengers.Rows(indx).Cells(0).Value = (indx + 1).ToString
                DataGridViewPassengers.Rows(indx).Cells(1).Value = txtdocnumber.Text
                DataGridViewPassengers.Rows(indx).Cells(2).Value = txtdatebook.Text
                

For x As Integer = 1 To (indx + 1)
                    lblnumpass.Text = x.ToString + " Passenger(s) added for this Flight"

                Next

'when deleting a row

 Private Sub btnremovepass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremovepass.Click

DataGridViewPassengers.Rows.Remove(DataGridViewPassengers.CurrentRow)
            
For x As Integer = 1 To (DataGridViewPassengers.Rows.Count() - 1)
      DataGridViewPassengers.Rows(x).Cells(0).Value = x.ToString

Next

lblnumpass.Text = (DataGridViewPassengers.Rows.Count() - 1).ToString + " Passenger(s) added for this Flight."

My problem is with the for loop when deleting a row. I'm missing something and can't solve it.

Wish someone would help me, would really appreciate it. Thanks so much in advance!

Chair 17 Light Poster

Hi, I've been searching all over trying to find an answer to my problem about reading/writing text files. I saw this very old post/code snippet and am wondering if you could help me with my own:

How about if I have this input file:

39882 M 7:45 18:16 10 hours 31 mins 900.00
39882 T 8:00 17:45 9 hours 45 mins 800.00
39882 W 7:56 17:30 9 hours 34 mins 800.00
39882 T 8:02 18:01 9 hours 59 mins 800.00
39882 F 7:57 18:05 10 hours 8 mins 900.00
39882 S 8:15 17:35 9 hours 20 mins 800.00
39882 S 8:00 17:30 9 hours 30 mins 800.00

And I want to read it and write to another text file like so:

39882 68 hours 47 mins 5800.00

It sums up the hours (int), mins (int), and the amount (float).
How do I go about reading and writing it so I get only one 39822 (char id)?

Thanks so much in advance!