Using variable in button to give value to label

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • violet469
    New Member
    • Mar 2015
    • 1

    Using variable in button to give value to label

    I have tried this on a MacBook with Parallels running Windows 7, and on a Vaio desktop running Windows 7, but both with Visual Studio 2012:

    I am trying to use different buttons to assign different values to a variable.
    There are 2 variables using different buttons to assign them.
    These variables are being added together to assign value to a label.

    I believe my error is in my syntax but I have not found out how to use a button to set the value for a variable.

    I get no error codes, I just do not get a result in my final label. It stays blank.


    Here is a chunk of my code:

    Code:
    Public Class frmLunchCombos
    
    ‘I went ahead and defined my variables
        Dim dblSandwichCost As Double
        Dim dblSoupCost As Double
    
    
    'Click TomatoBasil
        Private Sub btnTomatoBasil_Click(sender As Object, e As EventArgs) Handles btnTomatoBasil.Click
    
    ‘I mean for this to set SoupCost to the value 2.49        
    dblSoupCost = 2.49
    
         End Sub
    
    
    'Click ClassicTurkeyBreast
        Private Sub btnClassicTurkeyBreast_Click(sender As Object, e As EventArgs) Handles btnClassicTurkeyBreast.Click
    
    ‘I mean for this to set SandwichCost to the value 3.49
    
            dblSandwichCost = 3.49
    
        End Sub
    
    
    
    Private Sub lblCalcSubtotal_Click(sender As Object, e As EventArgs) Handles lblCalcSubtotal.Click
    
          ‘I made dblValue for easy formatting of the final label
    
            Dim dblValue As Double
    
     ‘Value= SoupCost (which would be assigned to 2.49 after clicking Tomato Basil) + SandwichCost (which would be assigned to 3.49 after clicking ClassicTurkeyBreast)
    
            dblValue = dblSoupCost + dblSandwichCost
    
     ‘And then convert Value to a currency-formatted string
    
            lblCalcSubtotal.Text = dblValue.ToString("C")
    
        End Sub
    Many thanks in advance! I really want to understand this and I feel like it's something simple.
  • kvinvisibleguy
    New Member
    • Mar 2013
    • 4

    #2
    Dear Friend,
    Your problem invoked a hornets nest in my programming world.I was doing C-Pad programming(cmd & notepad)
    and suddenly i found your problem has creeped in to my C-Pad also.No textbox,listbox or label is responding
    to button click.It was working easily for me all these days.Microsoft uploaded many updates recently(just 3 days since)
    They must have screwed up something.Anywa y,i did your project in visual studio express 2013 and uploaded to
    the URL:-(given below)
    Filesharing.com is the simplest way to send your files around the world. Share large files with a Filehosting Transfer up to 1GB free. Filesharing made easy!

    I used a listbox instead of label.No problem.Even Label and Textbox will work fine.Now i will have to analyse what went
    wrong in my C-Pad style.I have uploaded many projects to the following URL:-(It includes VB.Net and WPF-with-VB.Net).

    Do
    try out those and tell me whether they work in your Computer.I have windows 8.1.
    Venkatraman

    Comment

    • kvinvisibleguy
      New Member
      • Mar 2013
      • 4

      #3
      Dear Friend,
      I worked further and made your project as per your expectations.I also found out that It is not Microsoft who screwed up,But it is me.
      I actually had a simple error which i overlooked.Anyw ay it helps me to blame Microsoft first and then on retrying locate the blame on myself.
      (Not surprising considering my age-68+)This project is named Project469 and uploaded to URL:-(It is in C-Pad style)

      http://www.filehosting .org/file/details/478305/Project469.rar[/URL]

      You have to call the compiler from your cmd window as given below.First place the two .vb files(Violet2.v b and Violet22.vb) in a folder
      -New folder(you can name it appropriately).
      The compiler calling is:-

      path=%path%;c:\ windows\microso ft.net\framewor k\v4.0.30319
      VBC /OUT:Violet2 /T:winexe C:\Users\...... .\Desktop\Folde r\Violet2.vb
      VBC /OUT:Violet2 /T:winexe C:\Users\...... .\Desktop\Folde r\Violet22.vb C:\Users\VEKATR AMAN\Desktop\Ne w folder\Violet2. vb
      Violet2

      NOTE:The dotted portion is particular to your computer.Mostly it will be your name.Change the New folder to whatever you want.
      This project is exactly what you wanted-with ListBox as a bonus addition.

      Comment

      Working...