[Community Projekt] OpenLib

Es gibt 20 Antworten in diesem Thema. Der letzte Beitrag () ist von FAtheone.

    [Community Projekt] OpenLib

    Hey, ich hab hier mal irgendwo so ein kleines "Spiel" gesehen.
    Ich dachte, das es eigentlich keine schlechte Idee ist, einfach Codesnipptes zu posten und in eine Anwendung einzufügen.

    Ich dachte mir, man könnte das auch mit einem Class Library machen, das OpenLib.
    Das OpenLib soll eine Ansammlung aus nützliche Codes sein, die ich dann im Showroom releasen werden.

    Version 1.0.0 wird vorraussichtlich morgen um 20:00 Uhr im Showroom gepostet.
    Also strengt euch an, und postet ein paar nützliche Codes.

    Aktuelle Klassen / Subs:



    Allgemein.vb:
    Public Shared Function SortIntegerArray(ByVal Array As Integer(), Optional ByVal Aufsteigend As Boolean = True) As Integer()

    Internet.vb:
    -> Public Shared Sub Download(ByVal Address As String, ByVal Path As String)
    -> Public Shared Sub Upload(ByVal Address As String, ByVal Username As String, ByVal Password As String, ByVal File As String)

    Ausweis.vb:
    ->
    Public Shared Function IsDataValid() As Boolean

    Dieser Beitrag wurde bereits 7 mal editiert, zuletzt von „xXMichaelXx“ ()

    VB.NET-Quellcode

    1. 'Eine Datei aus dem Internet auf den Computer laden.
    2. Public Sub httpDownload(ByVal adress As String, ByVal savePath As String)
    3. Dim downloadClient As new WebClient()
    4. Try
    5. downloadClient.DownloadFile(adress, savePath)
    6. Catch ex As WebException
    7. MsgBox(ex.Message)
    8. End Try
    9. End Sub
    Der Code stammt vermutlich nicht vom Autor selbst.
    Code
    Bitte niemals fremden Code ohne Angabe der Quelle posten.
    mikeb69


    Personalausweis auf gültigkeit untersuchen und mehr:

    VB.NET-Quellcode

    1. ''' <summary>
    2. ''' Information über den Aufbau eines deutschen Personalausweises:
    3. ''' 123412345XD--123456X-123456X-------X
    4. ''' | | || | | | | |_Prüfsumme von allen Ziffern (1 Ziffer)
    5. ''' | | || | | | |_________Prüfsumme des Ablaufdatums (1 Ziffer)
    6. ''' | | || | | |_______________Das Ablaufdatum des Ausweises im Format YYMMDD (6 Ziffern)
    7. ''' | | || | |_________________Prüfsumme des Geburtsdatums (1 Ziffer)
    8. ''' | | || |_______________________Eigenes Geburtsdatum im Format YYMMDD (6 Ziffern)
    9. ''' | | ||__________________________Nationalität (D für Deutschland)
    10. ''' | | |___________________________Prüfsumme der ersten 9 Ziffern (1 Ziffer)
    11. ''' | |________________________________Die fortlaufende Nummer der Behördenkennzahl (5 Ziffern)
    12. ''' |____________________________________Die Behördenkennzahl (4 Ziffern)
    13. ''' </summary>
    14. Public Class Germany
    15. Private mGovernmentClassification(3) As Integer
    16. Private mCountNumber(4) As Integer
    17. Private mBirthDate(5) As Integer
    18. Private mExpirationDate(5) As Integer
    19. Private ValidData As Integer = 0
    20. Public Enum EnumPersonData
    21. FirstResidenceCFC = 1
    22. CountNumber = 2
    23. BirthDate = 4
    24. ExpirationDate = 8
    25. End Enum
    26. ''' <summary>
    27. ''' Die Behördenkennzahl (Die ersten 4 Ziffern)
    28. ''' </summary>
    29. Public WriteOnly Property GovernmentClassification() As String
    30. Set(ByVal value As String)
    31. ValidData = ValidData And Not CInt(EnumPersonData.FirstResidenceCFC)
    32. If value.Length <> 4 Then Throw New ArgumentException("INVALID DATALENGTH. MUST BE 4")
    33. For i As Integer = 0 To 3
    34. mGovernmentClassification(i) = Int32.Parse(value(i).ToString)
    35. Next
    36. ValidData = ValidData Or CInt(EnumPersonData.FirstResidenceCFC)
    37. End Set
    38. End Property
    39. ''' <summary>
    40. ''' Die fortlaufende Nummer der Behördenkennzahl (Die nächsten 5 Ziffern nach der Behördenkennzahl)
    41. ''' </summary>
    42. Public WriteOnly Property CountNumber() As String
    43. Set(ByVal value As String)
    44. ValidData = ValidData And Not CInt(EnumPersonData.CountNumber)
    45. If value.Length <> 5 Then Throw New ArgumentException("INVALID DATALENGTH. MUST BE 5")
    46. For i As Integer = 0 To 4
    47. mCountNumber(i) = Int32.Parse(value(i).ToString)
    48. Next
    49. ValidData = ValidData Or CInt(EnumPersonData.CountNumber)
    50. End Set
    51. End Property
    52. ''' <summary>
    53. ''' Das eigene Geburtsdatum (Die ersten 6 Ziffern des zweiten Ziffernblocks im Format JJMMDD)
    54. ''' </summary>
    55. Public WriteOnly Property BirthDate() As String
    56. Set(ByVal value As String)
    57. ValidData = ValidData And Not CInt(EnumPersonData.BirthDate)
    58. If value.Length <> 6 Then Throw New ArgumentException("INVALID DATALENGTH. MUST BE 6")
    59. For i As Integer = 0 To 5
    60. mBirthDate(i) = Int32.Parse(value(i).ToString)
    61. Next
    62. ValidData = ValidData Or CInt(EnumPersonData.BirthDate)
    63. End Set
    64. End Property
    65. ''' <summary>
    66. ''' Das Ablaufdatum des Ausweises (Die ersten 6 Ziffern des dritten Ziffernblocks im Format JJMMDD)
    67. ''' </summary>
    68. Public WriteOnly Property ExpirationDate() As String
    69. Set(ByVal value As String)
    70. ValidData = ValidData And Not CInt(EnumPersonData.ExpirationDate)
    71. If value.Length <> 6 Then Throw New ArgumentException("INVALID DATALENGTH. MUST BE 6")
    72. For i As Integer = 0 To 5
    73. mExpirationDate(i) = Int32.Parse(value(i).ToString)
    74. Next
    75. ValidData = ValidData Or CInt(EnumPersonData.ExpirationDate)
    76. End Set
    77. End Property
    78. ''' <summary>
    79. ''' Diese Funktion prüft ob die angegebene Daten alle richtig sind.
    80. ''' </summary>
    81. Public Function IsDataValid() As Boolean
    82. Dim nValidIf As Integer = CInt(EnumPersonData.FirstResidenceCFC) Or _
    83. CInt(EnumPersonData.CountNumber) Or _
    84. CInt(EnumPersonData.BirthDate) Or _
    85. CInt(EnumPersonData.ExpirationDate)
    86. Return (nValidIf = ValidData)
    87. End Function
    88. Private Function HashData() As IDHASH
    89. If Not IsDataValid() Then Return Nothing
    90. Dim HashA, HashB, HashC, HashD As Integer
    91. HashA = _
    92. (mGovernmentClassification(0) * 7) + _
    93. (mGovernmentClassification(1) * 3) + _
    94. (mGovernmentClassification(2) * 1) + _
    95. (mGovernmentClassification(3) * 7) + _
    96. (mCountNumber(0) * 3) + _
    97. (mCountNumber(1) * 1) + _
    98. (mCountNumber(2) * 7) + _
    99. (mCountNumber(3) * 3) + _
    100. (mCountNumber(4) * 1)
    101. HashB = _
    102. (mBirthDate(0) * 7) + _
    103. (mBirthDate(1) * 3) + _
    104. (mBirthDate(2) * 1) + _
    105. (mBirthDate(3) * 7) + _
    106. (mBirthDate(4) * 3) + _
    107. (mBirthDate(5) * 1)
    108. HashC = _
    109. (mExpirationDate(0) * 7) + _
    110. (mExpirationDate(1) * 3) + _
    111. (mExpirationDate(2) * 1) + _
    112. (mExpirationDate(3) * 7) + _
    113. (mExpirationDate(4) * 3) + _
    114. (mExpirationDate(5) * 1)
    115. HashD = _
    116. (mGovernmentClassification(0) * 7) + _
    117. (mGovernmentClassification(1) * 3) + _
    118. (mGovernmentClassification(2) * 1) + _
    119. (mGovernmentClassification(3) * 7) + _
    120. (mCountNumber(0) * 3) + _
    121. (mCountNumber(1) * 1) + _
    122. (mCountNumber(2) * 7) + _
    123. (mCountNumber(3) * 3) + _
    124. (mCountNumber(4) * 1) + _
    125. (HashA * 7) + _
    126. (mBirthDate(0) * 3) + _
    127. (mBirthDate(1) * 1) + _
    128. (mBirthDate(2) * 7) + _
    129. (mBirthDate(3) * 3) + _
    130. (mBirthDate(4) * 1) + _
    131. (mBirthDate(5) * 7) + _
    132. (HashB * 3) + _
    133. (mExpirationDate(0) * 1) + _
    134. (mExpirationDate(1) * 7) + _
    135. (mExpirationDate(2) * 3) + _
    136. (mExpirationDate(3) * 1) + _
    137. (mExpirationDate(4) * 7) + _
    138. (mExpirationDate(5) * 3) + _
    139. (HashC * 1)
    140. Return New IDHASH(HashA Mod 10, HashB Mod 10, HashC Mod 10, HashD Mod 10)
    141. End Function
    142. ''' <summary>
    143. ''' Diese Funktion erstellt eine gültige Personalausweis ID
    144. ''' </summary>
    145. ''' <param name="nGovernmentClassification">4-Stellige Behördenkennzahl (kann irgendeine Nummer sein oder eine aus den offiziellen Listen zu findem im Internet).</param>
    146. ''' <param name="nCountNumber">5-Stellige fortlaufende Nummer der Behördenkennzahl (kann irgendeine Nummer sein).</param>
    147. ''' <param name="nBirthDate">Geburtsdatum</param>
    148. ''' <param name="nExpirationDate">Ablaufdatum</param>
    149. Public Function CreateFullID(ByVal nGovernmentClassification As String, ByVal nCountNumber As String, ByVal nBirthDate As Date, ByVal nExpirationDate As Date) As FULLID
    150. Dim TmpBirthDate As String = nBirthDate.Year.ToString.Substring(2, 2) & Format(nBirthDate.Month, "0#") & Format(nBirthDate.Day, "0#")
    151. Dim TmpExpDate As String = nExpirationDate.Year.ToString.Substring(2, 2) & Format(nExpirationDate.Month, "0#") & Format(nExpirationDate.Day, "0#")
    152. GovernmentClassification = nGovernmentClassification
    153. CountNumber = nCountNumber
    154. BirthDate = TmpBirthDate
    155. ExpirationDate = TmpExpDate
    156. Dim HashValues As IDHASH = HashData()
    157. Dim NewFullID As FULLID
    158. NewFullID.GovernmentClassification = nGovernmentClassification
    159. NewFullID.CountNumber = nCountNumber
    160. NewFullID.BirthDate = TmpBirthDate
    161. NewFullID.ExpirationDate = TmpExpDate
    162. NewFullID.HashValues = HashValues
    163. Return NewFullID
    164. End Function
    165. Public Structure FULLID
    166. Public GovernmentClassification As String
    167. Public CountNumber As String
    168. Public BirthDate As String
    169. Public ExpirationDate As String
    170. Public HashValues As IDHASH
    171. Public Overrides Function ToString() As String
    172. Return GovernmentClassification & CountNumber & HashValues.HashA.ToString & "D<<" & BirthDate & HashValues.HashB.ToString & "<" & ExpirationDate & HashValues.HashC.ToString & "<<<<<<" & HashValues.HashD.ToString
    173. End Function
    174. End Structure
    175. Public Structure IDHASH
    176. Public HashA As Integer
    177. Public HashB As Integer
    178. Public HashC As Integer
    179. Public HashD As Integer
    180. Sub New(ByVal A As Integer, ByVal B As Integer, ByVal C As Integer, ByVal D As Integer)
    181. HashA = A
    182. HashB = B
    183. HashC = C
    184. HashD = D
    185. End Sub
    186. End Structure
    187. End Class

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „mikeb69“ ()


    Zitat

    bitte nur Subs posten.

    Finde ich nicht gut, denn es ist eine Klassenbibliothek, keine Subbibliothek.
    Desweiteren sind MessageBox (bzw. MsgBox) Ausgaben auf Bibliotheksebene nicht so toll.

    Viele Grüße, Phil.
    Ist doch klar das man nur Subs posten kann!
    Das ist nicht eine Klasse an dem du selber sitzt und arbeitest.
    Einzelne und hilfreiche Funktionen soll sie beinhalten und jeder soll damit arbeiten können ....

    VB.NET-Quellcode

    1. 'Ein Integer-Irray wird sortiert und zurückgegeben.
    2. 'Sortieralgorithmus: Bubble-Sort
    3. Public Function sortIntegerArray(ByVal intArray As Integer(), Optional ByVal aufsteigend As Boolean = True) As Integer()
    4. Dim newArray As Integer() = intArray.Clone
    5. For i = 0 To newArray.Length - 1
    6. For x = 0 To newArray.Length - 1
    7. If (newArray(x) > newArray(i) And aufsteigend = True) Then
    8. Dim tmp As Integer = newArray(i)
    9. newArray(i) = newArray(x)
    10. newArray(x) = tmp
    11. End If
    12. If (newArray(x) < newArray(i) And aufsteigend = False) Then
    13. Dim tmp As Integer = newArray(i)
    14. newArray(i) = newArray(x)
    15. newArray(x) = tmp
    16. End If
    17. Next
    18. Next
    19. Return newArray
    20. End Function
    Kann mir mal einer erklären, wie man ne vernünftige Struktur erstellen kann, wenn man nur Subs Posten darf? Das zeigt doch schon, dass der TE keine Ahnung von OOP hat. Keine Namespaces?.. oh no.

    Einen Personalausweis-prüfer im gleichen Namespace wie nen Download-Sub. Oha.
    Von meinem iPhone gesendet
    außerdem seeehr übersichtlich für den Benutzer der Lib...

    (Achtung war diesmal ironie, dass das nicht wieder falsch verstanden wird...)
    [/]
    @ Vb K1ng : Was hälst du von diesem Code?:

    VB.NET-Quellcode

    1. New WebClient().DownloadFileAsync(New Uri(Adresse),Zielpfad)

    damit hab ich nicht wirklich was gespart, außerdem ist mein Aufruf sogar noch etwas performanter :P
    Ich wollte auch mal ne total überflüssige Signatur:
    ---Leer---
    Kann mir mal einer erklären, wie man ne vernünftige Struktur erstellen kann, wenn man nur Subs Posten darf? Das zeigt doch schon, dass der TE keine Ahnung von OOP hat. Keine Namespaces?.. oh no.

    Einen Personalausweis-prüfer im gleichen Namespace wie nen Download-Sub. Oha.

    Sicherlich wird unübersichtlich.
    Eventuell könnte man ja einzelne Klassen erstellen (Kategorieren), und in diese dann die jeweiligen Subs.
    Also z.B.
    -> Allgemein
    -> Internet
    -> Dateisystem
    -> usw..
    Hallo,

    die Idee eine solche Dll zu erstellen ist nicht neu aber dennoch eine gute Sache.
    Das Ganze rein auf Subs zu reduzieren halte ich aber für nicht gut.

    Es zeigt im Prinzip wie unerfahren der Thread Ersteller ist.
    Vermutlich dient dieses Thema nur dazu Funktionen ohne Anstrengung freihaus geliefert zu bekommen.

    Gruss

    mikeb69

    mikeb69 schrieb:

    Vermutlich dient dieses Thema nur dazu Funktionen ohne Anstrengung freihaus geliefert zu bekommen.

    Hmm Mike, das glaube ich eher nicht. Auch muss man anerkennen, daß der von ihm selber gepostete Code doch zumindest fehlerfrei war ;)

    Ausserdem ist die Idee, einmal die vielen nützlichen Code-Schnippsel in diesem Forum zu sammeln , auch nicht schlecht. Allerdings ist die Form als Library wohl eher falsch.

    Wie wäre es wenn man ein eigenes Subforum für "Code Snippets" einrichtet, in der fertige Snippets (z.B. in der XML Form) gepostet werden können ? Allerdings mit sehr strikten Regeln über Form und Inhalt, sonst wird das genau so ein Wildwuchs wie das Sourcecode Forum .
    Haha lol, ich habs mir irgendwie gedacht das soetwas kommt.
    Natürlich geht es mir nicht darum, irgendwelche Funktionen geliefert zu bekommen.

    Wenn ich etwas brauche / nicht verstehe frage ich im Forum im entsprechenden Bereich nach.

    Nur Sub's währen einfach übersichtlicher.

    Wie gesagt, Klassen gibt's ja auch.
    Im ersten Post gibt's eine Übersicht von den aktuellen Subs / Klassen.
    Hallo xxMichaelxx,

    wenn du meinst - das es kindisch ist, dann wird es wohl so sein. ;)

    Vorschlag:
    Vereinheitlich das Ganze doch etwas und gib jedem Autor die Möglichkeit genannt zu werden.
    Dies kann man bequem mit einem Interface erreichen.

    Gruss

    mikeb69