[*] Evalueer je code Topic

Pagina: 1
Acties:
  • 37 views sinds 30-01-2008

  • Swerfer
  • Registratie: Mei 2003
  • Laatst online: 26-05 22:09
Onder het motto 2 weten meer dan één, kan je wel nagaan wat vele tweakers teweeg kunnen brengen...

Je kent het wel, na veel testen en wijzigen van je script of programma denk je het eindelijk voor elkaar te hebben. Je vele programmeerwerk is ten einde, je script of programma is af.

Alleen...

Is je code wel stabiel? Is je code wel snel? Doet je code wel altijd precies datgene wat je verwacht? Is je code veilig? Is je code wel optimaal geprogrammeerd?

Natuurlijk denk je, je hebt het toch zelf uitvoerig getest en verbeterd...

Maar wat als je nou datgene over het hoofd hebt gezien, wat voor een hoop problemen of teleurstelling kan gaan zorgen?

Daarom dit topic. Post hier (een deel van) je code om het te laten evalueren door andere tweakers. Een frisse blik door iemand anders kan alleen maar leiden tot verbetering van je code. Of het nou gaat om PHP, C#/C++ of VB, het maakt allemaal niet uit. Elke taal is welkom. Met een beetje moeite, kan je een andere programmeertaal meestal wel omzetten naar de taal die jij prefereert.

Verder kan een ander profijt hebben van de code die jij hebt geschreven, of doe je zelf ideeën op met andermans code.

Ook kan je hier tips kwijt over zaken die (nog) niet aan bod zijn gekomen, en kan je handige code sharen met mede tweakers, die misschien weer aanvullingen of tips hebben...

Natuurlijk heb ik zelf zo'n stuk code wat me veel tijd heeft gekost. Onderstaande procedure zet een RichText om in HTML. Althans, richtext die alleen tekstkleur en regular, bold en italic fontstyles bevat. De richtext bevind zich in RichTextBox1 en het resultaat komt in TextBox1 op het moment dat op Button1 wordt geklikt.
Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
                          System.EventArgs) Handles Button1.Click
    Dim PreviousColor As Drawing.Color = Color.Black
    Dim ColorSet As Boolean = False
    Dim PreviousFontStyle As FontStyle = FontStyle.Regular
    Dim FontStyleItalicSet As Boolean = False
    Dim FontStyleBoldSet As Boolean
    Dim FormattedColor As String
    Dim dummy As Integer
    For dummy = 0 To RichTextBox1.TextLength
        RichTextBox1.Select(dummy, 1)

        If Not RichTextBox1.SelectionColor.Equals(PreviousColor) Then
            If ColorSet Then
                TextBox1.Text += "</font>"
                If RichTextBox1.SelectionColor.Equals(Color.Black) Then
                    ColorSet = False
                End If
            End If
            If RichTextBox1.SelectionColor.Equals(Color.Black) Then
                ColorSet = False
            Else
                 FormattedColor = "#" & Mid(Hex(RichTextBox1.SelectionColor.ToArgb),3, 6)
                TextBox1.Text += "<font color = """ & FormattedColor & """>"
                ColorSet = True
            End If
            PreviousColor = RichTextBox1.SelectionColor
        End If

        If Not RichTextBox1.SelectionFont.Style.Equals(PreviousFontStyle) Then
            If FontStyleItalicSet And Not RichTextBox1.SelectionFont.Italic Then
                TextBox1.Text += "</i>"
                FontStyleItalicSet = False
            End If
            If FontStyleBoldSet And Not RichTextBox1.SelectionFont.Bold Then
                TextBox1.Text += "</b>"
                FontStyleBoldSet = False
            End If
            If RichTextBox1.SelectionFont.Style.Equals(FontStyle.Regular) Then
                FontStyleBoldSet = False
                FontStyleItalicSet = False
            Else
                If RichTextBox1.SelectionFont.Bold And Not FontStyleBoldSet Then
                    TextBox1.Text += "<b>"
                    FontStyleBoldSet = True
                End If
                If RichTextBox1.SelectionFont.Italic And Not FontStyleItalicSet Then
                    TextBox1.Text += "<i>"
                    FontStyleItalicSet = True
                End If
            End If
            PreviousFontStyle = RichTextBox1.SelectionFont.Style
        End If

        TextBox1.Text += RichTextBox1.SelectedText
    Next
End Sub

[ Voor 3% gewijzigd door Swerfer op 29-12-2003 21:11 ]

Home Assistant | Unifi | LG 51MR.U44 | Volvo EX30 SMER+ Vapour Grey, trekhaak | SmartEVSE V3 | Cronos Crypto.com


  • Glimi
  • Registratie: Augustus 2000
  • Niet online

Glimi

Designer Drugs

(overleden)
Contact opgenomen met gebruiker.

Dit topic is gesloten.