1

Solved:

void Download(string folder, string targetfile, string localPath)
{
    var dbx = new DropboxClient(Form1.api);
    var response = await dbx.Files.DownloadAsync(folder + "/" + targetfile);
    ulong fileSize = response.Response.Size;
    const int bufferSize = 1024 * 1024;
    var buffer = new byte[bufferSize];
    string folderName = @"C:\dropboxTest\teasdfst.exe";
    using (var stream = await response.GetContentAsStreamAsync())
    {
        using (var localfile = new FileStream(folderName, FileMode.OpenOrCreate))
        {
            var length = stream.Read(buffer, 0, bufferSize);
            while (length > 0)
            {
                localfile.Write(buffer, 0, length);
               // Console.WriteLine(localfile.);
                var percentage = 100 * (ulong)localfile.Length / fileSize;
                // Update progress bar with the percentage.
                // progressBar.Value = (int)percentage
                //Console.WriteLine(percentage);
                length = stream.Read(buffer, 0, bufferSize);
            }
        }
    }
}
private void button1_Click(object sender, EventArgs e)
{
    string folderName = @"c:\dropboxTest\test.exe";
    var task = Task.Run(() => Download("", "largetest.mpk", folderName));
    task.Wait(); // remove this if you don't want to block UI thread.
}
0

I'm trying to write a program in C# that downloads a file from my DropBox account but I keep getting an error with var task = Task.Run((Func<Task>)Download("", "largetest.mpk", folderName)); The error: Cannot convert type 'System.Threading.Tasks.Task' to 'System.Func<System.Threading.Tasks.Task>

I've been trying to figure it out for multiple hours and haven't had any luck. Any suggestions?

 private void button1_Click(object sender, EventArgs e)
     {
     string folderName = @"c:\dropboxTest\test.exe";

    var task = Task.Run((Func<Task>)Download("", "largetest.mpk", folderName));
    task.Wait();

    }

    async Task Download(string folder, string targetfile, string localPath)
        {
            var dbx = new DropboxClient(Form1.api);
            var response = await dbx.Files.DownloadAsync(folder + "/" + targetfile);
            ulong fileSize = response.Response.Size;
            const int bufferSize = 1024 * 1024;

            var buffer = new byte[bufferSize];
            string folderName = @"C:\dropboxTest\teasdfst.exe";
            using (var stream = await response.GetContentAsStreamAsync())
            {
                using (var localfile = new FileStream(folderName, FileMode.OpenOrCreate))
                {
                    var length = stream.Read(buffer, 0, bufferSize);

                    while (length > 0)
                    {
                        localfile.Write(buffer, 0, length);
                       // Console.WriteLine(localfile.);
                        var percentage = 100 * (ulong)localfile.Length / fileSize;
                        // Update progress bar with the percentage.
                        // progressBar.Value = (int)percentage
                        //Console.WriteLine(percentage);

                        length = stream.Read(buffer, 0, bufferSize);
                    }
                }
            }
        }
0

@JamesCherrill

I tried it many times and done it my self

import java.util.Scanner;

class FareCalculator{
public static void main(String arr[]){
    Scanner s = new Scanner(System.in);
    System.out.print("enter distance covered: ");
    int a = s.nextInt();
    int x=0,y=0;
    if(a<=5){
        System.out.println("fare for first 5KM : 50Rs");
        System.out.println("total distance: " +a+ " fare:50" );
    }   
    else if(a>5&&a<=20)
        {
        System.out.println("first 5 km fare : 50 Rs.");
        x = a-5;
        y=x*12;
        System.out.println("next " +x+ " KM fare @12 : " +y+ " Rs.");
        y=y+50;
        System.out.println("Total fare will be  : " +y+ " Rs.");
    }
    else if(a>20){
        System.out.println("first 5 km fare : 50 Rs.");
        x=20;
        y=20*12;
        System.out.println("next " +x+ " KM fare @12 : " +y+ " Rs.");
        int z = a-20;
        int b = z*14;
        System.out.println("next " +z+ " km  fare @14: " +b+ " Rs.");
        int c=y+b+50;
        System.out.println("Total fare will be  : " +c+ " Rs.");
    }
}   
}
0

