Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 17:39

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



VB Code in C# [HILFE]

Discussion on VB Code in C# [HILFE] within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
°Showii's Avatar
 
elite*gold: 33
Join Date: Oct 2011
Posts: 100
Received Thanks: 48
VB Code in C# [HILFE]

Hallo ich brauche einmal eue Hilfe. Ich benötige diesen Code in C#, doch wenn ich ihn in einem Converter eingebe convertiert er falsch.



VB-Code:
HTML Code:
  Public Function ReadLine(ByVal sFile As String, _
    Optional ByVal nLine As Long = 1) As String

        Dim sLines() As String
        Dim oFSO As Object
        Dim oFile As Object

        ' Fehlerbehandlung aktivieren
        On Error GoTo ErrHandler

        ' Verweis auf das FileSystemObject erstellen
        oFSO = CreateObject("Scripting.FileSystemObject")

        ' Existiert die Datei überhaupt?
        If oFSO.FileExists(sFile) Then
            ' Datei öffnen
            oFile = oFSO.OpenTextFile(sFile)

            ' Alles lesen und in Array zerlegen
            sLines = Split(oFile.ReadAll, vbCrLf)

            ' Datei schließen
            oFile.Close()

            Select Case Math.Sign(nLine)
                ' (nLine > 0)
                Case 1
                    ' n-te Zeile von vorne beginnend
                    ReadLine = sLines(nLine - 1)

                    ' (nLine < 0)
                Case -1
                    ' n-te Zeile von hinten beginnend
                    ReadLine = sLines(UBound(sLines) + nLine + 1)
            End Select
        End If

ErrHandler:
        ' Objekte zerstören
        oFile = Nothing
        oFSO = Nothing
    End Function

C# Code nach Converter:
HTML Code:
public string ReadLine(string sFile, long nLine = 1)
{
	string functionReturnValue = null;

	string[] sLines = null;
	object oFSO = null;
	object oFile = null;

	// Fehlerbehandlung aktivieren
	 // ERROR: Not supported in C#: OnErrorStatement


	// Verweis auf das FileSystemObject erstellen
	oFSO = Interaction.CreateObject("Scripting.FileSystemObject");

	// Existiert die Datei überhaupt?
	if (oFSO.FileExists(sFile)) {
		// Datei öffnen
		oFile = oFSO.OpenTextFile(sFile);

		// Alles lesen und in Array zerlegen
		sLines = Strings.Split(oFile.ReadAll, Constants.vbCrLf);

		// Datei schließen
		oFile.Close();

		switch (Math.Sign(nLine)) {
			// (nLine > 0)
			case 1:
				// n-te Zeile von vorne beginnend
				functionReturnValue = sLines[nLine - 1];

				break;
			// (nLine < 0)
			case -1:
				// n-te Zeile von hinten beginnend
				functionReturnValue = sLines[Information.UBound(sLines) + nLine + 1];
				break;
		}
	}
	ErrHandler:

	// Objekte zerstören
	oFile = null;
	oFSO = null;
	return functionReturnValue;
}
vielen Dank im Vorraus.

mfg. Showii
°Showii is offline  
Old 10/20/2011, 17:35   #2
 
Kraizy​'s Avatar
 
elite*gold: 0
The Black Market: 471/0/0
Join Date: Apr 2010
Posts: 9,696
Received Thanks: 1,811
Nimm doch einfach einen StreamReader. Und entferne das Goto.
Kraizy​ is offline  
Reply


Similar Threads Similar Threads
[S] Hilfe... EA Code in use?!
06/03/2011 - Steam Trading - 2 Replies
Hallo. ich habe im black market einen ea account mit den spielen medal of honor und battlefield bad company 2 gekauft. als ich jedoch fertig mit downloaden war und den multiplayer anzocken wollte, kam eine meldung, dass der key bereits genutzt wird. was kann ich nun tun? wer mir weiter hilft kriegt 1 egold^^
BB code hilfe
01/22/2011 - WarRock - 10 Replies
#Closerequest Problem gelöst
BB code hilfe
01/22/2011 - General Coding - 1 Replies
hallo, Ich möchte in meine signatur einen spoiler machen und in dem spoiler soll iene tabelle sein in der meine kontacktmöglichkeiten stehen kann mir da einer helfen hab das bei einem anderen user gesehen und möchte dies auch haben
Hilfe für Code
11/29/2010 - AutoIt - 10 Replies
hi ich wollte ein programm machen, dass wenn ich eine taste drücke (z.b. f) dass es dann von selbst 7mal die linke maustaste drückt. Und das ganze in dem prozess: engine.exe . Ich habe schon im help file usw gesucht aber ich finde keinen passenden befehl dazu, könnt ihr mir bitte helfen bin noch noob in autoit :D
Hilfe bei Hex?Code
07/19/2009 - Flyff - 3 Replies
Hallo, hat jmd von euch ne Idee, wozu heiordas gehört? It was '00 00 2a 00 ff ff ff ff 00 00 00 00 00 00 80 bf MfG DT



All times are GMT +1. The time now is 17:39.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.