Code Konvertieren

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von Matix Media.

    Code Konvertieren

    Hallo Menschen,

    ich habe leider gerade ein Problem mit sämtlichen Online code Convertern.

    Kann mir bitte jemand diesen C# Code zu VB.Net Konvertiern? Vielen Dank im vorraus!

    C#-Quellcode

    1. Directory.CreateDirectory(filePath.Replace(".zip", ""));
    2. zip.ExtractAll(filePath.Replace(".zip", ""), ExtractExistingFileAction.OverwriteSilently);
    3. zip.SaveProgress += (o, args) =>
    4. { //Fix this, not showing percentage of extraction.
    5. var percentage = (int)(1.0d / args.TotalBytesToTransfer * args.BytesTransferred * 100.0d);
    6. clearLine();
    7. Console.Write(percentage);
    8. };
    9. } using (ZipFile zip = ZipFile.Read(filePath))
    10. {
    11. Directory.CreateDirectory(filePath.Replace(".zip", ""));
    12. zip.ExtractAll(filePath.Replace(".zip", ""), ExtractExistingFileAction.OverwriteSilently);
    13. zip.SaveProgress += (o, args) =>
    14. { //Fix this, not showing percentage of extraction.
    15. var percentage = (int)(1.0d / args.TotalBytesToTransfer * args.BytesTransferred * 100.0d);
    16. clearLine();
    17. Console.Write(percentage);
    18. };
    Grüße, Matix
    Ok, kein Problem (habe schon ein paar enderungen Vorgenommen, deshalb gut nachdenken bein Kopieren xD)

    VB.NET-Quellcode

    1. Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    2. Try
    3. Dim ZipToUnpack As String = tbFile.Text
    4. Dim TargetDir As String = tbdestination.Text
    5. BeginInvoke(Sub() lvStatus.Items(1).SubItems(1).Text = "Extrahiere Archiv """ & ZipToUnpack & """ zu """ & TargetDir & """")
    6. Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
    7. AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress
    8. 'reset these values each time you unzip a folder
    9. BufferSize = CULng(zip1.BufferSize)
    10. TotalSize = 0
    11. ExtractedSize = 0
    12. 'get the total size in bytes to be extracted
    13. For Each ent As ZipEntry In zip1
    14. TotalSize += CULng(ent.UncompressedSize)
    15. Next
    16. 'if the total size is greater than Integer.MaxValue then divide it down by 1024 before setting the ProgressBar.Maximum
    17. If TotalSize >= Integer.MaxValue Then
    18. BeginInvoke(Sub() ProgressBar1.Maximum = CInt(TotalSize / 1024))
    19. Else
    20. BeginInvoke(Sub() ProgressBar1.Maximum = CInt(TotalSize))
    21. End If
    22. Dim e_ As ZipEntry
    23. ' here, we extract every entry, but we could extract
    24. ' based on entry name, size, date, etc.
    25. For Each e_ In zip1
    26. BeginInvoke(Sub() lvStatus.Items(1).SubItems(1).Text = "Extrahiere Datei """ & e_.FileName & """...")
    27. BeginInvoke(Sub() lvStatus.Items(1).ToolTipText = "Extrahiere Datei """ & e_.FileName & """...")
    28. If File.Exists(TargetDir & "\" & e_.FileName.Replace("/", "\")) Then
    29. If MsgBox("Wollen Sie folgende Datei Überschreiben? """ & TargetDir & "\" & e_.FileName.Replace("/", "\") & """", MsgBoxStyle.YesNo, "Überschreiben") = MsgBoxResult.Yes Then
    30. e_.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)
    31. Else
    32. End If
    33. Else
    34. e_.Extract(TargetDir, ExtractExistingFileAction.DoNotOverwrite)
    35. End If
    36. Next
    37. End Using
    38. BeginInvoke(Sub() lvStatus.Items(1).SubItems(1).Text = "Abgeschlossen.")
    39. BeginInvoke(Sub() lvStatus.Items(2).SubItems(1).Text = """" & ZipToUnpack & """ Erfogreich Extrahiert.")
    40. BeginInvoke(Sub() GroupBox1.Enabled = True)
    41. BeginInvoke(Sub() GroupBox2.Enabled = True)
    42. BeginInvoke(Sub() Button3.Enabled = True)
    43. BeginInvoke(Sub() lvErrors.Items.Clear())
    44. Catch ex As Exception
    45. Invoke(Sub() lvErrors.Items.Add(ex.Message))
    46. BeginInvoke(Sub() GroupBox1.Enabled = True)
    47. BeginInvoke(Sub() GroupBox2.Enabled = True)
    48. BeginInvoke(Sub() Button3.Enabled = True)
    49. BeginInvoke(Sub() lvStatus.Items(0).SubItems(1).Text = "Fehler!")
    50. BeginInvoke(Sub() lvStatus.Items(1).SubItems(1).Text = "Fehler!")
    51. BeginInvoke(Sub() lvStatus.Items(2).SubItems(1).Text = "Fehler!")
    52. End Try
    53. End Sub
    54. Async Sub MyExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
    55. 'if the reported BytesTransferred is greater than 0 then add the number of bytes that where transferred to the ExtractedSize variable
    56. 'and set the LastBtsTransfered to the number of bytes that have been transferred so far. Else reset the LastBtsTransfered to 0.
    57. If e.BytesTransferred > 0 Then
    58. ExtractedSize += CULng(e.BytesTransferred - LastBtsTransfered)
    59. LastBtsTransfered = CULng(e.BytesTransferred)
    60. Else
    61. LastBtsTransfered = 0
    62. End If
    63. 'again, if the total size is greater than Integer.MaxValue then divide the ExtractedSize by 1024 before setting the ProgressBar.Value
    64. If TotalSize >= Integer.MaxValue Then
    65. BeginInvoke(Sub() ProgressBar1.Value = CInt(ExtractedSize / 1024))
    66. Else
    67. BeginInvoke(Sub() ProgressBar1.Value = CInt(ExtractedSize))
    68. End If
    69. End Sub
    Grüße, Matix
    @Matix Media Sobald Du zwei und mehr Invokes nacheinander stehen hast, pack die in eines:

    VB.NET-Quellcode

    1. BeginInvoke(Sub()
    2. lvStatus.Items(0).SubItems(1).Text = "Fehler!")
    3. lvStatus.Items(1).SubItems(1).Text = "Fehler!")
    4. lvStatus.Items(2).SubItems(1).Text = "Fehler!"
    5. End Sub
    6. )
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!