Does anybody know whether System.Data.SqlLite has the capability to do a Change notification callback when one of it's tables is changed? I know that Python can do it by calling the C api, but This is kind of beyond me. I know I have done this before on an oracle system, and I know it is possible on a Sql server system, the problem being I have an appication that I wanted to avoid the network overhead and simply use an in-memory database.

0

Thank you @xjr.If I want to add one parameter to the function and save the out put(sec_nucli) in a text file for example, I have try this:

Sec_nucli = 0
def Fragmentation(v,D,xsec):
    sec_nucli = v * n_H * D * xsec
    return sec_nucli

file=open("Secondary.txt", "a")     
for xi in xsec: 
    for Dj in D:
       print(xi, Dj)
     for vj in v:
       Sec_nucli += Fragmentation(vi,Dj, xi)
       print(Sec_nucli)
       s = str(Fragmentation(xi))
       file.write(s + "\n")
file.close()

Dose this correct!! .
Thank you very much for your help

0
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("Nomor Faktur Belum di isi !! ", MsgBoxStyle.Exclamation,
            "Peringatan")
        Else
            Dim simpan1 As String
            CMD = Conn.CreateCommand
            Call bukaDB()
            simpan = "INSERT INTO tbbeli (nofak,tanggal,kodesup,totalitem,totalbayar)VALUES (@p1,@p2,@p3,@p4,@p5)"
            simpan1 = "INSERT INTO tbdetailbeli (nofak,kodebarang,jumlah) VALUES(@p6,@p7,@p8) "
            ubah = "UPDATE tbbarang SET stok=stok+@p9 WHERE kodebarang = @p10"
            With CMD
                .CommandText = simpan
                .Connection = Conn
                .Parameters.AddWithValue("p1", MySqlDbType.String).Value = TextBox1.Text
                .Parameters.AddWithValue("p2", MySqlDbType.DateTime).Value = Format(Now, "dd-MM-yyyy")
                .Parameters.AddWithValue("p3", MySqlDbType.String).Value = ComboBox1.Text
                .Parameters.AddWithValue("p4", MySqlDbType.Int32).Value = Label9.Text
                .Parameters.AddWithValue("p5", MySqlDbType.Int32).Value = Label10.Text
                .ExecuteNonQuery()   "(ERROR IN HERE)"
                Conn.Close()
            End With
            For i As Integer = 0 To DataGridView1.Rows.Count - 2
                CMD = Conn.CreateCommand
                With CMD
                    .CommandText = simpan
                    .Connection = Conn
                    .Parameters.AddWithValue("p6", MySqlDbType.String).Value = TextBox1.Text
                    .Parameters.AddWithValue("p7", MySqlDbType.String).Value = DataGridView1.Rows(i).Cells(0).Value
                    .Parameters.AddWithValue("p8", MySqlDbType.Int32).Value = DataGridView1.Rows(i).Cells(3).Value
                    .ExecuteNonQuery()        "(ERROR IN HERE)"
                    Conn.Close()
                End With
                CMD = Conn.CreateCommand
                With CMD
                    .CommandText = ubah
                    .Connection = Conn
                    .Parameters.AddWithValue("p9", MySqlDbType.UInt32).Value = DataGridView1.Rows(i).Cells(3).Value
                    .Parameters.AddWithValue("p10", MySqlDbType.String).Value = DataGridView1.Rows(i).Cells(0).Value
                    .ExecuteNonQuery()  "(ERROR IN HERE)"
                    Conn.Close()
                End With
            Next
        End If
        Conn.Close()
        CMD.Dispose()
        bersih()
    End Sub
1

Working out the difference between two files is trivial using (like I said earlier) diff and comm, both of which have existed since at least the 1970s.

The two provided files, diffed by word. Red bits have been removed, green added.

Screen_Shot_2018-02-15_at_16_18_03.png

Now, comm outputs three columns

  1. lines only in file 1
  2. lines only in file 2
  3. lines in both files

