Probleme mit Schleife in meinem ersten Programm

  • Sonstige

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von liuzewei.

    Probleme mit Schleife in meinem ersten Programm

    Hallo Community!
    Seid ein paar tagen lerne ich den Umgang mit VB 2010 und versuche mein erstes, simples Programm zu schreiben ... die Nacht war kurz und so langsam verzweifel ich


    Eigentlich soll es folgendes tun:
    1. ich zeichne etwas auf (klappt 1a)
    2. Programm wird gestartet durch den Button -> PlayTimer.Start()
    3. Nachdem er die erste Aufnahme abgespielt hat startet der "looper" und falls Schleifen gewünscht sind soll alles von Vorne anfangen nach einem DELAY

    ... wenn ich wie hier im Code MsgBox("New Start") einfüge verhällt sich das Programm genau so wie ich es haben möchte
    ... füge ich allerdings PlayTimer.Start() an diese Stelle ein, um die Aufzeichnung erneut zu starten, wird es eine ENDLOSSCHLEIFE !!!



    Visual Basic-Quellcode

    1. Public Class Form1#Region "DIMS"
    2. Dim result As Integer Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Short Dim curclicks = 0 Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer) Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move Private Const MOUSEEVENTF_MIDDLEDOWN = &H20 Private Const MOUSEEVENTF_MIDDLEUP = &H40 Private Const MOUSEEVENTF_RIGHTDOWN = &H8 Private Const MOUSEEVENTF_RIGHTUP = &H10 Private Declare Sub mouse_event Lib "user32" (ByVal dwflags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cbuttons As Long, ByVal dwExtraInfo As Long) Private Const mouseclickup = 4 Private Const mouseclickdown = 2
    3. #End Region Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RecorderTimer.Tick Dim Mouse As Point = Control.MousePosition If GetAsyncKeyState(MOUSEEVENTF_LEFTDOWN) Then ListBox2.Items.Add("Left") ListBox3.Items.Add("Right") ElseIf GetAsyncKeyState(MOUSEEVENTF_RIGHTDOWN) Then ListBox2.Items.Add("Right") ListBox3.Items.Add("Right") Else ListBox2.Items.Add(Mouse.X) ListBox3.Items.Add(Mouse.Y) End If ListBox1.Items.Add(GetAsyncKeyState(1)) End Sub
    4. Private Sub delay(ByVal zeit As Integer) Dim zeit1 As Integer = System.Environment.TickCount While (System.Environment.TickCount - zeit1) < zeit Application.DoEvents() End While End Sub
    5. Private Sub looper() Dim schleife As Integer = CInt(TextBox2.Text) If CheckBox1.Checked = True Then For i As Integer = 1 To schleife If i <= schleife Then restart() ElseIf i > schleife Then MsgBox("Done ! ... max loops reached") End If Next i ElseIf CheckBox1.Checked = False Then MsgBox("Done ! ... no loop activated") End If End Sub
    6. Private Sub restart() ListBox2.SelectedIndex = 0 ListBox3.SelectedIndex = 0 delay(3000) MsgBox("New Start") End Sub
    7. Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayTimer.Tick If ListBox1.Text = "-32767" Or ListBox1.Text = "-32768" Then mouse_event(mouseclickdown, 0, 0, 0, 0) mouse_event(mouseclickup, 0, 0, 0, 0) End If If ListBox3.Text = "Left" Then mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) ElseIf ListBox3.Text = "Right" Then mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0) ElseIf Not ListBox3.Text = "Left" And Not ListBox3.Text = "Right" Then Cursor.Position = New Point(ListBox2.Text, ListBox3.Text) End If Try ListBox1.SelectedIndex = ListBox2.SelectedIndex + +1 ListBox2.SelectedIndex = ListBox2.SelectedIndex + +1 ListBox3.SelectedIndex = ListBox3.SelectedIndex + +1
    8. Catch ex As Exception PlayTimer.Stop() looper()
    9. End Try End Sub






    Vielleicht kann mir ja hier jemand helfen, würde mich sehr über Tips und/oder Verbesserungsvorschläge freuen !
    Kannst du mir/uns bitte erklären wer deinen Code verstehen soll!?!
    Formatier deinen Code in eine lesbare Reihenfolge, dann kann dir bestimmt wer helfen!

    Tut mir leid, wenn ich das so "hart" sage, aber so wirst du keine Antwort erhalten.

    Gruß
    No!
    ui sorry, was hat das Forum denn da aus meinem Code gemacht.
    Dann hier noch einmal ohne [ vb ] ... sorry !



    Public Class Form1
    #Region "DIMS"



    Dim result As Integer
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Short
    Dim curclicks = 0
    Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
    Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
    Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
    Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
    Private Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Private Const MOUSEEVENTF_MIDDLEUP = &H40
    Private Const MOUSEEVENTF_RIGHTDOWN = &H8
    Private Const MOUSEEVENTF_RIGHTUP = &H10
    Private Declare Sub mouse_event Lib "user32" (ByVal dwflags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cbuttons As Long, ByVal dwExtraInfo As Long)
    Private Const mouseclickup = 4
    Private Const mouseclickdown = 2


    #End Region
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RecorderTimer.Tick
    Dim Mouse As Point = Control.MousePosition
    If GetAsyncKeyState(MOUSEEVENTF_LEFTDOWN) Then
    ListBox2.Items.Add("Left")
    ListBox3.Items.Add("Right")
    ElseIf GetAsyncKeyState(MOUSEEVENTF_RIGHTDOWN) Then
    ListBox2.Items.Add("Right")
    ListBox3.Items.Add("Right")
    Else
    ListBox2.Items.Add(Mouse.X)
    ListBox3.Items.Add(Mouse.Y)
    End If
    ListBox1.Items.Add(GetAsyncKeyState(1))
    End Sub



    Private Sub delay(ByVal zeit As Integer)
    Dim zeit1 As Integer = System.Environment.TickCount
    While (System.Environment.TickCount - zeit1) < zeit
    Application.DoEvents()
    End While
    End Sub



    Private Sub looper()
    Dim schleife As Integer = CInt(TextBox2.Text)
    If CheckBox1.Checked = True Then
    For i As Integer = 1 To schleife
    If i <= schleife Then
    restart()
    ElseIf i > schleife Then
    MsgBox("Done ! ... max loops reached")
    End If
    Next i
    ElseIf CheckBox1.Checked = False Then
    MsgBox("Done ! ... no loop activated")
    End If
    End Sub



    Private Sub restart()
    Dim pause As Integer = CInt(TextBox1.Text)
    ListBox2.SelectedIndex = 0
    ListBox3.SelectedIndex = 0
    delay(pause)
    PlayTimer.Start()
    End Sub



    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayTimer.Tick
    If ListBox1.Text = "-32767" Or ListBox1.Text = "-32768" Then
    mouse_event(mouseclickdown, 0, 0, 0, 0)
    mouse_event(mouseclickup, 0, 0, 0, 0)
    End If
    If ListBox3.Text = "Left" Then
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    ElseIf ListBox3.Text = "Right" Then
    mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
    ElseIf Not ListBox3.Text = "Left" And Not ListBox3.Text = "Right" Then
    Cursor.Position = New Point(ListBox2.Text, ListBox3.Text)
    End If
    Try
    ListBox1.SelectedIndex = ListBox2.SelectedIndex + +1
    ListBox2.SelectedIndex = ListBox2.SelectedIndex + +1
    ListBox3.SelectedIndex = ListBox3.SelectedIndex + +1

    Catch ex As Exception
    PlayTimer.Stop()
    looper()

    End Try
    End Sub