Shop OBEX P1 Docs P2 Docs Learn Events
VB and BS2 — Parallax Forums

VB and BS2

NWUpgradesNWUpgrades Posts: 292
edited 2009-06-09 05:26 in BASIC Stamp
Following Unsoundcode's Info at this site, http://forums.parallax.com/showthread.php?p=671804·I am able to get my BS2 to work with VB 2008 Express. Now the question is this: Is it possible to insert other "buttons" within this program to make a sound or LED to light up? I have a piezo speaker on IN4, but I am not sure of the code needed to make it work from within VB, or if it is even possible. Thanks if you can help.

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-06-07 23:32
    Hi, the thread re: VB Express Template is quite lengthy and covers various techniques for different set ups but on the second page of the thread is a zip file called Com_Template.zip which acutally demonstrates the use of several buttons to control a BOE Bot.

    Did you figure out how to select different baud rates?

    Jeff T.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-07 23:47
    Thanks for the tip. And no, I have not figured out the Baud rate issue.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-06-08 00:38
    Hi, the baudrate is passed as a string (and so is the com port) and can be typed directly into code like so

    SerialPort1.BaudRate="4800"

    The original template added the flexibility of allowing the user to select a baud rate. I used a combo box with certain baudrates pre-written in the "Collection" property of the combo box which when selected is passed to the serial port

    SerialPort1.BaudRate=ComboBox1.SelectedItem

    The port must be closed when selecting the baud.

    Jeff T.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-08 00:44
    OK. I understand that. Now I have anither issue. I am trying to run the How to create a communications template in VB but have a problem. What I am seeing is CommsToolStripMenuItem_Click, instead of this:

    After you have typed Comms double click the text and it will open Code View and insert the PortToolStripMenuItem_Click

    After inserting Form2show() and running it, Form 1 comes up. Any ideas of what I am doing wrong?

    Here is what comes up:

    Public Class Form1

    Private Sub CommsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CommsToolStripMenuItem.Click

    Form2.Show()

    End Sub

    End
    Class

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-06-08 00:50
    Not sure.

    If I remember I did make a mistake with the way I wrote that up originally but didn't think it was too far out to be an issue.

    Try the VB help file for menu items.

    Jeff T.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-08 00:52
    Do you mean the way you wrote the code or the explanation? VB help is not "helping"!!!
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-08 01:00
    Also, I just need to verify that this is for VB 2008 Express, correct?
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-08 01:31
    I got it!!! Just a brain fart. It usually helps to click on Comms in the Menu for Form 2 to come up!!!!
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-08 02:06
    OK, I got stuck again. Where on Form2 am I suppose to declare the following? I tried at the top of the statement and at the top of the form, but I still get teh error that ComboBox 1 and 2 are not declared.

    ComboBox2.Items.Add(2400)
    ComboBox2.Items.Add(4800)
    ComboBox2.Items.Add(9600)


    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    For Each portName As String In My.Computer.Ports.SerialPortNames

    ComboBox1.Items.Add(portName)

    Next

    If Not _port.IsOpen Then

    Button2.Enabled = False

    ComboBox1.Text = ComboBox1.Items(0)

    ComboBox2.Text = ComboBox2.Items(0)

    Else

    Button1.Enabled = False

    ComboBox1.Text = _port.PortName

    ComboBox2.Text = _port.BaudRate

    End If

    End Sub

    End
    Class

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-06-08 02:41
    Hi, the code should work fine with VB Express 2005 or VB Express 2008.

    Before writing the code for Form2 all the controls should be placed on the form in designer view·, thats something like 3 buttons and 2 combo boxes. If you do that , making sure the comboboxes are named Combobox1 and Combobox2·, that should clear the errors.

    The code for the comboboxes is written in the Form2 load event
    [color=#0000ff]Private[/color] [color=#0000ff][color=#0000ff]Sub[/color][/color] Form2_Load([color=#0000ff][color=#0000ff]ByVal[/color][/color] sender [color=#0000ff][color=#0000ff]As[/color][/color] System.Object, [color=#0000ff][color=#0000ff]ByVal[/color][/color] e [color=#0000ff][color=#0000ff]As[/color][/color] System.EventArgs) [color=#0000ff][color=#0000ff]Handles[/color][/color] [color=#0000ff][color=#0000ff]MyBase[/color][/color].Load
    

    [color=#000000]ComboBox2.Items.Add(2400)[/color]
    
    [color=#000000]ComboBox2.Items.Add(4800)[/color]
    [color=#000000]ComboBox2.Items.Add(9600)[/color]
            
     [color=blue]For[/color] [color=blue]Each[/color][color=#000000] portName [/color][color=blue]As[/color] [color=blue]String[/color] [color=blue]In[/color] [color=blue]My[/color][color=#000000].Computer.Ports.SerialPortNames[/color] 
    [color=#000000]            ComboBox1.Items.Add(portName)[/color] 
            [color=blue]Next[/color] 
            [color=blue]If[/color] [color=blue]Not[/color][color=#000000] _port.IsOpen [/color][color=blue]Then[/color] 
    [color=#000000]            Button2.Enabled = [/color][color=blue]False[/color] 
    [color=#000000]            ComboBox1.Text = ComboBox1.Items(0)[/color] 
    [color=#000000]            ComboBox2.Text = ComboBox2.Items(0)[/color] 
            [color=blue]Else[/color] 
    [color=#000000]            Button1.Enabled = [/color][color=blue]False[/color] 
    [color=#000000]            ComboBox1.Text = _port.PortName[/color] 
    [color=#000000]            ComboBox2.Text = _port.BaudRate[/color] 
            [color=blue]End[/color] [color=blue]If[/color]
     
    

    [color=#0000ff]End[/color] [color=#0000ff][color=#0000ff]Sub[/color][/color]
    

    Jeff T.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-08 03:02
    yea, I figured out what the problem was with that. Did you get the PM I sent?
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-09 05:26
    Just to let you all know I have gottent all this figured out with Jeff's assistance. Thanks for everything. The code os brillaint!!!! Next step: Getting my Stepper motors to work the way the Servos are!!!! Should be interesting.
Sign In or Register to comment.