So by default, lines that were deleted in file 2 will be in column 1, lines that were added in file 2 will be in column 2, and lines that remain unchanged will be in column 3. You can surpress columns using -1, -2 or -3, so we can run the command multiple times to get a nice summary.

Lines deleted in f2:
deleted.png

Lines added in f2:
added.png

Lines unchanged:
unchanged.png

0

Please find the below example,

If file1 has the below data

aimee.neece,aimee,neece,aimee.neece@faculty.asdf.org,aimee neece,aimee neece,"CN=aimee neece,OU=Imported,dc=Faculty,dc=asdf,dc=org"
alexis.andrews,alexis,andrews,alexis.andrews@faculty.asdf.org,alexis andrews,alexis andrews,"CN=alexis
alice.lee,alice,lee,alice.lee@faculty.asdf.org,alice lee,alice lee,"CN=alice lee,OU=Imported,dc=Faculty,dc=asdf,dc=org"
allyson.knanishu,allyson,knanishu,allyson.knanishu@faculty.asdf.org,allyson knanishu,allyson knanishu,"CN=allyson knanishu,OU=Imported,dc=Faculty,dc=asdf,dc=org"

If file2 contains below data

aimee.neece,aimee,neece,aimee.neece@faculty.asdf.org,aimee neece,aimee neece,"CN=aimee
alexis.andrews,alexis,andrews,alexis.andrews@faculty.asdf.org,alexis andrews,alexis andrews,"CN=alexis
alice.lee,alice,lee,alice.lee@faculty.asdf.org,alice lee,alice lee,"CN=alice lee,OU=Imported,dc=Faculty,dc=asdf,dc=org"
allyson.knanishu,allyson,knanishu,allyson.knanishu@faculty.asdf.org,allyson knanishu,allyson knanishu,"CN=James knanishu,OU=Imported,dc=Faculty,dc=asdf,dc=org"
andrews,OU=Imported,dc=Faculty,dc=asdf,dc=org"

From the file2,

2nd line ie, "neece,OU=Imported,dc=Faculty,dc=asdf,dc=org" is deleted. This should be printed in deleted list.
New line ie, "andrews,OU=Imported,dc=Faculty,dc=asdf,dc=org" is added in file2. This should be printed in new line added list.
allyson is updated to James in file2. Which should be printed in updated lines list.

0

i just wanted to update my code here as it has changed.

with open(filename, "rb") as binaryfile:
    while True:
        read_file = binaryfile.read()
        if len(read_file):
            for find_bytes in re.finditer(bytes1, read_file):
                with open("foundhex.txt", "a") as found1:
                    found1.write("Found bytes at : " + str(find_bytes.start()) + " " +str(find_bytes.end()) + "\n")
        else:
            break

this code finds all occurences of bytes1. I am still trying to figure out how to find the 6 bytes before bytes1. there was an idea to use slice but im not sure how to use it with the code i have now (for loop). i was thinking something like:

find_prevbytes = read_file[find_bytes -6:6]

but ofc theres the TypeError.

0

thank you for your reply woooee. ive ended up with this code, using re.finditer

import re

with open(filename, "rb") as binaryfile:
    while True:
        read_file = binaryfile.read()
        if len(read_file):
            for find_bytes in re.finditer(bytes1, read_file):
                with open("foundhex.txt", "a") as found1:
                    found1.write("Found bytes at : " + str(find_bytes.start()) + " " +str(find_bytes.end()) + "\n")
        else:
            break

it finds all occurences of bytes1

0

Hello dear forum members,

I am brand new in C programming and have to program an "X" as homework (see attached picture).
The edge length of the "X's" should be entered by the user, ie the "X" should be arbitrarily large or small.

Can someone help me with the task?

So far I have the following code:

include <stdio.h>
     int main () {
     int edge length, i;
     printf ("Please enter the edge length of the pattern: \ n");
     scanf ("% d", & edge length);
    
     char sign;
     character = '';
    
     for (i = 0; i <edge length; i ++) {
     printf ("-% c- \ n", character);
    
     }
     return 0;
     }