Visual Basic Question

Discussion in 'Programming' started by ozirock, May 26, 2009.

  1. #1
    Hi Guy's,

    I was wondering if any of you would be able to help me with a program I'm trying to make. I have a velleman k8055 USB interface board and I want to control some of the ports with the arrow keys on my keyboard. I have made a program which doesnt work and I dont know how to fix it. I'm not an experience programmer, I'm just a lost beginner so any help would be apprecited :)

    The Code:

    Public Class Form1
    Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer
    Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
    Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Connect.Click
    Dim CardAddress As Integer
    Dim h As Integer
    CardAddress = 3

    h = OpenDevice(3)
    Label1.Text = "Card " + Str(h) + " connected"

    End Sub

    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
    If e.KeyCode = Keys.Left Then
    Left = False
    End If
    If e.KeyCode = Keys.Right Then
    Right = False
    End If
    If e.KeyCode = Keys.Up Then
    up = False
    End If
    If e.KeyCode = Keys.Down Then
    down = False
    End If

    If Left Then
    ClearDigitalChannel(1)
    End If
    If Right Then
    ClearDigitalChannel(2)
    End If
    If up Then
    ClearDigitalChannel(4)
    End If
    If down Then
    ClearDigitalChannel(3)
    End If

    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim down As Boolean
    Dim left As Boolean
    Dim right As Boolean
    Dim up As Boolean

    Left = False
    Right = False
    up = False
    down = False

    End Sub

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

    If e.KeyCode = Keys.Left Then
    left = True
    End If
    If e.KeyCode = Keys.Right Then
    right = True
    End If
    If e.KeyCode = Keys.Up Then
    up = True
    End If
    If e.KeyCode = Keys.Down Then
    down = True
    End If

    If left Then
    SetDigitalChannel(1)
    End If
    If right Then
    SetDigitalChannel(2)
    End If
    If up Then
    SetDigitalChannel(4)
    End If
    If down Then
    SetDigitalChannel(3)
    End If

    End Sub

    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

    End Sub
    End Class


    I'm using visual basic 2005 express edition if that's important, any help at all would be great :)
     
    ozirock, May 26, 2009 IP
  2. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #2
    How do you know the application does not work? Is the application throwing exceptions (errors), application does not control the interface board as expected, etc? Provide us more details and we will try to help.
     
    Social.Network, May 26, 2009 IP
  3. jmihoku

    jmihoku Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah. Error codes would really help. If you can give the highlighted line when you debug in runtime, that would be better.
     
    jmihoku, May 27, 2009 IP
  4. ozirock

    ozirock Member

    Messages:
    235
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #4
    Sorry that was very stupid of me :)

    Warning 1 withEvents variable 'Left' conflicts with property 'Left' in the base class 'Control' and should be declared 'Shadows'. 106 23

    Warning 2 withEvents variable 'Right' conflicts with property 'Right' in the base class 'Control' and should be declared 'Shadows'. 107 23

    Error 3 Value of type 'Boolean' cannot be converted to 'System.Windows.Forms.Button'. 18 20

    Error 4 Value of type 'Boolean' cannot be converted to 'System.Windows.Forms.Button'. 21 21

    Error 5 Name 'up' is not declared. 24 13

    Error 6 Name 'down' is not declared. 27 13

    Error 7 Value of type 'System.Windows.Forms.Button' cannot be converted to 'Boolean'. 30 12

    Error 8 Value of type 'System.Windows.Forms.Button' cannot be converted to 'Boolean'. 33 12

    Error 9 Name 'up' is not declared. 36 12

    Error 10 Name 'down' is not declared. 39 12

    Error 11 Value of type 'Boolean' cannot be converted to 'System.Windows.Forms.Button'. 60 20

    Error 12 Value of type 'Boolean' cannot be converted to 'System.Windows.Forms.Button'. 63 21

    Error 13 Name 'up' is not declared. 66 13

    Error 14 Name 'down' is not declared. 69 13

    Error 15 Value of type 'System.Windows.Forms.Button' cannot be converted to 'Boolean'. 72 12

    Error 16 Value of type 'System.Windows.Forms.Button' cannot be converted to 'Boolean'. 75 12

    Error 17 Name 'up' is not declared. 78 12

    Error 18 Name 'down' is not declared. 81 12

    Can someone please clarify what exactly Boolean is, does it just mean something can either be true or false or can you save anything as boolean?

    Why are up and down not declared when I have them declared in the code, don't I?
     
    ozirock, May 27, 2009 IP