VB to send command to arduino

Hi so i am completely new to Arduino. and VB for that matter. but i have a basic understanding of both. In VB express 2010 i created a small program. It is basically ( for now) 5 radio buttons, and depending which is selected when the go button is pressed it will display a message box that says "you have selected such and such." I'd like to change that to send a command to Arduino. Basically it would say power up digital pin 1 for x amount of time. Now i dont need help in programming in Arduino. I would write the whole code for arduino inside VB, tide to its own indiviual radio button. Then when the go button is hit, instead of the message box, i want it to activate arduino and run.

Im not sure if there is an easier way to do this? I am pretty much just trying to make a user interface. Select the option you want in the VB program and it will do it in arduino.

Also i am running visual basic express 2010 and have an arduino uno

Check this out:
http://arduino.cc/forum/index.php/topic,101231.0.html

Hi there ! I am also new to Arduino. and but I have understanding of VB express 2010. I have also created many small programs in VB express 2010. I here to understand and use the Arduino concepts. Thanks for sharing the thread link arduinoadrian, It was very helpful.

hi kids

I'm not an expert at all, but I can tell you what I did, and some of the thoughts I had.

If you havn't found out yet .. pick a serial port in the toolbox and drop it on your form.
Doubleclick the icon and .. voila, you are i the event that responds when bytes comes back from the arduino.
I hope that you've found out, that vb is event-driven, and that the code-'cursor' flutters around between the events that occurs .. thats my way of thinking about it.
The serial port you just dumped may not know about the port you use, so I put this code in the form 'new' procedure:

Public Sub New()

InitializeComponent()

For Each p In My.Computer.Ports.SerialPortNames
If p = "COM15" Then
SerialPort1 = My.Computer.Ports.OpenSerialPort("COM15")
SerialPort1.Encoding = New System.Text.ASCIIEncoding
If Not SerialPort1.IsOpen = True Then
SerialPort1.Open()
End If
End If
Next
.....

I've chosen ASCII becourse it's a one byte encoding [edit:no, it's 2 bytes] (you'll have to get to grips with encodings sooner or later). I recall, that the Port didn't always read all the code that came from the controller .. that's where it's handy to be able to rely on just 1 'message'-bite. Alternatively the SerialPort1.ReadExisting can be used. The sort of 'encoding' you choose for yourself doesn't matter .. the important thing is, that YOU understand it.

In the code-editor you can find "SerialPort1" in the left drop-down menu. Once you've picked it there, you may look at it's 'events' in the right drop-down menu. There's an 'errorRecieved' that may come in handy.

And when you've collected something to send .. SerialPort1.Write(..). You'll probably place it in a button-click event.

have fun

This is the VB6 code I use to find the com port the Arduino is on:

For n = 1 To 16
  If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
   On Error Resume Next
   MSComm1.CommPort = n
   On Error Resume Next
   MSComm1.InputLen = 0
   MSComm1.PortOpen = True
   If MSComm1.CommID > 0 Then
     For i = 1 To 100  'keep trying
      str = ""
      str = MSComm1.Input

 
      If InStr(str, "< ") > 0 And InStr(str, ">") > 0 Then GoTo jump:

     ' these are the chars I use to bracket the output from the Arduino 
     ' you can use anything you want
     ' the reason I do this is so the VB can tell the Arduino port 
     'from other active ports otherwise the code
     ' will just pick the first one open
                                                                                  
      Sleep 50                                                                                       
     Next i
  End If
Next n
If MSComm1.PortOpen = False Then MsgBox "Controller Not functioning , Please check USB connection", vbCritical, "": ComFail = True: Exit Sub